lib/social_profile/people/facebook.rb in social_profile-0.2.2 vs lib/social_profile/people/facebook.rb in social_profile-0.3.0
- old
+ new
@@ -9,10 +9,17 @@
"comments.fields(created_time).limit(1).summary(true)",
"likes.limit(1).fields(id).summary(true)",
"created_time",
"shares"
]
+ POST_FIELDS = [
+ "comments.fields(created_time).limit(1).summary(true)",
+ "likes.limit(1).fields(id).summary(true)",
+ "created_time",
+ "shares"
+ ]
+ MUTUAL_FRIENDS = "SELECT uid, mutual_friend_count FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY mutual_friend_count"
# Find album by id
def fetch_album(album_id)
::FbGraph::Album.fetch(album_id, :access_token => access_token)
end
@@ -29,11 +36,11 @@
end
# Get followers count
#
def followers_count
- @followers_count ||= followers(:limit => 1).total_count
+ @followers_count ||= followers(:limit => 1).size
end
def fetch_friends_count
response = FbGraph::Query.new(FRIENDS_FQL).fetch(:access_token => access_token)
@@ -72,22 +79,22 @@
limit = options[:limit] || 100
max_iteration = options[:max_iteration] || 100
iteration = 0
posts = collection = last_posts(limit, options)
- return [] if posts.blank?
+ return [] if posts.blank? || posts.last.created_time.nil?
last_created_time = posts.last.created_time
- while last_created_time > date && !last_created_time.blank? && iteration < max_iteration
+ while !last_created_time.blank? && last_created_time > date && iteration < max_iteration
iteration += 1
collection = collection.next
posts += collection
last_created_time = posts.last.created_time
end
- posts.select { |p| p.created_time > date }
+ posts.select { |p| p.created_time && p.created_time > date }
end
# Get all friends list
#
def friends(options={})
@@ -96,10 +103,13 @@
end
# Get all followers list
#
def followers(options={})
+ # Not avaiable since 30.04.2015
+ return []
+
limit = options[:limit] || 5000
fetch_all = options[:fetch_all] || false
iteration = 0
_followers = collection = user.subscribers(:limit => limit)
@@ -114,13 +124,31 @@
end
_followers
end
+ # Get post from feed with comments, shares and likes counters
+ #
+ def fetch_post(post_uid, options = {})
+ fields = options[:fields] || POST_FIELDS
+
+ ::FbGraph::Post.fetch(post_uid, :fields => fields.join(","), :access_token => access_token)
+ end
+
+ # Get friends list with mutual friends counter
+ #
+ def mutual_friends(options={})
+ response = FbGraph::Query.new(MUTUAL_FRIENDS).fetch(:access_token => access_token)
+
+ return {} unless response.is_a?(Array)
+
+ response.inject({}) {|h, a| h.merge!(a["uid"] => a["mutual_friend_count"]) }
+ end
+
protected
def user
@user ||= ::FbGraph::User.me(access_token)
end
end
end
-end
\ No newline at end of file
+end