Class: TwoPerformant::OAuth

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options, host)
  consumer = ::OAuth::Consumer.new(options[:consumer_token], options[:consumer_secret], {:site => host})
  @access_token = ::OAuth::AccessToken.new(consumer, options[:access_token], options[:access_secret])
  @headers = { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



20
21
22
# File 'lib/two_performant/oauth.rb', line 20

def access_token
  @access_token
end

#consumerObject

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