peddler 5.0.0.pre.1 → 5.0.0.pre.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d0c406e3251609fdef8fe5669557eea8bb2ceb6673daa4eba35e6b7aae0c705
4
- data.tar.gz: 51bbdc9b06c899c9484aae73ccff292d78a08ef7c280e9c82c41ca2bb753dcad
3
+ metadata.gz: 20b378be071f3a0cade83e11f4c9970aa5d00ad4077097fd4ac22d709b20bf3d
4
+ data.tar.gz: 86420f4e6823a302e9785c2f795714f3769dce647e7880dcdee0bf5cdfd6b94b
5
5
  SHA512:
6
- metadata.gz: deb8c6851661129e96b2447e6ede291cac59454e56c50eff3a071c9b81afaae6f7ad9d5d843d8fdebaa59889007b77209bbd061899335eb319a7ac9e8c8f2d53
7
- data.tar.gz: 551d460e69641c2607d524e47fab94eda8435f7a065438e7a364b898dd51e424e515c0eac226438ae8b88811f00036902ba2687b67c84a8d1d3e2b7bea2b2e55
6
+ metadata.gz: 6cd309742cd1cc9594c570171553137ab43966cb3060f1af36a6da17a8c15f56cb4f93cd60f06bb06425a05e2d97108209f4e164890c5d574fabe0ac237e62c5
7
+ data.tar.gz: c5762d1e6b36d83dd7cbc0348d3ae6500bc983015e5efdd6c772d56d853aa8155f92a485e8292f2d4acc2501c333437685dd41fde8871d13f247b6db812ae518
data/README.md CHANGED
@@ -55,35 +55,35 @@ require "peddler/apis/orders_v0"
55
55
  A seller or vendor [provides you a refresh token][authorization] to access their data on Amazon.
56
56
 
57
57
  ```ruby
58
- refresh_token = Peddled::Token.request(
58
+ refresh_token = Peddler::LWA.request(
59
59
  code: "<AUTHORIZATION_CODE>"
60
- ).parse["refresh_token"]
60
+ ).parse.refresh_token
61
61
  ```
62
62
 
63
63
  You use this to generate a temporary access token to authenticate individual API requests.
64
64
 
65
65
  ```ruby
66
- access_token = Peddler::Token.request(
66
+ access_token = Peddler::LWA.request(
67
67
  refresh_token: "<REFRESH_TOKEN>",
68
- ).parse["access_token"]
68
+ ).parse.access_token
69
69
  ```
70
70
 
71
71
  Similarly, you can request a token for grantless operations.
72
72
 
73
73
  ```ruby
74
- access_token = Peddler::Token.request(
74
+ access_token = Peddler::LWA.request(
75
75
  scope: "sellingpartnerapi::notifications",
76
- ).parse["access_token"]
76
+ ).parse.access_token
77
77
  ```
78
78
 
79
79
  If you haven't set your LWA credentials as environment variables, pass them directly when requesting the token.
80
80
 
81
81
  ```ruby
82
- access_token = Peddler::Token.request(
82
+ access_token = Peddler::LWA.request(
83
83
  client_id: "<YOUR_CLIENT_ID>",
84
84
  client_secret: "<YOUR_CLIENT_SECRET>",
85
85
  refresh_token: "<REFRESH_TOKEN>",
86
- ).parse["access_token"]
86
+ ).parse.access_token
87
87
  ```
88
88
 
89
89
  Access tokens are valid for one hour. To optimize performance, cache the token and reuse across calls.
@@ -96,9 +96,9 @@ class Seller
96
96
 
97
97
  def access_token
98
98
  Rails.cache.fetch("#{cache_key}/access_key", expires_in: 1.hour) do
99
- Peddler::Token.request(
99
+ Peddler::LWA.request(
100
100
  refresh_token:,
101
- ).parse["access_token"]
101
+ ).parse.access_token
102
102
  end
103
103
  end
104
104
  end
