Class: OAuth2::AccessToken
- Inherits:
-
Object
- Object
- OAuth2::AccessToken
- Defined in:
- lib/oauth2/access_token.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#token_param ⇒ Object
Returns the value of attribute token_param.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #delete(path, params = {}, headers = {}) ⇒ Object
- #expired? ⇒ Boolean
-
#expires? ⇒ Boolean
True if the token in question has an expiration time.
- #get(path, params = {}, headers = {}) ⇒ Object
-
#initialize(client, token, refresh_token = nil, expires_in = nil, params = {}) ⇒ AccessToken
constructor
A new instance of AccessToken.
- #post(path, params = {}, headers = {}) ⇒ Object
- #put(path, params = {}, headers = {}) ⇒ Object
- #request(verb, path, params = {}, headers = {}) ⇒ Object
Constructor Details
#initialize(client, token, refresh_token = nil, expires_in = nil, params = {}) ⇒ AccessToken
Returns a new instance of AccessToken.
6 7 8 9 10 11 12 13 14 |
# File 'lib/oauth2/access_token.rb', line 6 def initialize(client, token, refresh_token=nil, expires_in=nil, params={}) @client = client @token = token.to_s @refresh_token = refresh_token.to_s @expires_in = (expires_in.nil? || expires_in == '') ? nil : expires_in.to_i @expires_at = Time.now + @expires_in if @expires_in @params = params @token_param = 'oauth_token' end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/oauth2/access_token.rb', line 3 def client @client end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
3 4 5 |
# File 'lib/oauth2/access_token.rb', line 3 def expires_at @expires_at end |
#expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
3 4 5 |
# File 'lib/oauth2/access_token.rb', line 3 def expires_in @expires_in end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/oauth2/access_token.rb', line 3 def params @params end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
3 4 5 |
# File 'lib/oauth2/access_token.rb', line 3 def refresh_token @refresh_token end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
3 4 5 |
# File 'lib/oauth2/access_token.rb', line 3 def token @token end |
#token_param ⇒ Object
Returns the value of attribute token_param.
4 5 6 |
# File 'lib/oauth2/access_token.rb', line 4 def token_param @token_param end |
Instance Method Details
#[](key) ⇒ Object
16 17 18 |
# File 'lib/oauth2/access_token.rb', line 16 def [](key) @params[key] end |
#delete(path, params = {}, headers = {}) ⇒ Object
49 50 51 |
# File 'lib/oauth2/access_token.rb', line 49 def delete(path, params={}, headers={}) request(:delete, path, params, headers) end |
#expired? ⇒ Boolean
25 26 27 |
# File 'lib/oauth2/access_token.rb', line 25 def expired? expires? && expires_at < Time.now end |
#expires? ⇒ Boolean
True if the token in question has an expiration time.
21 22 23 |
# File 'lib/oauth2/access_token.rb', line 21 def expires? !!@expires_in end |
#get(path, params = {}, headers = {}) ⇒ Object
37 38 39 |
# File 'lib/oauth2/access_token.rb', line 37 def get(path, params={}, headers={}) request(:get, path, params, headers) end |
#post(path, params = {}, headers = {}) ⇒ Object
41 42 43 |
# File 'lib/oauth2/access_token.rb', line 41 def post(path, params={}, headers={}) request(:post, path, params, headers) end |
#put(path, params = {}, headers = {}) ⇒ Object
45 46 47 |
# File 'lib/oauth2/access_token.rb', line 45 def put(path, params={}, headers={}) request(:put, path, params, headers) end |
#request(verb, path, params = {}, headers = {}) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/oauth2/access_token.rb', line 29 def request(verb, path, params={}, headers={}) if params.instance_of?(Hash) params = params.merge token_param => @token end headers = headers.merge 'Authorization' => "OAuth #{@token}" @client.request(verb, path, params, headers) end |