Class: SocialProfile::People::Facebook
- Inherits:
-
SocialProfile::Person
- Object
- SocialProfile::Person
- SocialProfile::People::Facebook
- Defined in:
- lib/social_profile/people/facebook.rb
Constant Summary collapse
- LAST_POSTS_FIELDS =
[ "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" ]
Instance Attribute Summary
Attributes inherited from SocialProfile::Person
Instance Method Summary collapse
-
#album!(options = {}) ⇒ Object
Create new album id.
-
#fetch_album(album_id) ⇒ Object
Find album by id.
-
#fetch_post(post_uid, options = {}) ⇒ Object
Get post from feed with comments, shares and likes counters.
-
#first_post_exists?(year) ⇒ Boolean
Check if exists any post before current year.
-
#followers(options = {}) ⇒ Object
Get all followers list.
-
#followers_count ⇒ Object
Get followers count.
-
#friends(options = {}) ⇒ Object
Get all friends list.
-
#friends_count ⇒ Object
Get friends count.
-
#last_post_by_days(days, options = {}) ⇒ Object
Get last post by days from feed with comments, shares and likes counters.
-
#last_posts(limit, options = {}) ⇒ Object
Get last limited posts from feed with comments, shares and likes counters.
-
#mutual_friends(options = {}) ⇒ Object
Get friends list with mutual friends counter.
Methods inherited from SocialProfile::Person
#find_album, #find_or_create_album, get, #initialize, #share_photo!, #tag_object!
Constructor Details
This class inherits a constructor from SocialProfile::Person
Instance Method Details
#album!(options = {}) ⇒ Object
Create new album id
25 26 27 |
# File 'lib/social_profile/people/facebook.rb', line 25 def album!( = {}) user.album!() end |
#fetch_album(album_id) ⇒ Object
Find album by id
20 21 22 |
# File 'lib/social_profile/people/facebook.rb', line 20 def fetch_album(album_id) ::FbGraph2::Album.fetch(album_id, :access_token => access_token) end |
#fetch_post(post_uid, options = {}) ⇒ Object
Get post from feed with comments, shares and likes counters
112 113 114 115 116 |
# File 'lib/social_profile/people/facebook.rb', line 112 def fetch_post(post_uid, = {}) fields = [:fields] || POST_FIELDS ::FbGraph2::Post.fetch(post_uid, :fields => fields.join(","), :access_token => access_token) end |
#first_post_exists?(year) ⇒ Boolean
Check if exists any post before current year
43 44 45 46 |
# File 'lib/social_profile/people/facebook.rb', line 43 def first_post_exists?(year) # TODO return nil end |
#followers(options = {}) ⇒ Object
Get all followers list
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/social_profile/people/facebook.rb', line 88 def followers(={}) # Not avaiable since 30.04.2015 return [] limit = [:limit] || 5000 fetch_all = [:fetch_all] || false iteration = 0 _followers = collection = user.subscribers(:limit => limit) max_iteration = _followers.total_count / limit + 1 if fetch_all while iteration < max_iteration iteration += 1 collection = collection.next _followers += collection end end _followers end |
#followers_count ⇒ Object
Get followers count
37 38 39 |
# File 'lib/social_profile/people/facebook.rb', line 37 def followers_count @followers_count ||= followers(:limit => 1).size end |
#friends(options = {}) ⇒ Object
Get all friends list
81 82 83 84 |
# File 'lib/social_profile/people/facebook.rb', line 81 def friends(={}) limit = [:limit] || 5000 user.friends(:limit => limit) end |
#friends_count ⇒ Object
Get friends count
31 32 33 |
# File 'lib/social_profile/people/facebook.rb', line 31 def friends_count @friends_count ||= friends(limit: 1).summary['total_count'] end |
#last_post_by_days(days, options = {}) ⇒ Object
Get last post by days from feed with comments, shares and likes counters
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/social_profile/people/facebook.rb', line 58 def last_post_by_days(days, ={}) date = ([:date_end] || Time.now) - days.days limit = [:limit] || 100 max_iteration = [:max_iteration] || 100 iteration = 0 posts = collection = last_posts(limit, ) return [] if posts.blank? || posts.last.created_time.nil? last_created_time = posts.last.created_time 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 && p.created_time > date } end |
#last_posts(limit, options = {}) ⇒ Object
Get last limited posts from feed with comments, shares and likes counters
50 51 52 53 54 |
# File 'lib/social_profile/people/facebook.rb', line 50 def last_posts(limit, = {}) fields = [:fields] || LAST_POSTS_FIELDS user.feed(:fields => fields.join(","), :limit => limit) end |
#mutual_friends(options = {}) ⇒ Object
Get friends list with mutual friends counter
120 121 122 |
# File 'lib/social_profile/people/facebook.rb', line 120 def mutual_friends(={}) return {} end |