Sha256: 9e2263915749682e7aa586d9c1da3184f56e8c0e9c078370d5c3be09ae1b6802

Contents?: true

Size: 965 Bytes

Versions: 1

Compression:

Stored size: 965 Bytes

Contents

require 'fb/request'
require 'fb/page'

module Fb
  # Provides methods to get a collection of pages that an access token is
  # allowed to manage and get page insights on those pages.
  class User
    # @access_token The access token returned by Facebook's OAuth flow.
    def initialize(access_token)
      @access_token = access_token
    end

    # @return [String] the email of the Facebook user.
    def email
      @email ||= begin
        response_body = Fb::Request.new(path: '/me',
          params: {fields: :email, access_token: @access_token}).run
        response_body["email"]
      end
    end

    # @return [Array] a collection of pages available to the given access token.
    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
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fb-auth-0.1.0 lib/fb/user.rb