Class: Peddler::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/peddler/token.rb

Overview

Requests refresh and access tokens that authorize your application to take actions on behalf of a selling partner.

The refresh token allows you to generate access tokens. Access tokens expire one hour after they are issued.

Defined Under Namespace

Classes: Error

Constant Summary collapse

URL =
"https://api.amazon.com/auth/o2/token"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id: ENV["LWA_CLIENT_ID"], client_secret: ENV["LWA_CLIENT_SECRET"], **options) ⇒ Token

Returns a new instance of Token.



31
32
33
34
35
# File 'lib/peddler/token.rb', line 31

def initialize(client_id: ENV["LWA_CLIENT_ID"], client_secret: ENV["LWA_CLIENT_SECRET"], **options)
  @client_id = client_id
  @client_secret = client_secret
  @options = options
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



23
24
25
# File 'lib/peddler/token.rb', line 23

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



23
24
25
# File 'lib/peddler/token.rb', line 23

def client_secret
  @client_secret
end

#optionsObject (readonly)

Returns the value of attribute options.



23
24
25
# File 'lib/peddler/token.rb', line 23

def options
  @options
end

Class Method Details

.requestObject



26
27
28
# File 'lib/peddler/token.rb', line 26

def request(...)
  new(...).request
end

Instance Method Details

#requestObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/peddler/token.rb', line 37

def request
  response = HTTP.post(URL, form: params)

  unless response.status.success?
    message = response.parse["error_description"]
    raise Error.new(message, response)
  end

  response
end