Class: OAuthSimple::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth-simple/token.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, secret) ⇒ Token

Returns a new instance of Token.



25
26
27
28
# File 'lib/oauth-simple/token.rb', line 25

def initialize(key, secret)
  @key = key
  @secret = secret
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



24
25
26
# File 'lib/oauth-simple/token.rb', line 24

def key
  @key
end

#secretObject (readonly)

Returns the value of attribute secret.



24
25
26
# File 'lib/oauth-simple/token.rb', line 24

def secret
  @secret
end

Class Method Details

.from_string(str) ⇒ Object



34
35
36
37
# File 'lib/oauth-simple/token.rb', line 34

def self.from_string(str)
  params = CGI.parse(str)
  return new(params['oauth_token'].first, params['oauth_token_secret'].first)
end

Instance Method Details

#authorize_urlObject



45
46
47
48
# File 'lib/oauth-simple/token.rb', line 45

def authorize_url
  req = Request.from_consumer_and_token(@consumer, self, @consumer.authorize_url, {})
  return req.to_url
end

#consumer=(c) ⇒ Object

In order to have a token generate a URL, it needs to know of its consumer. Doesn’t look quite right to have it here, but the way the API works…



41
42
43
# File 'lib/oauth-simple/token.rb', line 41

def consumer=(c)
  @consumer = c
end

#get_access_tokenObject



50
51
52
53
54
55
56
# File 'lib/oauth-simple/token.rb', line 50

def get_access_token
  request = Request.from_consumer_and_token(@consumer, self, @consumer.access_token_url)
  request.consumer = @consumer
  request.sign_request(@consumer.signature_method, self)
  response = open(request.get_normalized_http_url, 'r', request.to_header).read
  return Token.from_string(response)
end

#to_sObject



30
31
32
# File 'lib/oauth-simple/token.rb', line 30

def to_s
  "oauth_token=#{CGI.escape(@key)}&oauth_token_secret=#{CGI.escape(@secret)}"
end