Class: FacebookClient
- Inherits:
-
Object
- Object
- FacebookClient
- Defined in:
- lib/facebook_client.rb
Instance Method Summary collapse
- #age ⇒ Object
- #birthday ⇒ Object
- #data ⇒ Object
- #education ⇒ Object
- #email ⇒ Object
- #facebook_friend_ids ⇒ Object
- #first_name ⇒ Object
- #gender ⇒ Object
-
#initialize(token) ⇒ FacebookClient
constructor
A new instance of FacebookClient.
- #last_name ⇒ Object
- #mutual_friends(facebook_user_id) ⇒ Object
- #profile_picture ⇒ Object
- #token_for_business ⇒ Object
- #user_id ⇒ Object
- #work ⇒ Object
Constructor Details
#initialize(token) ⇒ FacebookClient
Returns a new instance of FacebookClient.
4 5 6 |
# File 'lib/facebook_client.rb', line 4 def initialize(token) @client = Koala::Facebook::API.new(token) end |
Instance Method Details
#age ⇒ Object
81 82 83 84 85 86 87 |
# 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 ⇒ Object
29 30 31 32 33 34 35 |
# 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 ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# 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 ⇒ Object
45 46 47 |
# File 'lib/facebook_client.rb', line 45 def email basic_information["email"] end |
#facebook_friend_ids ⇒ Object
93 94 95 |
# File 'lib/facebook_client.rb', line 93 def facebook_friend_ids friends_response.map { |friend| friend["id"] } end |
#first_name ⇒ Object
37 38 39 |
# File 'lib/facebook_client.rb', line 37 def first_name basic_information["first_name"] end |
#gender ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/facebook_client.rb', line 73 def gender if basic_information["gender"].present? basic_information["gender"] else "notspecified" end end |
#last_name ⇒ Object
41 42 43 |
# File 'lib/facebook_client.rb', line 41 def last_name basic_information["last_name"] end |
#mutual_friends(facebook_user_id) ⇒ Object
97 98 99 |
# File 'lib/facebook_client.rb', line 97 def mutual_friends(facebook_user_id) get_mutual_friends(facebook_user_id) end |
#profile_picture ⇒ Object
101 102 103 |
# File 'lib/facebook_client.rb', line 101 def profile_picture photo_url(basic_information["facebook_user_id"]) end |
#token_for_business ⇒ Object
89 90 91 |
# File 'lib/facebook_client.rb', line 89 def token_for_business business_token_info["token_for_business"] end |
#user_id ⇒ Object
25 26 27 |
# File 'lib/facebook_client.rb', line 25 def user_id basic_information["id"] end |
#work ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 |