Class: Facebookdp::OAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/facebookdp/oauth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apikey, apisecret, graph_api_url = "https://graph.facebook.com", callback_url = "http://localhost:3000/facebook/callback") ⇒ OAuth

Returns a new instance of OAuth.



5
6
7
8
9
10
# File 'lib/facebookdp/oauth.rb', line 5

def initialize(apikey, apisecret, graph_api_url = "https://graph.facebook.com", callback_url = "http://localhost:3000/facebook/callback")
  @apikey = apikey
  @apisecret = apisecret
  @graph_api_url = graph_api_url
  @callback_url = callback_url
end

Instance Attribute Details

#apikeyObject

Returns the value of attribute apikey.



3
4
5
# File 'lib/facebookdp/oauth.rb', line 3

def apikey
  @apikey
end

#apisecretObject

Returns the value of attribute apisecret.



3
4
5
# File 'lib/facebookdp/oauth.rb', line 3

def apisecret
  @apisecret
end

#callback_urlObject

Returns the value of attribute callback_url.



3
4
5
# File 'lib/facebookdp/oauth.rb', line 3

def callback_url
  @callback_url
end

#codeObject

Returns the value of attribute code.



3
4
5
# File 'lib/facebookdp/oauth.rb', line 3

def code
  @code
end

#graph_api_urlObject

Returns the value of attribute graph_api_url.



3
4
5
# File 'lib/facebookdp/oauth.rb', line 3

def graph_api_url
  @graph_api_url
end

Instance Method Details

#authorize_urlObject

Get the url needed to recieve auth token behind the scenes, oauth2 is passing id and secret



23
24
25
# File 'lib/facebookdp/oauth.rb', line 23

def authorize_url
  client.web_server.authorize_url( :redirect_uri => callback_url )
end

#clientObject

client is an instance of an oauth object, but needs to be authenticated by having a user visit facebook and retrieve a access code



16
17
18
# File 'lib/facebookdp/oauth.rb', line 16

def client
  @client ||= OAuth2::Client.new(@apikey, @apisecret, :site => @graph_api_url)
end

#get_access_token(code) ⇒ Object

Create access_token, and then we’re connected



29
30
31
32
# File 'lib/facebookdp/oauth.rb', line 29

def get_access_token(code)
  @code = code
  @access_token ||= client.web_server.get_access_token( @code, :redirect_uri => callback_url)
end