Class: FacebookClient

Inherits:
Object
  • Object
show all
Defined in:
lib/facebook_client.rb

Instance Method Summary collapse

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

#ageObject



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

#birthdayObject



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

#dataObject



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

#educationObject



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

#emailObject



45
46
47
# File 'lib/facebook_client.rb', line 45

def email
  basic_information["email"]
end

#facebook_friend_idsObject



93
94
95
# File 'lib/facebook_client.rb', line 93

def facebook_friend_ids
  friends_response.map { |friend| friend["id"] }
end

#first_nameObject



37
38
39
# File 'lib/facebook_client.rb', line 37

def first_name
  basic_information["first_name"]
end

#genderObject



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_nameObject



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_pictureObject



101
102
103
# File 'lib/facebook_client.rb', line 101

def profile_picture
	photo_url(basic_information["facebook_user_id"])
end

#token_for_businessObject



89
90
91
# File 'lib/facebook_client.rb', line 89

def token_for_business
  business_token_info["token_for_business"]
end

#user_idObject



25
26
27
# File 'lib/facebook_client.rb', line 25

def user_id
  basic_information["id"]
end

#workObject



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