Class: OAuth::ConsumerToken

Inherits:
Token show all
Defined in:
lib/oauth/tokens/consumer_token.rb

Overview

Superclass for tokens used by OAuth Clients

Direct Known Subclasses

AccessToken, RequestToken

Instance Attribute Summary collapse

Attributes inherited from Token

#secret, #token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Token

#to_query

Methods included from Helper

#_escape, #escape, #generate_key, #generate_timestamp, #normalize, #normalize_nested_query, #parse_header, #stringify_keys, #unescape

Constructor Details

#initialize(consumer, token = "", secret = "") ⇒ ConsumerToken

Returns a new instance of ConsumerToken



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

def initialize(consumer, token="", secret="")
  super(token, secret)
  @consumer = consumer
  @params   = {}
end

Instance Attribute Details

#consumerObject

Returns the value of attribute consumer



4
5
6
# File 'lib/oauth/tokens/consumer_token.rb', line 4

def consumer
  @consumer
end

#paramsObject

Returns the value of attribute params



4
5
6
# File 'lib/oauth/tokens/consumer_token.rb', line 4

def params
  @params
end

#responseObject (readonly)

Returns the value of attribute response



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

def response
  @response
end

Class Method Details

.from_hash(consumer, hash) ⇒ Object



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

def self.from_hash(consumer, hash)
  token = self.new(consumer, hash[:oauth_token], hash[:oauth_token_secret])
  token.params = hash
  token
end

Instance Method Details

#request(http_method, path, *arguments) ⇒ Object

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' })


24
25
26
# File 'lib/oauth/tokens/consumer_token.rb', line 24

def request(http_method, path, *arguments)
  @response = consumer.request(http_method, path, self, {}, *arguments)
end

#sign!(request, options = {}) ⇒ Object

Sign a request generated elsewhere using Net:HTTP::Post.new or friends



29
30
31
# File 'lib/oauth/tokens/consumer_token.rb', line 29

def sign!(request, options = {})
  consumer.sign!(request, self, options)
end