@@ -4,14 +4,18 @@ require "http"
4
4
 
5
5
  require "peddler/error"
6
6
  require "peddler/response"
7
+ require "peddler/types/lwa_token"
7
8
 
8
9
  module Peddler
9
- # Requests refresh and access tokens that authorize your application to take actions on behalf of a selling partner.
10
+ # Requests Login with Amazon (LWA) access tokens that authorize your application to make SP-API requests.
10
11
  #
11
- # The refresh token allows you to generate access tokens. Access tokens expire one hour after they are issued.
12
+ # Supports three OAuth 2.0 grant types:
13
+ # - authorization_code: Exchange authorization code for refresh token (initial authorization)
14
+ # - refresh_token: Exchange refresh token for access token (most common)
15
+ # - client_credentials: Get access token for grantless operations (e.g., notifications)
12
16
  #
13
17
  # @see https://developer-docs.amazon.com/sp-api/docs/connecting-to-the-selling-partner-api
14
- class Token
18
+ class LWA
15
19
  URL = "https://api.amazon.com/auth/o2/token"
16
20
 
17
21
  attr_reader :client_id, :client_secret, :options
@@ -30,7 +34,7 @@ module Peddler
30
34
 
31
35
  def request
32
36
  http_response = HTTP.post(URL, form: params)
33
- Response.wrap(http_response)
37
+ Response.wrap(http_response, parser: -> { Types::LWAToken })
34
38
  end
35
39
 
36
40
  def grant_type
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "structure"
4
+
5
+ module Peddler
6
+ module Types
7
+ # Login with Amazon (LWA) OAuth 2.0 token response
8
+ #
9
+ # This type represents the response from Amazon's token endpoint for all grant types:
10
+ # - authorization_code: Returns access_token, refresh_token, token_type, expires_in
11
+ # - refresh_token: Returns access_token, token_type, expires_in (refresh_token rarely included)
12
+ # - client_credentials: Returns access_token, token_type, expires_in, scope
13
+ #
14
+ # @see https://developer-docs.amazon.com/sp-api/docs/connecting-to-the-selling-partner-api
15
+ # @see https://developer.amazon.com/docs/login-with-amazon/documentation-overview.html
16
+ LWAToken = Structure.new do
17
+ # @return [String] The access token used to authenticate SP-API requests
18
+ attribute(:access_token, String)
19
+
20
+ # @return [String] The token type (always "bearer")
21
+ attribute(:token_type, String)
22
+
23
+ # @return [Integer] Number of seconds until the access token expires (typically 3600)
24
+ attribute?(:expires_in, Integer)
25
+
26
+ # @return [String, nil] The refresh token (present for authorization_code grant, rarely for refresh_token grant)
27
+ attribute?(:refresh_token, String)
28
+
29
+ # @return [String, nil] The scope granted (only present for client_credentials grant)
30
+ attribute?(:scope, String)
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Peddler
4
- VERSION = "5.0.0.pre.1"
4
+ VERSION = "5.0.0.pre.2"
5
5
  end
data/lib/peddler.rb CHANGED
@@ -63,7 +63,7 @@ require "peddler/apis/vendor_invoices_v1"
63
63
  require "peddler/apis/vendor_orders_v1"
64
64
  require "peddler/apis/vendor_shipments_v1"
65
65
  require "peddler/apis/vendor_transaction_status_v1"
66
- require "peddler/token"
66
+ require "peddler/lwa"
67
67
 
68
68
  module Peddler
69
69
  class << self
@@ -1,9 +1,8 @@
1
1
  module Peddler
2
- class Token
2
+ # Requests Login with Amazon (LWA) access tokens for SP-API authorization
3
+ class LWA
3
4
  URL: String
4
5
 
5
- class Error < Peddler::Error
6
- end
7
6
  @client_id: String?
8
7
  @client_secret: String?
