Class: FourRuby::OAuth2
- Inherits:
-
Object
- Object
- FourRuby::OAuth2
- Defined in:
- lib/four_ruby/oauth2.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#id ⇒ Object
Returns the value of attribute id.
-
#secret ⇒ Object
Returns the value of attribute secret.
Instance Method Summary collapse
- #access_token(code, options = {}) ⇒ Object
- #authorize_url(redirect_uri) ⇒ Object
- #get(url) ⇒ Object
-
#initialize(id, secret = nil, options = {}) ⇒ OAuth2
constructor
A new instance of OAuth2.
- #post(url, body) ⇒ Object
Constructor Details
#initialize(id, secret = nil, options = {}) ⇒ OAuth2
Returns a new instance of OAuth2.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/four_ruby/oauth2.rb', line 12 def initialize(id, secret=nil, ={}) if secret @id = id @secret = secret else require 'yaml' yml = YAML::load(File.open(id)) raise StandardError, "Foursquare config file does not exist" if yml['foursquare'].nil? @id = yml['foursquare']['client_id'] @secret = yml['foursquare']['client_secret'] end end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
10 11 12 |
# File 'lib/four_ruby/oauth2.rb', line 10 def client @client end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/four_ruby/oauth2.rb', line 10 def id @id end |
#secret ⇒ Object
Returns the value of attribute secret.
10 11 12 |
# File 'lib/four_ruby/oauth2.rb', line 10 def secret @secret end |
Instance Method Details
#access_token(code, options = {}) ⇒ Object
30 31 32 |
# File 'lib/four_ruby/oauth2.rb', line 30 def access_token(code, ={}) @access_token ||= client.get_access_token(code, ) end |
#authorize_url(redirect_uri) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/four_ruby/oauth2.rb', line 34 def (redirect_uri) client.web_server.( :redirect_uri => redirect_uri, :scope => 'email,offline_access' ) end |
#get(url) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/four_ruby/oauth2.rb', line 41 def get(url) if @access_token @access_token.get(url) else HTTParty.get(url) end end |
#post(url, body) ⇒ Object
49 50 51 |
# File 'lib/four_ruby/oauth2.rb', line 49 def post(url, body) HTTParty.post(url, body) end |