Class: EmailToFace::App
- Inherits:
-
Object
- Object
- EmailToFace::App
- Defined in:
- lib/email_to_face/app.rb
Instance Attribute Summary collapse
-
#face_init ⇒ Object
Returns the value of attribute face_init.
-
#fb_init ⇒ Object
Returns the value of attribute fb_init.
-
#fb_type ⇒ Object
Returns the value of attribute fb_type.
Instance Method Summary collapse
- #convert(email) ⇒ Object
-
#initialize(options = {}) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(options = {}) ⇒ App
Returns a new instance of App.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/email_to_face/app.rb', line 5 def initialize(={}) # Initialize Facebook if params present if [:facebook_user_token] Facebook.init([:facebook_user_token], [:facebook_image_type]) @fb_init = true @fb_type = [:facebook_image_type] end # Initialize Face.com API if params present if [:face_api_key] and [:face_api_secret] FaceAPI.init([:face_api_key], [:face_api_secret], [:use_face_for_gravatar]) @face_init = true end end |
Instance Attribute Details
#face_init ⇒ Object
Returns the value of attribute face_init.
3 4 5 |
# File 'lib/email_to_face/app.rb', line 3 def face_init @face_init end |
#fb_init ⇒ Object
Returns the value of attribute fb_init.
3 4 5 |
# File 'lib/email_to_face/app.rb', line 3 def fb_init @fb_init end |
#fb_type ⇒ Object
Returns the value of attribute fb_type.
3 4 5 |
# File 'lib/email_to_face/app.rb', line 3 def fb_type @fb_type end |
Instance Method Details
#convert(email) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/email_to_face/app.rb', line 22 def convert(email) raise ArgumentError, "must pass a valid email address" if email.nil? or !email.match(/^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i) # First query facebook if initialized if @fb_init image_url = Facebook.user_image(email) end # If not found and twitter is initialized if image_url.nil? image_url = Gravatar.user_image(email, @fb_type) end # If still no image found, return nil return nil if image_url.nil? # If present, grab face x,y from face.com if @face_init and xy = FaceAPI.get_center(image_url) { :url => image_url, :x => xy['x'], :y => xy['y'] } else { :url => image_url } end end |