Class: RFGraph::Auth
- Inherits:
-
Object
- Object
- RFGraph::Auth
- Defined in:
- lib/rfgraph/auth.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#app_secret ⇒ Object
Returns the value of attribute app_secret.
-
#expires ⇒ Object
Returns the value of attribute expires.
Instance Method Summary collapse
-
#authorize(callback_url, code) ⇒ Object
Take the oauth2 request token and turn it into an access token which can be used to access private data.
-
#authorize_url(callback_url, options = {}) ⇒ Object
Options: * :display - page (default), popup, wap, touch.
-
#initialize(app_id, app_secret) ⇒ Auth
constructor
A new instance of Auth.
Constructor Details
#initialize(app_id, app_secret) ⇒ Auth
Returns a new instance of Auth.
11 12 13 14 |
# File 'lib/rfgraph/auth.rb', line 11 def initialize(app_id, app_secret) @app_id = app_id @app_secret = app_secret end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
8 9 10 |
# File 'lib/rfgraph/auth.rb', line 8 def access_token @access_token end |
#app_id ⇒ Object
Returns the value of attribute app_id.
6 7 8 |
# File 'lib/rfgraph/auth.rb', line 6 def app_id @app_id end |
#app_secret ⇒ Object
Returns the value of attribute app_secret.
7 8 9 |
# File 'lib/rfgraph/auth.rb', line 7 def app_secret @app_secret end |
#expires ⇒ Object
Returns the value of attribute expires.
9 10 11 |
# File 'lib/rfgraph/auth.rb', line 9 def expires @expires end |
Instance Method Details
#authorize(callback_url, code) ⇒ Object
Take the oauth2 request token and turn it into an access token which can be used to access private data
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rfgraph/auth.rb', line 33 def (callback_url, code) data = open("#{BASE_URL}/oauth/access_token?client_id=#{app_id}&redirect_uri=#{CGI.escape callback_url}&client_secret=#{app_secret}&code=#{CGI.escape code}").read # The expiration date is not necessarily set, as the app might have # requested offline_access to the data match_data = data.match(/expires=([^&]+)/) @expires = match_data && match_data[1] || nil # Extract the access token @access_token = data.match(/access_token=([^&]+)/)[1] end |
#authorize_url(callback_url, options = {}) ⇒ Object
Options:
-
:display - page (default), popup, wap, touch. See: developers.facebook.com/docs/authentication/.
-
:scope - either a String “user_photos,user_videos,stream_publish” or an
Array like [:user_photos, :user_videos, :stream_publish] For more permission scopes, see developers.facebook.com/docs/authentication/permissions
All other options in the options Hash will be put in the authorize_url.
23 24 25 26 27 28 29 |
# File 'lib/rfgraph/auth.rb', line 23 def (callback_url, = {}) url = "#{BASE_URL}/oauth/authorize?client_id=#{app_id}&redirect_uri=#{callback_url}" scope = .delete(:scope) url += "&scope=#{scope.join(',')}" unless scope.blank? url += "&#{.to_query}" unless .blank? # Add other options. FIXME: to_query method requires Rails?! return url end |