Class: FacebookGraph::Authentication

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/facebook-graph/base/authentication.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HTTPHelper

#get

Constructor Details

#initialize(client_id, client_secret, redirect_uri = nil) ⇒ Authentication

Returns a new instance of Authentication.



4
5
6
7
# File 'lib/facebook-graph/base/authentication.rb', line 4

def initialize(client_id, client_secret, redirect_uri=nil)
  @client_id, @client_secret = client_id, client_secret
  @redirect_uri = redirect_uri
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



28
29
30
# File 'lib/facebook-graph/base/authentication.rb', line 28

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



28
29
30
# File 'lib/facebook-graph/base/authentication.rb', line 28

def client_secret
  @client_secret
end

#redirect_uriObject

Returns the value of attribute redirect_uri.



29
30
31
# File 'lib/facebook-graph/base/authentication.rb', line 29

def redirect_uri
  @redirect_uri
end

Instance Method Details

#access_token(code) ⇒ Object



21
22
23
24
25
26
# File 'lib/facebook-graph/base/authentication.rb', line 21

def access_token code
  config = FacebookGraph.configuration
  parse_form_data("#{config[:base_uri] + config[:access_token_uri]}?client_id=#{@client_id}" + 
                  "&client_secret=#{@client_secret}&code=#{CGI.escape(code)}" + 
                  "&redirect_uri=#{CGI.escape(@redirect_uri)}")['access_token'][0]
end

#client_id_and_secretObject



9
10
11
# File 'lib/facebook-graph/base/authentication.rb', line 9

def client_id_and_secret
  [client_id, client_secret]
end

#user_authorization_uri(options = {}) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/facebook-graph/base/authentication.rb', line 13

def user_authorization_uri(options={})
  config = FacebookGraph.configuration 
  uri = "#{config[:base_uri] + config[:authorize_uri]}?client_id=#{@client_id}"
  uri += "&redirect_uri=#{CGI.escape(@redirect_uri)}" if @redirect_uri
  uri += "&#{hash_to_querystring(options)}" unless options.nil? || options.empty?
  uri         
end