Class: Facebook::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/facebook/client.rb

Overview

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id, secret, options = {}, &block) ⇒ Client

Returns a new instance of Client.



27
28
29
30
31
# File 'lib/facebook/client.rb', line 27

def initialize(app_id, secret, options = {}, &block)
  @oauth = self.class.oauth_client(app_id, secret, &block)
  @default_params = { :scope => options[:permissions], :display => options[:display] }
  @user_fields = Array(options[:user_fields])
end

Class Attribute Details

.last_oauth_clientObject (readonly)

Returns the value of attribute last_oauth_client.



7
8
9
# File 'lib/facebook/client.rb', line 7

def last_oauth_client
  @last_oauth_client
end

Instance Attribute Details

#oauthObject (readonly)

Returns the value of attribute oauth.



25
26
27
# File 'lib/facebook/client.rb', line 25

def oauth
  @oauth
end

Class Method Details

.access_token_optionsObject



17
18
19
# File 'lib/facebook/client.rb', line 17

def self.access_token_options
  {:mode => :query, :param_name => 'access_token'}
end

.oauth_client(app_id, secret, &block) ⇒ Object



10
11
12
13
14
15
# File 'lib/facebook/client.rb', line 10

def self.oauth_client(app_id, secret, &block)
  @last_oauth_client = OAuth2::Client.new app_id, secret,
    :site => 'https://graph.facebook.com',
    :token_url => '/oauth/access_token',
    &block
end

.restore_access_token(token_string) ⇒ Object



21
22
23
# File 'lib/facebook/client.rb', line 21

def self.restore_access_token(token_string)
  OAuth2::AccessToken.new(last_oauth_client, token_string, access_token_options)
end

Instance Method Details

#authorize_url(params = {}) ⇒ Object

params: redirect_uri, scope, display



34
35
36
# File 'lib/facebook/client.rb', line 34

def authorize_url(params = {})
  @oauth.auth_code.authorize_url(@default_params.merge(params))
end

#get_access_token(code, redirect_uri) ⇒ Object



38
39
40
41
42
# File 'lib/facebook/client.rb', line 38

def get_access_token(code, redirect_uri)
  token = @oauth.auth_code.get_token(code, :redirect_uri => redirect_uri, :parse => :query)
  token.options.update(self.class.access_token_options)
  token
end

#get_user_info(access_token, path) ⇒ Object



48
49
50
# File 'lib/facebook/client.rb', line 48

def (access_token, path)
  access_token.get(path, :fields => @user_fields.join(','))
end

#login_handler(options = {}) ⇒ Object



44
45
46
# File 'lib/facebook/client.rb', line 44

def (options = {})
  Login.new(self, options)
end