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.



7
8
9
10
11
# File 'lib/two_performant/oauth.rb', line 7

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/xml', 'Content-Type' => 'application/xml' }
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



5
6
7
# File 'lib/two_performant/oauth.rb', line 5

def access_token
  @access_token
end

#consumerObject

Returns the value of attribute consumer.



5
6
7
# File 'lib/two_performant/oauth.rb', line 5

def consumer
  @consumer
end

Instance Method Details

#delete(path, params) ⇒ Object



29
30
31
32
# File 'lib/two_performant/oauth.rb', line 29

def delete(path, params) 
  response = access_token.delete("#{path}?#{params.to_params}")
  Crack::XML.parse(response.body)
end

#get(path, params_hash, params_xml) ⇒ Object



13
14
15
16
17
# File 'lib/two_performant/oauth.rb', line 13

def get(path, params_hash, params_xml) 
  params_hash ||= {}
  response = access_token.get("#{path}?#{params_hash.to_params}")
  Crack::XML.parse(response.body)
end

#post(path, params_hash, params_xml) ⇒ Object



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

def post(path, params_hash, params_xml) 
  response = access_token.post(path, params_xml, @headers)
  Crack::XML.parse(response.body)
end

#put(path, params_hash, params_xml) ⇒ Object



24
25
26
27
# File 'lib/two_performant/oauth.rb', line 24

def put(path, params_hash, params_xml) 
  response = access_token.put(path, params_xml, @headers)
  Crack::XML.parse(response.body)
end