Class: OAuth::ConsumerToken

Inherits:
Token
  • Object
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.



15
16
17
18
19
# File 'lib/oauth/tokens/consumer_token.rb', line 15

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

Instance Attribute Details

#consumerObject

Returns the value of attribute consumer.



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

def consumer
  @consumer
end

#paramsObject

Returns the value of attribute params.



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

def params
  @params
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Class Method Details

.from_hash(consumer, hash) ⇒ Object



9
10
11
12
13
# File 'lib/oauth/tokens/consumer_token.rb', line 9

def self.from_hash(consumer, hash)
  token = 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' })


26
27
28
# File 'lib/oauth/tokens/consumer_token.rb', line 26

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



31
32
33
# File 'lib/oauth/tokens/consumer_token.rb', line 31

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