class Tosuto::OauthToken

Constants

ENDPOINT

Attributes

access_token[RW]
expires_at[RW]
expires_in[RW]
scope[RW]
token_type[RW]

Public Class Methods

create(client_id, client_secret, user_access_type: "TOAST_MACHINE_CLIENT", api: API.new) click to toggle source
# 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
new(attributes = {}) click to toggle source
# 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

Public Instance Methods

expired?() click to toggle source
# File lib/tosuto/oauth_token.rb, line 29
def expired?
  expires_at < Time.now
end
inspect() click to toggle source
# File lib/tosuto/oauth_token.rb, line 33
def inspect
  "#<#{self.class} #{access_token&.inspect}>"
end