social_profile 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ff2a46cb1b8edb78c457fb204d2efac1035b642
4
- data.tar.gz: e843f72028951caa385e61478566a2eda9ba31ae
3
+ metadata.gz: fdac7e14e4ac53d6ed004757214c21d530ee41c8
4
+ data.tar.gz: bf33b21598dc7bf2a1615c5ee1c3385842a406f0
5
5
  SHA512:
6
- metadata.gz: 889b1b58ae675301c69a86282700b552cae13d99f441bacf9b2d74c579e06110942fddaadd687a1f075420b9fc0436d5d953628be875fe7c2315db83245f00dc
7
- data.tar.gz: 9108fb8234539617a98bf26c94247515a10b32b7e804b697e365e5d6d45fd7048f944c990086815ebabec2ffd90e1c6c72b718ec0ea4b2f2ba354f0b4cbedc6f
6
+ metadata.gz: 9647a224c9e7d0de76ffad852de0143a0bdee4fc66b11f0df6c51df645fb270673044f15e5a7a49c39d190490eb95216321727be8cb9dd33c61b990d479f4009
7
+ data.tar.gz: 5095bf772342c7f5a6f5807edab3e58bb979d83140ccff35657d17e2762ab56f2eb49da8e93aab9ecba2a9d6887499af0974e395499870216ef4c4b03ae9d15f
@@ -11,6 +11,13 @@ module SocialProfile
11
11
  "created_time",
12
12
  "shares"
13
13
  ]
14
+ POST_FIELDS = [
15
+ "comments.fields(created_time).limit(1).summary(true)",
16
+ "likes.limit(1).fields(id).summary(true)",
17
+ "created_time",
18
+ "shares"
19
+ ]
20
+ MUTUAL_FRIENDS = "SELECT uid, mutual_friend_count FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY mutual_friend_count"
14
21
 
15
22
  # Find album by id
16
23
  def fetch_album(album_id)
@@ -31,7 +38,7 @@ module SocialProfile
31
38
  # Get followers count
32
39
  #
33
40
  def followers_count
34
- @followers_count ||= followers(:limit => 1).total_count
41
+ @followers_count ||= followers(:limit => 1).size
35
42
  end
36
43
 
37
44
  def fetch_friends_count
@@ -74,18 +81,18 @@ module SocialProfile
74
81
  iteration = 0
75
82
 
76
83
  posts = collection = last_posts(limit, options)
77
- return [] if posts.blank?
84
+ return [] if posts.blank? || posts.last.created_time.nil?
78
85
 
79
86
  last_created_time = posts.last.created_time
80
87
 
81
- while last_created_time > date && !last_created_time.blank? && iteration < max_iteration
88
+ while !last_created_time.blank? && last_created_time > date && iteration < max_iteration
82
89
  iteration += 1
83
90
  collection = collection.next
84
91
  posts += collection
85
92
  last_created_time = posts.last.created_time
86
93
  end
87
94
 
88
- posts.select { |p| p.created_time > date }
95
+ posts.select { |p| p.created_time && p.created_time > date }
89
96
  end
90
97
 
91
98
  # Get all friends list
@@ -98,6 +105,9 @@ module SocialProfile
98
105
  # Get all followers list
99
106
  #
100
107
  def followers(options={})
108
+ # Not avaiable since 30.04.2015
109
+ return []
110
+
101
111
  limit = options[:limit] || 5000
102
112
  fetch_all = options[:fetch_all] || false
103
113
  iteration = 0
@@ -116,6 +126,24 @@ module SocialProfile
116
126
  _followers
117
127
  end
118
128
 
129
+ # Get post from feed with comments, shares and likes counters
130
+ #
131
+ def fetch_post(post_uid, options = {})
132
+ fields = options[:fields] || POST_FIELDS
133
+
134
+ ::FbGraph::Post.fetch(post_uid, :fields => fields.join(","), :access_token => access_token)
135
+ end
136
+
137
+ # Get friends list with mutual friends counter
138
+ #
139
+ def mutual_friends(options={})
140
+ response = FbGraph::Query.new(MUTUAL_FRIENDS).fetch(:access_token => access_token)
141
+
142
+ return {} unless response.is_a?(Array)
143
+
144
+ response.inject({}) {|h, a| h.merge!(a["uid"] => a["mutual_friend_count"]) }
145
+ end
146
+
119
147
  protected
120
148
 
121
149
  def user
@@ -123,4 +151,4 @@ module SocialProfile
123
151
  end
124
152
  end
125
153
  end
126
- end
154
+ end
@@ -0,0 +1,21 @@
1
+ require "instagram"
2
+
3
+ module SocialProfile
4
+ module People
5
+ class Instagram < Person
6
+ POSTS_COUNT = 100
7
+
8
+ def last_posts(options={})
9
+ limit = options[:limit] || POSTS_COUNT
10
+
11
+ client.user_recent_media count: limit
12
+ end
13
+
14
+ protected
15
+
16
+ def client
17
+ ::Instagram.client(access_token: access_token)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -167,6 +167,27 @@ module SocialProfile
167
167
 
168
168
  fetch_all_method_items(:fetch_followers, options)
169
169
  end
170
+
171
+ # Get post by id
172
+ #
173
+ def get_post(post_uid, options={})
174
+ options = {
175
+ :posts => post_uid,
176
+ :extended => 1
177
+ }.merge(options)
178
+
179
+ user.wall.getById(options)
180
+ end
181
+
182
+ # Get mutual friends (options target_uids is required)
183
+ #
184
+ def mutual_friends(options={})
185
+ response = user.friends.getMutual(options)
186
+
187
+ return {} unless response.is_a?(Array)
188
+
189
+ response.inject({}) {|h, a| h.merge!(a["id"].to_s => a["common_count"]) }
190
+ end
170
191
 
171
192
  protected
172
193
 
@@ -17,6 +17,7 @@ module SocialProfile
17
17
  when "facebook" then People::Facebook
18
18
  when "vkontakte" then People::Vkontakte
19
19
  when "twitter" then People::Twitter
20
+ when "instagram" then People::Instagram
20
21
  else Person
21
22
  end
22
23
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module SocialProfile
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  end
@@ -18,6 +18,7 @@ module SocialProfile
18
18
  autoload :Facebook, "social_profile/people/facebook"
19
19
  autoload :Vkontakte, "social_profile/people/vkontakte"
20
20
  autoload :Twitter, "social_profile/people/twitter"
21
+ autoload :Instagram, "social_profile/people/instagram"
21
22
  end
22
23
 
23
24
  def self.get(auth_hash, options = {})
@@ -6,7 +6,7 @@ require 'social_profile/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "social_profile"
8
8
  spec.version = SocialProfile::VERSION
9
- spec.authors = ["Igor Galeta"]
9
+ spec.authors = ["Igor Galeta", "Pavel Galeta"]
10
10
  spec.email = ["galeta.igor@gmail.com"]
11
11
  spec.description = %q{Wrapper for Omniauth profile hash, post photo to album}
12
12
  spec.summary = %q{Wrapper for Omniauth profile hash}
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "fb_graph", '~> 2.7.16'
25
25
  spec.add_dependency "vkontakte", '~> 0.0.6'
26
26
  spec.add_dependency "twitter", '~> 5.11.0'
27
+ spec.add_dependency "instagram", '~> 1.1.6'
27
28
  spec.add_dependency "httpclient"
28
29
  spec.add_dependency "multi_json"
29
30
  end