class FacebookClient
Attributes
client[R]
Public Class Methods
new(token)
click to toggle source
# File lib/facebook_client.rb, line 4 def initialize(token) @client = Koala::Facebook::API.new(token) end
Public Instance Methods
age()
click to toggle source
# File lib/facebook_client.rb, line 81 def age if basic_information["birthday"].present? Date.today.year - Date.strptime(basic_information["birthday"], "%m/%d/%Y").year else 0 end end
birthday()
click to toggle source
# File lib/facebook_client.rb, line 29 def birthday if basic_information["birthday"].present? Date.strptime(basic_information["birthday"], "%m/%d/%Y") else "" end end
data()
click to toggle source
# File lib/facebook_client.rb, line 8 def data { "id": user_id, "birthday": birthday, "first_name": first_name, "last_name": last_name, "email": email, "work": work, "education": education, "gender": gender, "age": age, "facebook_friend_ids": facebook_friend_ids, "profile_picture": profile_picture } end
education()
click to toggle source
# File lib/facebook_client.rb, line 62 def education if basic_information["education"].present? education = basic_information["education"] if education.length != 0 education.last['school']['name'] else "Education not mentioned!" end end end
email()
click to toggle source
# File lib/facebook_client.rb, line 45 def email basic_information["email"] end
facebook_friend_ids()
click to toggle source
# File lib/facebook_client.rb, line 93 def facebook_friend_ids friends_response.map { |friend| friend["id"] } end
first_name()
click to toggle source
# File lib/facebook_client.rb, line 37 def first_name basic_information["first_name"] end
gender()
click to toggle source
# File lib/facebook_client.rb, line 73 def gender if basic_information["gender"].present? basic_information["gender"] else "notspecified" end end
last_name()
click to toggle source
# File lib/facebook_client.rb, line 41 def last_name basic_information["last_name"] end
mutual_friends(facebook_user_id)
click to toggle source
# File lib/facebook_client.rb, line 97 def mutual_friends(facebook_user_id) get_mutual_friends(facebook_user_id) end
profile_picture()
click to toggle source
# File lib/facebook_client.rb, line 101 def profile_picture photo_url(basic_information["facebook_user_id"]) end
token_for_business()
click to toggle source
# File lib/facebook_client.rb, line 89 def token_for_business business_token_info["token_for_business"] end
user_id()
click to toggle source
# File lib/facebook_client.rb, line 25 def user_id basic_information["id"] end
work()
click to toggle source
# File lib/facebook_client.rb, line 49 def work if basic_information["work"].present? work = basic_information["work"][0] if work["position"] "#{work["position"]["name"]} at #{work["employer"]["name"]}" else "#{work["employer"]["name"]}" end else "" end end
Private Instance Methods
basic_information()
click to toggle source
# File lib/facebook_client.rb, line 109 def basic_information @basic_information ||= client.get_object("me",fields:'first_name,last_name,email,birthday,education,work,gender') end
business_token_info()
click to toggle source
# File lib/facebook_client.rb, line 127 def business_token_info @business_token_info ||= client.get_object("me?fields=token_for_business") end
friends_response()
click to toggle source
# File lib/facebook_client.rb, line 131 def friends_response @friends_response ||= client.get_connections("me", "friends?limit=5000") @friends_response ||= client.get_connections("me", "friends?limit=5000") end
get_mutual_friends(facebook_user_id)
click to toggle source
# File lib/facebook_client.rb, line 117 def get_mutual_friends(facebook_user_id) context = user_context(facebook_user_id) mutual_friends = client.get_object("#{context["context"]["id"]}?fields=all_mutual_friends.fields(picture.width(100).height(100), name)") if mutual_friends["all_mutual_friends"] mutual_friends["all_mutual_friends"]["data"].map{|friend| {"name" => friend["name"], "profile_picture_url" => friend["picture"]["data"]["url"]}} else [] end end
photo_url(facebook_user_id)
click to toggle source
# File lib/facebook_client.rb, line 136 def photo_url(facebook_user_id) "http://graph.facebook.com/v2.3/#{facebook_user_id}/picture" + "?height=500&width=500" end
user_context(facebook_user_id)
click to toggle source
# File lib/facebook_client.rb, line 113 def user_context(facebook_user_id) context = client.get_object("#{facebook_user_id}?fields=context") end