class SocialProfile::People::Facebook

Constants

LAST_POSTS_FIELDS
POST_FIELDS

Public Instance Methods

album!(options = {}) click to toggle source

Create new album id

# File lib/social_profile/people/facebook.rb, line 25
def album!(options = {})
  user.album!(options)
end
fetch_album(album_id) click to toggle source

Find album by id

# 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 = {}) click to toggle source

Get post from feed with comments, shares and likes counters

# File lib/social_profile/people/facebook.rb, line 112
def fetch_post(post_uid, options = {})
  fields = options[:fields] || POST_FIELDS

  ::FbGraph2::Post.fetch(post_uid, :fields => fields.join(","), :access_token => access_token)
end
first_post_exists?(year) click to toggle source

Check if exists any post before current year

# File lib/social_profile/people/facebook.rb, line 43
def first_post_exists?(year)
  # TODO
  return nil
end
followers(options={}) click to toggle source

Get all followers list

# File lib/social_profile/people/facebook.rb, line 88
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)
  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() click to toggle source

Get followers count

# File lib/social_profile/people/facebook.rb, line 37
def followers_count
  @followers_count ||= followers(:limit => 1).size
end
friends(options={}) click to toggle source

Get all friends list

# File lib/social_profile/people/facebook.rb, line 81
def friends(options={})
  limit = options[:limit] || 5000
  user.friends(:limit => limit)
end
friends_count() click to toggle source

Get friends count

# 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={}) click to toggle source

Get last post by days from feed with comments, shares and likes counters

# File lib/social_profile/people/facebook.rb, line 58
def last_post_by_days(days, options={})
  date = (options[:date_end] || Time.now) - days.days
  limit = options[:limit] || 100
  max_iteration = options[:max_iteration] || 100
  iteration = 0

  posts = collection = last_posts(limit, options)
  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 = {}) click to toggle source

Get last limited posts from feed with comments, shares and likes counters

# File lib/social_profile/people/facebook.rb, line 50
def last_posts(limit, options = {})
  fields = options[:fields] || LAST_POSTS_FIELDS

  user.feed(:fields => fields.join(","), :limit => limit)
end
mutual_friends(options={}) click to toggle source

Get friends list with mutual friends counter

# File lib/social_profile/people/facebook.rb, line 120
def mutual_friends(options={})
  return {}
end

Protected Instance Methods

user() click to toggle source
# File lib/social_profile/people/facebook.rb, line 126
def user
  @user ||= ::FbGraph2::User.me(access_token)
end