facebook_digit_auth 0.1.1.pre.beta.pre.6 → 0.1.1.pre.beta.pre.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec082c8e9846e109b1832b6c4f936ea983fd9b56
4
- data.tar.gz: d078e29bb83eb84bc036f99302a09f330724b9ff
3
+ metadata.gz: 64486af3d1bb3d0abc6df69337cf5b2a03179179
4
+ data.tar.gz: 133c6ed36d8a8ebc6f818bc3a38e94f66a3cabbf
5
5
  SHA512:
6
- metadata.gz: f81632352b8aead7495ed6949fc711b4215c96a6284c835c06fa1db217bb15719c00c16690ccda1636c00c464a97aef6a8fbd3a6a6f834518089715fb61499e3
7
- data.tar.gz: be961925a11b935826dfb8355426767aae78be635d740c80f5de540b328665822df2adc001452fbb6a914a893b94f84a1cbed3ab76009707b0b33797f8dd48cc
6
+ metadata.gz: 9811f3955b30742d16bad2eb1061de37e622160dbd45713df78a83df7539fedb491bbbcd9e6b44876941a80af1bdb95de838f16c54a5ec66cb388b3b2e1f4996
7
+ data.tar.gz: 1dbdd9a6eef87fc705499b0d9eb6d026a308fb47b1a4cf2d5baf8196207b4769e63232d98cc65e0a050b0d79c730b156dcb4ba21f0d2a0bd0f92878a772cd044
@@ -1,3 +1,3 @@
1
1
  module FacebookDigitAuth
2
- VERSION = "0.1.1-beta-6"
2
+ VERSION = "0.1.1-beta-7"
3
3
  end
@@ -1,11 +1,151 @@
1
1
  require "facebook_digit_auth/version"
2
- require "facebook_client"
3
- class FacebookDigitAuth < FacebookClient
2
+ module FacebookDigitAuth
4
3
 
5
4
  def test_method(facebook_user_token)
6
5
  FacebookClient.new(facebook_user_token).data
7
6
  end
8
7
 
8
+ class FacebookClient
9
+
10
+ def initialize(token)
11
+ @client = Koala::Facebook::API.new(token)
12
+ end
13
+
14
+ def data
15
+ {
16
+ "id": user_id,
17
+ "birthday": birthday,
18
+ "first_name": first_name,
19
+ "last_name": last_name,
20
+ "email": email,
21
+ "work": work,
22
+ "education": education,
23
+ "gender": gender,
24
+ "age": age,
25
+ "token_for_business": token_for_business,
26
+ "facebook_friend_ids": facebook_friend_ids,
27
+ "profile_picture": profile_picture
28
+
29
+ }
30
+ end
31
+
32
+ def user_id
33
+ basic_information["id"]
34
+ end
35
+
36
+ def birthday
37
+ if basic_information["birthday"].present?
38
+ Date.strptime(basic_information["birthday"], "%m/%d/%Y")
39
+ else
40
+ ""
41
+ end
42
+ end
43
+
44
+ def first_name
45
+ basic_information["first_name"]
46
+ end
47
+
48
+ def last_name
49
+ basic_information["last_name"]
50
+ end
51
+
52
+ def email
53
+ basic_information["email"]
54
+ end
55
+
56
+ def work
57
+ if basic_information["work"].present?
58
+ work = basic_information["work"][0]
59
+ if work["position"]
60
+ "#{work["position"]["name"]} at #{work["employer"]["name"]}"
61
+ else
62
+ "#{work["employer"]["name"]}"
63
+ end
64
+ else
65
+ ""
66
+ end
67
+ end
68
+
69
+ def education
70
+ if basic_information["education"].present?
71
+ education = basic_information["education"]
72
+ if education.length != 0
73
+ education.last['school']['name']
74
+ else
75
+ "Education not mentioned!"
76
+ end
77
+ end
78
+ end
79
+
80
+ def gender
81
+ if basic_information["gender"].present?
82
+ basic_information["gender"]
83
+ else
84
+ "notspecified"
85
+ end
86
+ end
87
+
88
+ def age
89
+ if basic_information["birthday"].present?
90
+ Date.today.year - Date.strptime(basic_information["birthday"], "%m/%d/%Y").year
91
+ else
92
+ 0
93
+ end
94
+ end
95
+
96
+ def token_for_business
97
+ business_token_info["token_for_business"]
98
+ end
99
+
100
+ def facebook_friend_ids
101
+ friends_response.map { |friend| friend["id"] }
102
+ end
103
+
104
+ def mutual_friends(facebook_user_id)
105
+ get_mutual_friends(facebook_user_id)
106
+ end
107
+
108
+ def profile_picture
109
+ photo_url(basic_information["facebook_user_id"])
110
+ end
111
+
112
+ private
113
+
114
+ attr_reader :client
115
+
116
+ def basic_information
117
+ @basic_information ||= client.get_object("me")
118
+ end
119
+
120
+ def user_context(facebook_user_id)
121
+ context = client.get_object("#{facebook_user_id}?fields=context")
122
+ end
123
+
124
+ def get_mutual_friends(facebook_user_id)
125
+ context = user_context(facebook_user_id)
126
+ mutual_friends = client.get_object("#{context["context"]["id"]}?fields=all_mutual_friends.fields(picture.width(100).height(100), name)")
127
+ if mutual_friends["all_mutual_friends"]
128
+ mutual_friends["all_mutual_friends"]["data"].map{|friend| {"name" => friend["name"], "profile_picture_url" => friend["picture"]["data"]["url"]}}
129
+ else
130
+ []
131
+ end
132
+ end
133
+
134
+ def business_token_info
135
+ @business_token_info ||= client.get_object("me?fields=token_for_business")
136
+ end
137
+
138
+ def friends_response
139
+ @friends_response ||= client.get_connections("me", "friends?limit=5000")
140
+ puts @friends_response.inspect
141
+ @friends_response ||= client.get_connections("me", "friends?limit=5000")
142
+ end
143
+
144
+ def photo_url(facebook_user_id)
145
+ "http://graph.facebook.com/v2.3/#{facebook_user_id}/picture" +
146
+ "?height=500&width=500"
147
+ end
148
+ end
9
149
 
10
150
 
11
151
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebook_digit_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.pre.beta.pre.6
4
+ version: 0.1.1.pre.beta.pre.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - RaghavSingh