Class: TwoPerformant::OAuth
- Inherits:
-
Object
- Object
- TwoPerformant::OAuth
- Defined in:
- lib/two_performant/oauth.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#consumer ⇒ Object
Returns the value of attribute consumer.
Instance Method Summary collapse
- #delete(path, params) ⇒ Object
- #get(path, params_hash) ⇒ Object
-
#initialize(options, host) ⇒ OAuth
constructor
A new instance of OAuth.
- #post(path, params_hash) ⇒ Object
- #put(path, params_hash) ⇒ Object
Constructor Details
#initialize(options, host) ⇒ OAuth
Returns a new instance of OAuth.
22 23 24 25 26 |
# File 'lib/two_performant/oauth.rb', line 22 def initialize(, host) consumer = ::OAuth::Consumer.new([:consumer_token], [:consumer_secret], {:site => host}) @access_token = ::OAuth::AccessToken.new(consumer, [:access_token], [:access_secret]) @headers = { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
20 21 22 |
# File 'lib/two_performant/oauth.rb', line 20 def access_token @access_token end |
#consumer ⇒ Object
Returns the value of attribute consumer.
20 21 22 |
# File 'lib/two_performant/oauth.rb', line 20 def consumer @consumer end |
Instance Method Details
#delete(path, params) ⇒ Object
44 45 46 47 |
# File 'lib/two_performant/oauth.rb', line 44 def delete(path, params) response = access_token.delete("#{path}?#{params.to_params}") (response.body && response.body.size > 0) ? JSON.parse(response.body) : nil end |
#get(path, params_hash) ⇒ Object
28 29 30 31 32 |
# File 'lib/two_performant/oauth.rb', line 28 def get(path, params_hash) params_hash ||= {} response = access_token.get("#{path}?#{params_hash.to_params}") (response.body && response.body.size > 0) ? JSON.parse(response.body) : nil end |
#post(path, params_hash) ⇒ Object
34 35 36 37 |
# File 'lib/two_performant/oauth.rb', line 34 def post(path, params_hash) response = access_token.post(path, params_hash, @headers) (response.body && response.body.size > 0) ? JSON.parse(response.body) : nil end |
#put(path, params_hash) ⇒ Object
39 40 41 42 |
# File 'lib/two_performant/oauth.rb', line 39 def put(path, params_hash) response = access_token.put(path, params_hash, @headers) (response.body && response.body.size > 0) ? JSON.parse(response.body) : nil end |