Class: Lightspeed::API::Tokens

Inherits:
Object
  • Object
show all
Defined in:
lib/lightspeed/api/tokens.rb

Constant Summary collapse

REFRESH_TOKEN_URL =
"https://cloud.merchantos.com/oauth/access_token.php"

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Tokens

Returns a new instance of Tokens.



8
9
10
# File 'lib/lightspeed/api/tokens.rb', line 8

def initialize(client)
  @client = client
end

Instance Method Details

#refreshObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lightspeed/api/tokens.rb', line 12

def refresh
  raise Lightspeed::Errors::MissingRefreshToken unless client.refresh_token

  response = Faraday.post(
    REFRESH_TOKEN_URL,
    refresh_token: client.refresh_token,
    client_id: client.client_id,
    client_secret: client.client_secret,
    grant_type: "refresh_token",
  )

  JSON.parse(response.body)
end