Class: Peddler::LWA
- Inherits:
-
Object
- Object
- Peddler::LWA
- Defined in:
- lib/peddler/lwa.rb
Overview
Requests Login with Amazon (LWA) access tokens that authorize your application to make SP-API requests.
Supports three OAuth 2.0 grant types:
- authorization_code: Exchange authorization code for refresh token (initial authorization)
- refresh_token: Exchange refresh token for access token (most common)
- client_credentials: Get access token for grantless operations (e.g., notifications)
Constant Summary collapse
- URL =
"https://api.amazon.com/auth/o2/token"
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #grant_type ⇒ Object
-
#initialize(client_id: ENV["LWA_CLIENT_ID"], client_secret: ENV["LWA_CLIENT_SECRET"], **options) ⇒ LWA
constructor
A new instance of LWA.
- #request ⇒ Object
Constructor Details
#initialize(client_id: ENV["LWA_CLIENT_ID"], client_secret: ENV["LWA_CLIENT_SECRET"], **options) ⇒ LWA
Returns a new instance of LWA.
25 26 27 28 29 |
# File 'lib/peddler/lwa.rb', line 25 def initialize(client_id: ENV["LWA_CLIENT_ID"], client_secret: ENV["LWA_CLIENT_SECRET"], **) @client_id = client_id @client_secret = client_secret @options = end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
17 18 19 |
# File 'lib/peddler/lwa.rb', line 17 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
17 18 19 |
# File 'lib/peddler/lwa.rb', line 17 def client_secret @client_secret end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/peddler/lwa.rb', line 17 def @options end |
Class Method Details
.request ⇒ Object
20 21 22 |
# File 'lib/peddler/lwa.rb', line 20 def request(...) new(...).request end |
Instance Method Details
#grant_type ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/peddler/lwa.rb', line 36 def grant_type if .key?(:grant_type) [:grant_type] elsif .key?(:refresh_token) "refresh_token" elsif .key?(:scope) "client_credentials" elsif .key?(:code) "authorization_code" end end |