Class: OAuthSimple::Token
- Inherits:
-
Object
- Object
- OAuthSimple::Token
- Defined in:
- lib/oauth-simple/token.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Class Method Summary collapse
Instance Method Summary collapse
- #authorize_url ⇒ Object
-
#consumer=(c) ⇒ Object
In order to have a token generate a URL, it needs to know of its consumer.
- #get_access_token ⇒ Object
-
#initialize(key, secret) ⇒ Token
constructor
A new instance of Token.
- #to_s ⇒ Object
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
#key ⇒ Object (readonly)
Returns the value of attribute key.
24 25 26 |
# File 'lib/oauth-simple/token.rb', line 24 def key @key end |
#secret ⇒ Object (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_url ⇒ Object
45 46 47 48 |
# File 'lib/oauth-simple/token.rb', line 45 def req = Request.from_consumer_and_token(@consumer, self, @consumer., {}) 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_token ⇒ Object
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_s ⇒ Object
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 |