9
8
  @options: Hash[Symbol, untyped]
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peddler
4
+ module Types
5
+ # Login with Amazon (LWA) OAuth 2.0 token response
6
+ #
7
+ # This type represents the response from Amazon's token endpoint for all grant types:
8
+ # - authorization_code: Returns access_token, refresh_token, token_type, expires_in
9
+ # - refresh_token: Returns access_token, token_type, expires_in (refresh_token rarely included)
10
+ # - client_credentials: Returns access_token, token_type, expires_in, scope
11
+ class LWAToken < Data
12
+ # The access token used to authenticate SP-API requests
13
+ def access_token: () -> String
14
+
15
+ # The token type (always "bearer")
16
+ def token_type: () -> String
17
+
18
+ # Number of seconds until the access token expires (typically 3600)
19
+ def expires_in: () -> Integer?
20
+
21
+ # The refresh token (present for authorization_code grant, rarely for refresh_token grant)
22
+ def refresh_token: () -> String?
23
+
24
+ # The scope granted (only present for client_credentials grant)
25
+ def scope: () -> String?
26
+
27
+ def self.parse: (untyped value) -> LWAToken
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peddler
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.pre.1
4
+ version: 5.0.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hakan Ensari
@@ -126,9 +126,9 @@ files:
126
126
  - lib/peddler/error.rb
127
127
  - lib/peddler/helpers/feeds_2021_06_30.rb
128
128
  - lib/peddler/helpers/reports_2021_06_30.rb
129
+ - lib/peddler/lwa.rb
129
130
  - lib/peddler/marketplace.rb
130
131
  - lib/peddler/response.rb
131
- - lib/peddler/token.rb
132
132
  - lib/peddler/types/amazon_warehousing_and_distribution_2024_05_09.rb
133
133
  - lib/peddler/types/amazon_warehousing_and_distribution_2024_05_09/address.rb
134
134
  - lib/peddler/types/amazon_warehousing_and_distribution_2024_05_09/carrier_code.rb
@@ -960,6 +960,7 @@ files:
960
960
  - lib/peddler/types/listings_restrictions_2021_08_01/reason.rb
961
961
  - lib/peddler/types/listings_restrictions_2021_08_01/restriction.rb
962
962
  - lib/peddler/types/listings_restrictions_2021_08_01/restriction_list.rb
963
+ - lib/peddler/types/lwa_token.rb
963
964
  - lib/peddler/types/merchant_fulfillment_v0.rb
964
965
  - lib/peddler/types/merchant_fulfillment_v0/additional_inputs.rb
965
966
  - lib/peddler/types/merchant_fulfillment_v0/additional_inputs_list.rb
@@ -2074,9 +2075,9 @@ files:
2074
2075
  - sig/peddler/error.rbs
2075
2076
  - sig/peddler/helpers/feeds_2021_06_30.rbs
2076
2077
  - sig/peddler/helpers/reports_2021_06_30.rbs
2078
+ - sig/peddler/lwa.rbs
2077
2079
  - sig/peddler/marketplace.rbs
2078
2080
  - sig/peddler/response.rbs
2079
- - sig/peddler/token.rbs
2080
2081
  - sig/peddler/types/amazon_warehousing_and_distribution_2024_05_09.rbs
2081
2082
  - sig/peddler/types/aplus_content_2020_11_01.rbs
2082
2083
  - sig/peddler/types/application_integrations_2024_04_01.rbs
@@ -2102,6 +2103,7 @@ files:
2102
2103
  - sig/peddler/types/listings_items_2020_09_01.rbs
2103
2104
  - sig/peddler/types/listings_items_2021_08_01.rbs
2104
2105
  - sig/peddler/types/listings_restrictions_2021_08_01.rbs
2106
+ - sig/peddler/types/lwa_token.rbs
2105
2107
  - sig/peddler/types/merchant_fulfillment_v0.rbs
2106
2108
  - sig/peddler/types/messaging_v1.rbs
2107
2109
  - sig/peddler/types/money.rbs