Class: Fb::User

Inherits:
Object
  • Object
show all
Defined in:
lib/fb/user.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ User

Returns a new instance of User.



6
7
8
# File 'lib/fb/user.rb', line 6

def initialize(access_token)
  @access_token = access_token
end

Instance Method Details

#emailString

Returns the email of the Facebook user.

Returns:

  • (String)

    the email of the Facebook user.



11
12
13
14
15
16
17
# 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

#pagesArray

Returns a collection of pages available to the given access token.

Returns:

  • (Array)

    a collection of pages available to the given access token.



20
21
22
23
24
25
26
27
28
# 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