module UiFaces
Constants
- BASE_LINK
- MEN
- USERNAME
- VERSION
- WOMEN
Public Class Methods
face(network=false, username='random', format="epic")
click to toggle source
# File lib/ui_faces.rb, line 89 def self.face(network=false, username='random', format="epic") #return a image link from uifaces #to make it faster.... network should be false if(username != 'random') link = "http://uifaces.com/api/v1/user/" else link = '/api/v1/random' end unless network #if you don't want to use internet to retrieve an image link #than it will return a custom image link built from the USERNAME array return local_random(format) else #I'll try to use the network begin response = Net::HTTP.get_response("uifaces.com", link + username) rescue SocketError return local_random(format) end #checking the response code 200 || 400 if response.code.eql?'200' hash = JSON.parse(response.body) return hash['image_urls'][format] else #the username that you are looking for doesn't exist ## response.code == 404 return local_random(format) end end#unless end
faces(network=false, username='random', format='epic')
click to toggle source
# File lib/ui_faces.rb, line 124 def self.faces(network=false, username='random', format='epic') #return a hash of links #puts faces['bigger'] link = self.face(network, username, format) username = link.split("/")[-2] return faces = {:bigger => BASE_LINK + username + "/73.jpg", :normal => BASE_LINK + username + "/48.jpg", :epic => BASE_LINK + username + "/128.jpg", :mini => BASE_LINK + username + "/24.jpg" } end
man(format="epic")
click to toggle source
# File lib/ui_faces.rb, line 141 def self.man(format="epic") return retrieve_a_link(format, MEN) end
sex(genre="male", format="epic")
click to toggle source
# File lib/ui_faces.rb, line 145 def self.sex(genre="male", format="epic") if ( genre.eql?("female") or (genre.eql?("woman"))) return retrieve_a_link(format, WOMEN) else return retrieve_a_link(format, MEN) end end
woman(format="epic")
click to toggle source
Only one parameter
# File lib/ui_faces.rb, line 137 def self.woman(format="epic") return retrieve_a_link(format, WOMEN) end
Private Class Methods
local_random(format="epic")
click to toggle source
# File lib/ui_faces.rb, line 155 def self.local_random(format="epic") return retrieve_a_link(format, USERNAME) end
retrieve_a_link(format="epic", object_name=USERNAME)
click to toggle source
# File lib/ui_faces.rb, line 160 def self.retrieve_a_link(format="epic", object_name=USERNAME) return BASE_LINK + object_name.sample + "/" + width(format) + ".jpg" end
width(format)
click to toggle source
# File lib/ui_faces.rb, line 165 def self.width(format) if(format.eql?"bigger") '73' elsif (format.eql?"normal") '48' elsif (format.eql?"mini") '24' else '128' end end