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.
17 18 19 20 21 |
# File 'lib/two_performant/oauth.rb', line 17 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/x-www-form-urlencoded' } end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
15 16 17 |
# File 'lib/two_performant/oauth.rb', line 15 def access_token @access_token end |
#consumer ⇒ Object
Returns the value of attribute consumer.
15 16 17 |
# File 'lib/two_performant/oauth.rb', line 15 def consumer @consumer end |
Instance Method Details
#delete(path, params) ⇒ Object
39 40 41 42 |
# File 'lib/two_performant/oauth.rb', line 39 def delete(path, params) response = access_token.delete("#{path}?#{params.to_params}") JSON.parse(response.body) end |
#get(path, params_hash) ⇒ Object
23 24 25 26 27 |
# File 'lib/two_performant/oauth.rb', line 23 def get(path, params_hash) params_hash ||= {} response = access_token.get("#{path}?#{params_hash.to_params}") JSON.parse(response.body) end |
#post(path, params_hash) ⇒ Object
29 30 31 32 |
# File 'lib/two_performant/oauth.rb', line 29 def post(path, params_hash) response = access_token.post(path, params_hash.to_json, @headers) JSON.parse(response.body) end |
#put(path, params_hash) ⇒ Object
34 35 36 37 |
# File 'lib/two_performant/oauth.rb', line 34 def put(path, params_hash) response = access_token.put(path, params_hash.to_json, @headers) JSON.parse(response.body) end |