Class: Tosuto::OauthToken
- Defined in:
- lib/tosuto/oauth_token.rb
Constant Summary collapse
- ENDPOINT =
"/authentication/v1/authentication/login".freeze
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#token_type ⇒ Object
Returns the value of attribute token_type.
Class Method Summary collapse
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ OauthToken
constructor
A new instance of OauthToken.
- #inspect ⇒ Object
Methods inherited from Resource
attr_collections, attr_objects, encode_form_data, #parse_collection, #parse_object, #set_attribute, #set_attributes, #underscore
Constructor Details
#initialize(attributes = {}) ⇒ OauthToken
Returns a new instance of OauthToken.
19 20 21 22 23 24 25 26 27 |
# File 'lib/tosuto/oauth_token.rb', line 19 def initialize(attributes = {}) return unless (token = attributes['token']) self.access_token = token['accessToken'] self.expires_in = token['expiresIn'].to_i self.expires_at = Time.now + expires_in self.token_type = token['tokenType'] self.scope = token['scope'] end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/tosuto/oauth_token.rb', line 5 def access_token @access_token end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
5 6 7 |
# File 'lib/tosuto/oauth_token.rb', line 5 def expires_at @expires_at end |
#expires_in ⇒ Object
Returns the value of attribute expires_in.
5 6 7 |
# File 'lib/tosuto/oauth_token.rb', line 5 def expires_in @expires_in end |
#scope ⇒ Object
Returns the value of attribute scope.
5 6 7 |
# File 'lib/tosuto/oauth_token.rb', line 5 def scope @scope end |
#token_type ⇒ Object
Returns the value of attribute token_type.
5 6 7 |
# File 'lib/tosuto/oauth_token.rb', line 5 def token_type @token_type end |
Class Method Details
.create(client_id, client_secret, user_access_type: "TOAST_MACHINE_CLIENT", api: API.new) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/tosuto/oauth_token.rb', line 7 def self.create(client_id, client_secret, user_access_type: "TOAST_MACHINE_CLIENT", api: API.new) body = { userAccessType: user_access_type, clientId: client_id, clientSecret: client_secret, } response = api.request(:post, ENDPOINT, body: body) raise response.error unless response.success? return new(response.json_body) end |
Instance Method Details
#expired? ⇒ Boolean
29 30 31 |
# File 'lib/tosuto/oauth_token.rb', line 29 def expired? expires_at < Time.now end |
#inspect ⇒ Object
33 34 35 |
# File 'lib/tosuto/oauth_token.rb', line 33 def inspect "#<#{self.class} #{access_token&.inspect}>" end |