Class: Fb::User
- Inherits:
-
Object
- Object
- Fb::User
- 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
-
#email ⇒ String
The email of the Facebook user.
-
#initialize(access_token) ⇒ User
constructor
A new instance of User.
-
#pages ⇒ Array
A collection of pages available to the given access token.
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
#email ⇒ String
Returns 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 |
#pages ⇒ Array
Returns 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 |