Sha256: 6c9e3d7634ffa3698c15d6c140de6f2fbb504c8002a099702825d3520d1d53a0

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Fb
  # Provides methods to interact with Facebook users through the Graph API.
  # @see https://developers.facebook.com/docs/graph-api/reference/user/
  class User
    # @param [Hash] options to initialize a User object.
    # @option [String] :access_token an access token for the user.
    def initialize(options = {})
      @access_token = options[:access_token]
    end

    # @return [String] the user’s email address.
    def email
      @email ||= begin
        params = {fields: :email, access_token: @access_token}
        request = HTTPRequest.new path: '/me', params: params
        request.run.body['email']
      end
    end

    # @return [Array<Fb::Page>] the pages managed by the user.
    def pages
      @pages ||= begin
        params = {access_token: @access_token}
        request = HTTPRequest.new path: '/me/accounts', params: params
        request.run.body['data'].map do |page_data|
          Page.new symbolize_keys(page_data)
        end
      end
    end

  private

    def symbolize_keys(hash)
      {}.tap do |new_hash|
        hash.each_key{|key| new_hash[key.to_sym] = hash[key]}
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fb-core-1.0.0.alpha2 lib/fb/user.rb
fb-core-1.0.0.alpha1 lib/fb/user.rb