1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
module OAuth
# Superclass for tokens used by OAuth Clients
class ConsumerToken < Token
attr_accessor :consumer, :params
attr_reader :response
def self.from_hash(consumer, hash)
token = self.new(consumer, hash[:oauth_token], hash[:oauth_token_secret])
token.params = hash
token
end
def initialize(consumer, token="", secret="")
super(token, secret)
@consumer = consumer
@params = {}
end
# Make a signed request using given http_method to the path
#
# @token.request(:get, '/people')
# @token.request(:post, '/people', @person.to_xml, { 'Content-Type' => 'application/xml' })
#
def request(http_method, path, *arguments)
@response = consumer.request(http_method, path, self, {}, *arguments)
end
# Sign a request generated elsewhere using Net:HTTP::Post.new or friends
def sign!(request, options = {})
consumer.sign!(request, self, options)
end
end
end
|