Class: Facebook::Client

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

Overview

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Client.



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

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

Class Attribute Details

.app_idObject

Returns the value of attribute app_id.



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

def app_id
  @app_id
end

.secretObject

Returns the value of attribute secret.



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

def secret
  @secret
end

Class Method Details

.oauth_client(app_id = nil, secret = nil) ⇒ Object



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

def self.oauth_client(app_id = nil, secret = nil)
  self.app_id, self.secret = app_id, secret unless app_id.nil?
  OAuth2::Client.new(self.app_id, self.secret, :site => 'https://graph.facebook.com')
end

Instance Method Details

#authorize_url(params = {}) ⇒ Object

params: redirect_uri, scope, display



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

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

#get_access_token(code, redirect_uri) ⇒ Object



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

def get_access_token(code, redirect_uri)
  @oauth.web_server.get_access_token(code, :redirect_uri => redirect_uri)
end

#get_user_info(access_token, path) ⇒ Object



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

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

#login_handler(options = {}) ⇒ Object



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

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

#restore_access_token(token_string) ⇒ Object



30
31
32
# File 'lib/facebook/client.rb', line 30

def restore_access_token(token_string)
  OAuth2::AccessToken.new(@oauth, token_string)
end