class Fb::User

Provides methods to get a collection of pages that an access token is allowed to manage and get page insights on those pages.

Attributes

access_token[R]

Public Class Methods

new(access_token) click to toggle source

@access_token The access token returned by Facebook's OAuth flow.

# File lib/fb/user.rb, line 6
def initialize(access_token)
  @access_token = access_token
end

Public Instance Methods

email() click to toggle source

@return [String] the email of the Facebook user.

# File lib/fb/user.rb, line 11
def email
  @email ||= begin
    response_body = Fb::Request.new(path: '/me',
      params: {fields: :email, access_token: @access_token}).run
    response_body["email"]
  end
end
pages() click to toggle source

@return [Array] a collection of pages available to the given access token.

# File lib/fb/user.rb, line 20
def pages
  @pages ||= begin
    response_body = Fb::Request.new(path: '/me/accounts',
      params: {access_token: @access_token}).run
    response_body["data"].map do |page_data|
      Fb::Page.new page_data.merge('user' => self)
    end
  end
end