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.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #delete(path, params = {}, headers = {}) ⇒ Object
-
#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) ⇒ 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) ⇒ AccessToken
Returns a new instance of AccessToken.
5 6 7 8 9 10 11 |
# File 'lib/oauth2/access_token.rb', line 5 def initialize(client, token, refresh_token = nil, expires_in = nil) @client = client @token = token @refresh_token = refresh_token @expires_in = (expires_in.nil? || expires_in == '') ? nil : expires_in.to_i @expires_at = Time.now + @expires_in if @expires_in 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 |
#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 |
Instance Method Details
#delete(path, params = {}, headers = {}) ⇒ Object
34 35 36 |
# File 'lib/oauth2/access_token.rb', line 34 def delete(path, params = {}, headers = {}) request(:delete, path, params, headers) end |
#expires? ⇒ Boolean
True if the token in question has an expiration time.
14 15 16 |
# File 'lib/oauth2/access_token.rb', line 14 def expires? !!@expires_in end |
#get(path, params = {}, headers = {}) ⇒ Object
22 23 24 |
# File 'lib/oauth2/access_token.rb', line 22 def get(path, params = {}, headers = {}) request(:get, path, params, headers) end |
#post(path, params = {}, headers = {}) ⇒ Object
26 27 28 |
# File 'lib/oauth2/access_token.rb', line 26 def post(path, params = {}, headers = {}) request(:post, path, params, headers) end |
#put(path, params = {}, headers = {}) ⇒ Object
30 31 32 |
# File 'lib/oauth2/access_token.rb', line 30 def put(path, params = {}, headers = {}) request(:put, path, params, headers) end |
#request(verb, path, params = {}, headers = {}) ⇒ Object
18 19 20 |
# File 'lib/oauth2/access_token.rb', line 18 def request(verb, path, params = {}, headers = {}) @client.request(verb, path, params.merge('access_token' => @token), headers.merge('Authorization' => "Token token=\"#{@token}\"")) end |