facebook_digit_auth 0.1.0 → 0.1.1.pre.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/facebook_client.rb +140 -0
- data/lib/facebook_digit_auth/version.rb +1 -1
- data/lib/facebook_digit_auth.rb +4 -4
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 602f3e54220a1afdeec789f942353a3c046a7ab1
|
4
|
+
data.tar.gz: ff293cc162458d8d06495a346e27efde2560abbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0f63bb598e1d2627e9b027ec8bfe59657defe74358fedaa983fedc4bf73c8ca073c0530fcdb9100c77106730c5a2d3f01a5bab06ac45b2387af603ecc661898
|
7
|
+
data.tar.gz: ac82e11deff984c1393edd995d4143d4a39ba436ea3f8f89e52b86f7093486161ba2497302939002c49163980dbecfc232b783a0da3fe19528e88c901796642a
|
@@ -0,0 +1,140 @@
|
|
1
|
+
class FacebookClient
|
2
|
+
def initialize(token)
|
3
|
+
@client = Koala::Facebook::API.new(token)
|
4
|
+
end
|
5
|
+
|
6
|
+
def data
|
7
|
+
{
|
8
|
+
"id": user_id,
|
9
|
+
"birthday": birthday,
|
10
|
+
"first_name": first_name,
|
11
|
+
"last_name": last_name,
|
12
|
+
"email": email,
|
13
|
+
"work": work,
|
14
|
+
"education": education,
|
15
|
+
"gender": gender,
|
16
|
+
"age": age,
|
17
|
+
"token_for_business": token_for_business,
|
18
|
+
"facebook_friend_ids": facebook_friend_ids,
|
19
|
+
"profile_picture": profile_picture
|
20
|
+
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def user_id
|
25
|
+
basic_information["id"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def birthday
|
29
|
+
if basic_information["birthday"].present?
|
30
|
+
Date.strptime(basic_information["birthday"], "%m/%d/%Y")
|
31
|
+
else
|
32
|
+
""
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def first_name
|
37
|
+
basic_information["first_name"]
|
38
|
+
end
|
39
|
+
|
40
|
+
def last_name
|
41
|
+
basic_information["last_name"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def email
|
45
|
+
basic_information["email"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def work
|
49
|
+
if basic_information["work"].present?
|
50
|
+
work = basic_information["work"][0]
|
51
|
+
if work["position"]
|
52
|
+
"#{work["position"]["name"]} at #{work["employer"]["name"]}"
|
53
|
+
else
|
54
|
+
"#{work["employer"]["name"]}"
|
55
|
+
end
|
56
|
+
else
|
57
|
+
""
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def education
|
62
|
+
if basic_information["education"].present?
|
63
|
+
education = basic_information["education"]
|
64
|
+
if education.length != 0
|
65
|
+
education.last['school']['name']
|
66
|
+
else
|
67
|
+
"Education not mentioned!"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def gender
|
73
|
+
if basic_information["gender"].present?
|
74
|
+
basic_information["gender"]
|
75
|
+
else
|
76
|
+
"notspecified"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def age
|
81
|
+
if basic_information["birthday"].present?
|
82
|
+
Date.today.year - Date.strptime(basic_information["birthday"], "%m/%d/%Y").year
|
83
|
+
else
|
84
|
+
0
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def token_for_business
|
89
|
+
business_token_info["token_for_business"]
|
90
|
+
end
|
91
|
+
|
92
|
+
def facebook_friend_ids
|
93
|
+
friends_response.map { |friend| friend["id"] }
|
94
|
+
end
|
95
|
+
|
96
|
+
def mutual_friends(facebook_user_id)
|
97
|
+
get_mutual_friends(facebook_user_id)
|
98
|
+
end
|
99
|
+
|
100
|
+
def profile_picture
|
101
|
+
photo_url(basic_information["facebook_user_id"])
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
attr_reader :client
|
107
|
+
|
108
|
+
def basic_information
|
109
|
+
@basic_information ||= client.get_object("me")
|
110
|
+
end
|
111
|
+
|
112
|
+
def user_context(facebook_user_id)
|
113
|
+
context = client.get_object("#{facebook_user_id}?fields=context")
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_mutual_friends(facebook_user_id)
|
117
|
+
context = user_context(facebook_user_id)
|
118
|
+
mutual_friends = client.get_object("#{context["context"]["id"]}?fields=all_mutual_friends.fields(picture.width(100).height(100), name)")
|
119
|
+
if mutual_friends["all_mutual_friends"]
|
120
|
+
mutual_friends["all_mutual_friends"]["data"].map{|friend| {"name" => friend["name"], "profile_picture_url" => friend["picture"]["data"]["url"]}}
|
121
|
+
else
|
122
|
+
[]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def business_token_info
|
127
|
+
@business_token_info ||= client.get_object("me?fields=token_for_business")
|
128
|
+
end
|
129
|
+
|
130
|
+
def friends_response
|
131
|
+
@friends_response ||= client.get_connections("me", "friends?limit=5000")
|
132
|
+
puts @friends_response.inspect
|
133
|
+
@friends_response ||= client.get_connections("me", "friends?limit=5000")
|
134
|
+
end
|
135
|
+
|
136
|
+
def photo_url(facebook_user_id)
|
137
|
+
"http://graph.facebook.com/v2.3/#{facebook_user_id}/picture" +
|
138
|
+
"?height=500&width=500"
|
139
|
+
end
|
140
|
+
end
|
data/lib/facebook_digit_auth.rb
CHANGED
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.
|
4
|
+
version: 0.1.1.pre.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RaghavSingh
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- bin/console
|
69
69
|
- bin/setup
|
70
70
|
- facebook_digit_auth.gemspec
|
71
|
+
- lib/facebook_client.rb
|
71
72
|
- lib/facebook_digit_auth.rb
|
72
73
|
- lib/facebook_digit_auth/version.rb
|
73
74
|
homepage: https://github.com/RaghavVishnoi/test_gem.git
|
@@ -85,9 +86,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
86
|
version: '0'
|
86
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
88
|
requirements:
|
88
|
-
- - "
|
89
|
+
- - ">"
|
89
90
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
91
|
+
version: 1.3.1
|
91
92
|
requirements: []
|
92
93
|
rubyforge_project:
|
93
94
|
rubygems_version: 2.5.1
|