peddler 3.0.0.beta1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +96 -106
- data/lib/peddler/api/amazon_warehousing_and_distribution_2024_05_09.rb +34 -22
- data/lib/peddler/api/aplus_content_2020_11_01.rb +86 -48
- data/lib/peddler/api/application_integrations_2024_04_01.rb +56 -0
- data/lib/peddler/api/application_management_2023_11_30.rb +12 -2
- data/lib/peddler/api/catalog_items_2020_12_01.rb +31 -20
- data/lib/peddler/api/catalog_items_2022_04_01.rb +35 -25
- data/lib/peddler/api/catalog_items_v0.rb +39 -26
- data/lib/peddler/api/data_kiosk_2023_11_15.rb +41 -25
- data/lib/peddler/api/easy_ship_2022_03_23.rb +62 -43
- data/lib/peddler/api/fba_inbound_eligibility_v1.rb +13 -5
- data/lib/peddler/api/fba_inventory_v1.rb +40 -24
- data/lib/peddler/api/feeds_2021_06_30.rb +43 -25
- data/lib/peddler/api/finances_2024_06_19.rb +50 -0
- data/lib/peddler/api/finances_v0.rb +86 -59
- data/lib/peddler/api/fulfillment_inbound_2024_03_20.rb +304 -205
- data/lib/peddler/api/fulfillment_inbound_v0.rb +112 -74
- data/lib/peddler/api/fulfillment_outbound_2020_07_01.rb +90 -53
- data/lib/peddler/api/invoices_2024_06_19.rb +180 -0
- data/lib/peddler/api/listings_items_2020_09_01.rb +44 -33
- data/lib/peddler/api/listings_items_2021_08_01.rb +76 -60
- data/lib/peddler/api/listings_restrictions_2021_08_01.rb +19 -9
- data/lib/peddler/api/merchant_fulfillment_v0.rb +31 -15
- data/lib/peddler/api/messaging_v1.rb +93 -61
- data/lib/peddler/api/notifications_v1.rb +54 -23
- data/lib/peddler/api/orders_v0.rb +87 -72
- data/lib/peddler/api/product_fees_v0.rb +39 -31
- data/lib/peddler/api/product_pricing_2022_05_01.rb +17 -6
- data/lib/peddler/api/product_pricing_v0.rb +63 -45
- data/lib/peddler/api/product_type_definitions_2020_09_01.rb +29 -18
- data/lib/peddler/api/replenishment_2022_11_07.rb +21 -9
- data/lib/peddler/api/reports_2021_06_30.rb +60 -36
- data/lib/peddler/api/sales_v1.rb +20 -12
- data/lib/peddler/api/sellers_v1.rb +16 -4
- data/lib/peddler/api/services_v1.rb +138 -98
- data/lib/peddler/api/shipment_invoicing_v0.rb +25 -12
- data/lib/peddler/api/shipping_v1.rb +54 -29
- data/lib/peddler/api/shipping_v2.rb +132 -80
- data/lib/peddler/api/solicitations_v1.rb +18 -8
- data/lib/peddler/api/supply_sources_2020_07_01.rb +33 -15
- data/lib/peddler/api/tokens_2021_03_01.rb +13 -5
- data/lib/peddler/api/uploads_2020_11_01.rb +16 -6
- data/lib/peddler/api/vendor_direct_fulfillment_inventory_v1.rb +12 -4
- data/lib/peddler/api/vendor_direct_fulfillment_orders_2021_12_28.rb +29 -17
- data/lib/peddler/api/vendor_direct_fulfillment_orders_v1.rb +29 -17
- data/lib/peddler/api/vendor_direct_fulfillment_payments_v1.rb +11 -3
- data/lib/peddler/api/vendor_direct_fulfillment_sandbox_test_data_2021_10_28.rb +14 -4
- data/lib/peddler/api/vendor_direct_fulfillment_shipping_2021_12_28.rb +74 -48
- data/lib/peddler/api/vendor_direct_fulfillment_shipping_v1.rb +74 -50
- data/lib/peddler/api/vendor_direct_fulfillment_transactions_2021_12_28.rb +11 -3
- data/lib/peddler/api/vendor_direct_fulfillment_transactions_v1.rb +11 -3
- data/lib/peddler/api/vendor_invoices_v1.rb +11 -3
- data/lib/peddler/api/vendor_orders_v1.rb +54 -43
- data/lib/peddler/api/vendor_shipments_v1.rb +63 -51
- data/lib/peddler/api/vendor_transaction_status_v1.rb +12 -3
- data/lib/peddler/api.rb +41 -18
- data/lib/peddler/endpoint.rb +51 -0
- data/lib/peddler/error.rb +1 -0
- data/lib/peddler/marketplace.rb +49 -0
- data/lib/peddler/token.rb +70 -0
- data/lib/peddler/version.rb +1 -1
- data/lib/peddler.rb +56 -52
- metadata +10 -6
- data/lib/peddler/access_token.rb +0 -76
- data/lib/peddler/region.rb +0 -30
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "http"
|
4
|
+
|
5
|
+
module Peddler
|
6
|
+
# Requests refresh and access tokens that authorize your application to take actions on behalf of a selling partner.
|
7
|
+
#
|
8
|
+
# The refresh token allows you to generate access tokens. Access tokens expire one hour after they are issued.
|
9
|
+
#
|
10
|
+
# @see https://developer-docs.amazon.com/sp-api/docs/connecting-to-the-selling-partner-api
|
11
|
+
class Token
|
12
|
+
class Error < StandardError
|
13
|
+
attr_reader :cause
|
14
|
+
|
15
|
+
def initialize(msg = nil, cause = nil)
|
16
|
+
@cause = cause
|
17
|
+
super(msg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
URL = "https://api.amazon.com/auth/o2/token"
|
22
|
+
|
23
|
+
attr_reader :client_id, :client_secret, :options
|
24
|
+
|
25
|
+
class << self
|
26
|
+
def request(...)
|
27
|
+
new(...).request
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(client_id: ENV["LWA_CLIENT_ID"], client_secret: ENV["LWA_CLIENT_SECRET"], **options)
|
32
|
+
@client_id = client_id
|
33
|
+
@client_secret = client_secret
|
34
|
+
@options = options
|
35
|
+
end
|
36
|
+
|
37
|
+
def request
|
38
|
+
response = HTTP.post(URL, form: params)
|
39
|
+
|
40
|
+
unless response.status.success?
|
41
|
+
message = response.parse["error_description"]
|
42
|
+
raise Error.new(message, response)
|
43
|
+
end
|
44
|
+
|
45
|
+
response
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def params
|
51
|
+
{
|
52
|
+
grant_type: grant_type,
|
53
|
+
client_id: client_id,
|
54
|
+
client_secret: client_secret,
|
55
|
+
}.compact.merge(options)
|
56
|
+
end
|
57
|
+
|
58
|
+
def grant_type
|
59
|
+
return if options.key?(:grant_type)
|
60
|
+
|
61
|
+
if options.key?(:refresh_token)
|
62
|
+
"refresh_token"
|
63
|
+
elsif options.key?(:scope)
|
64
|
+
"client_credentials"
|
65
|
+
elsif options.key?(:code)
|
66
|
+
"authorization_code"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/peddler/version.rb
CHANGED
data/lib/peddler.rb
CHANGED
@@ -1,54 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "peddler/
|
4
|
-
require "peddler/api/
|
5
|
-
require "peddler/api/
|
6
|
-
require "peddler/api/application_management_2023_11_30
|
7
|
-
require "peddler/api/
|
8
|
-
require "peddler/api/
|
9
|
-
require "peddler/api/
|
10
|
-
require "peddler/api/data_kiosk_2023_11_15
|
11
|
-
require "peddler/api/easy_ship_2022_03_23
|
12
|
-
require "peddler/api/fba_inbound_eligibility_v1
|
13
|
-
require "peddler/api/fba_inventory_v1
|
14
|
-
require "peddler/api/feeds_2021_06_30
|
15
|
-
require "peddler/api/
|
16
|
-
require "peddler/api/
|
17
|
-
require "peddler/api/fulfillment_inbound_2024_03_20
|
18
|
-
require "peddler/api/
|
19
|
-
require "peddler/api/
|
20
|
-
require "peddler/api/
|
21
|
-
require "peddler/api/
|
22
|
-
require "peddler/api/
|
23
|
-
require "peddler/api/
|
24
|
-
require "peddler/api/
|
25
|
-
require "peddler/api/
|
26
|
-
require "peddler/api/
|
27
|
-
require "peddler/api/
|
28
|
-
require "peddler/api/
|
29
|
-
require "peddler/api/
|
30
|
-
require "peddler/api/
|
31
|
-
require "peddler/api/
|
32
|
-
require "peddler/api/
|
33
|
-
require "peddler/api/
|
34
|
-
require "peddler/api/
|
35
|
-
require "peddler/api/
|
36
|
-
require "peddler/api/
|
37
|
-
require "peddler/api/
|
38
|
-
require "peddler/api/
|
39
|
-
require "peddler/api/
|
40
|
-
require "peddler/api/
|
41
|
-
require "peddler/api/
|
42
|
-
require "peddler/api/
|
43
|
-
require "peddler/api/
|
44
|
-
require "peddler/api/
|
45
|
-
require "peddler/api/
|
46
|
-
require "peddler/api/
|
47
|
-
require "peddler/api/
|
48
|
-
require "peddler/api/
|
49
|
-
require "peddler/api/
|
50
|
-
require "peddler/api/
|
51
|
-
require "peddler/api/
|
52
|
-
require "peddler/api/
|
53
|
-
require "peddler/api/
|
54
|
-
require "peddler/api/
|
3
|
+
require "peddler/api/amazon_warehousing_and_distribution_2024_05_09"
|
4
|
+
require "peddler/api/aplus_content_2020_11_01"
|
5
|
+
require "peddler/api/application_integrations_2024_04_01"
|
6
|
+
require "peddler/api/application_management_2023_11_30"
|
7
|
+
require "peddler/api/catalog_items_2020_12_01"
|
8
|
+
require "peddler/api/catalog_items_2022_04_01"
|
9
|
+
require "peddler/api/catalog_items_v0"
|
10
|
+
require "peddler/api/data_kiosk_2023_11_15"
|
11
|
+
require "peddler/api/easy_ship_2022_03_23"
|
12
|
+
require "peddler/api/fba_inbound_eligibility_v1"
|
13
|
+
require "peddler/api/fba_inventory_v1"
|
14
|
+
require "peddler/api/feeds_2021_06_30"
|
15
|
+
require "peddler/api/finances_2024_06_19"
|
16
|
+
require "peddler/api/finances_v0"
|
17
|
+
require "peddler/api/fulfillment_inbound_2024_03_20"
|
18
|
+
require "peddler/api/fulfillment_inbound_v0"
|
19
|
+
require "peddler/api/fulfillment_outbound_2020_07_01"
|
20
|
+
require "peddler/api/invoices_2024_06_19"
|
21
|
+
require "peddler/api/listings_items_2020_09_01"
|
22
|
+
require "peddler/api/listings_items_2021_08_01"
|
23
|
+
require "peddler/api/listings_restrictions_2021_08_01"
|
24
|
+
require "peddler/api/merchant_fulfillment_v0"
|
25
|
+
require "peddler/api/messaging_v1"
|
26
|
+
require "peddler/api/notifications_v1"
|
27
|
+
require "peddler/api/orders_v0"
|
28
|
+
require "peddler/api/product_fees_v0"
|
29
|
+
require "peddler/api/product_pricing_2022_05_01"
|
30
|
+
require "peddler/api/product_pricing_v0"
|
31
|
+
require "peddler/api/product_type_definitions_2020_09_01"
|
32
|
+
require "peddler/api/replenishment_2022_11_07"
|
33
|
+
require "peddler/api/reports_2021_06_30"
|
34
|
+
require "peddler/api/sales_v1"
|
35
|
+
require "peddler/api/sellers_v1"
|
36
|
+
require "peddler/api/services_v1"
|
37
|
+
require "peddler/api/shipment_invoicing_v0"
|
38
|
+
require "peddler/api/shipping_v1"
|
39
|
+
require "peddler/api/shipping_v2"
|
40
|
+
require "peddler/api/solicitations_v1"
|
41
|
+
require "peddler/api/supply_sources_2020_07_01"
|
42
|
+
require "peddler/api/tokens_2021_03_01"
|
43
|
+
require "peddler/api/uploads_2020_11_01"
|
44
|
+
require "peddler/api/vendor_direct_fulfillment_inventory_v1"
|
45
|
+
require "peddler/api/vendor_direct_fulfillment_orders_2021_12_28"
|
46
|
+
require "peddler/api/vendor_direct_fulfillment_orders_v1"
|
47
|
+
require "peddler/api/vendor_direct_fulfillment_payments_v1"
|
48
|
+
require "peddler/api/vendor_direct_fulfillment_sandbox_test_data_2021_10_28"
|
49
|
+
require "peddler/api/vendor_direct_fulfillment_shipping_2021_12_28"
|
50
|
+
require "peddler/api/vendor_direct_fulfillment_shipping_v1"
|
51
|
+
require "peddler/api/vendor_direct_fulfillment_transactions_2021_12_28"
|
52
|
+
require "peddler/api/vendor_direct_fulfillment_transactions_v1"
|
53
|
+
require "peddler/api/vendor_invoices_v1"
|
54
|
+
require "peddler/api/vendor_orders_v1"
|
55
|
+
require "peddler/api/vendor_shipments_v1"
|
56
|
+
require "peddler/api/vendor_transaction_status_v1"
|
57
|
+
require "peddler/marketplace"
|
58
|
+
require "peddler/token"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peddler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hakan Ensari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -40,10 +40,10 @@ files:
|
|
40
40
|
- LICENSE
|
41
41
|
- README.md
|
42
42
|
- lib/peddler.rb
|
43
|
-
- lib/peddler/access_token.rb
|
44
43
|
- lib/peddler/api.rb
|
45
44
|
- lib/peddler/api/amazon_warehousing_and_distribution_2024_05_09.rb
|
46
45
|
- lib/peddler/api/aplus_content_2020_11_01.rb
|
46
|
+
- lib/peddler/api/application_integrations_2024_04_01.rb
|
47
47
|
- lib/peddler/api/application_management_2023_11_30.rb
|
48
48
|
- lib/peddler/api/catalog_items_2020_12_01.rb
|
49
49
|
- lib/peddler/api/catalog_items_2022_04_01.rb
|
@@ -53,10 +53,12 @@ files:
|
|
53
53
|
- lib/peddler/api/fba_inbound_eligibility_v1.rb
|
54
54
|
- lib/peddler/api/fba_inventory_v1.rb
|
55
55
|
- lib/peddler/api/feeds_2021_06_30.rb
|
56
|
+
- lib/peddler/api/finances_2024_06_19.rb
|
56
57
|
- lib/peddler/api/finances_v0.rb
|
57
58
|
- lib/peddler/api/fulfillment_inbound_2024_03_20.rb
|
58
59
|
- lib/peddler/api/fulfillment_inbound_v0.rb
|
59
60
|
- lib/peddler/api/fulfillment_outbound_2020_07_01.rb
|
61
|
+
- lib/peddler/api/invoices_2024_06_19.rb
|
60
62
|
- lib/peddler/api/listings_items_2020_09_01.rb
|
61
63
|
- lib/peddler/api/listings_items_2021_08_01.rb
|
62
64
|
- lib/peddler/api/listings_restrictions_2021_08_01.rb
|
@@ -93,10 +95,12 @@ files:
|
|
93
95
|
- lib/peddler/api/vendor_orders_v1.rb
|
94
96
|
- lib/peddler/api/vendor_shipments_v1.rb
|
95
97
|
- lib/peddler/api/vendor_transaction_status_v1.rb
|
98
|
+
- lib/peddler/endpoint.rb
|
96
99
|
- lib/peddler/error.rb
|
97
|
-
- lib/peddler/
|
100
|
+
- lib/peddler/marketplace.rb
|
101
|
+
- lib/peddler/token.rb
|
98
102
|
- lib/peddler/version.rb
|
99
|
-
homepage: https://github.com/
|
103
|
+
homepage: https://github.com/lineofflight/peddler
|
100
104
|
licenses:
|
101
105
|
- MIT
|
102
106
|
metadata:
|
@@ -119,5 +123,5 @@ requirements: []
|
|
119
123
|
rubygems_version: 3.5.16
|
120
124
|
signing_key:
|
121
125
|
specification_version: 4
|
122
|
-
summary:
|
126
|
+
summary: Amazon Selling Partner API (SP-API) in Ruby
|
123
127
|
test_files: []
|
data/lib/peddler/access_token.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "http"
|
4
|
-
|
5
|
-
module Peddler
|
6
|
-
# Requests a Login with Amazon (LWA) access token that authorizes your application to take actions on behalf of a
|
7
|
-
# selling partner. An LWA access token expires one hour after it is issued.
|
8
|
-
#
|
9
|
-
# @see https://developer-docs.amazon.com/sp-api/docs/connecting-to-the-selling-partner-api
|
10
|
-
class AccessToken
|
11
|
-
URL = "https://api.amazon.com/auth/o2/token"
|
12
|
-
|
13
|
-
attr_reader :client_id, :client_secret, :refresh_token, :scope
|
14
|
-
|
15
|
-
class << self
|
16
|
-
# Requests an access token
|
17
|
-
#
|
18
|
-
# @param client_id [String]
|
19
|
-
# @param client_secret [String]
|
20
|
-
# @param refresh_token [String]
|
21
|
-
# @param scope [String]
|
22
|
-
def request(client_id: ENV["LWA_CLIENT_ID"], client_secret: ENV["LWA_CLIENT_SECRET"], refresh_token: nil,
|
23
|
-
scope: nil)
|
24
|
-
new(client_id: client_id, client_secret: client_secret, refresh_token: refresh_token, scope: scope).request
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# @param client_id [String]
|
29
|
-
# @param client_secret [String]
|
30
|
-
# @param refresh_token [String]
|
31
|
-
# @param scope [String]
|
32
|
-
def initialize(client_id: ENV["LWA_CLIENT_ID"], client_secret: ENV["LWA_CLIENT_SECRET"], refresh_token: nil,
|
33
|
-
scope: nil)
|
34
|
-
@client_id = client_id
|
35
|
-
@client_secret = client_secret
|
36
|
-
@refresh_token = refresh_token
|
37
|
-
@scope = scope
|
38
|
-
|
39
|
-
validate_lwa_credentials!
|
40
|
-
validate_exclusive_token_or_scope!
|
41
|
-
end
|
42
|
-
|
43
|
-
def request
|
44
|
-
response = HTTP.post(URL, form: params)
|
45
|
-
response.parse.fetch("access_token")
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def validate_lwa_credentials!
|
51
|
-
if client_id.nil? || client_secret.nil?
|
52
|
-
raise ArgumentError, "Provide client_id and client_secret."
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def validate_exclusive_token_or_scope!
|
57
|
-
if @refresh_token.nil? == @scope.nil?
|
58
|
-
raise ArgumentError, "Provide either refresh_token or scope, not both."
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def params
|
63
|
-
{
|
64
|
-
grant_type: grant_type,
|
65
|
-
refresh_token: refresh_token,
|
66
|
-
scope: scope,
|
67
|
-
client_id: client_id,
|
68
|
-
client_secret: client_secret,
|
69
|
-
}.compact
|
70
|
-
end
|
71
|
-
|
72
|
-
def grant_type
|
73
|
-
scope ? "client_credentials" : "refresh_token"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/lib/peddler/region.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "uri"
|
4
|
-
|
5
|
-
module Peddler
|
6
|
-
class Region
|
7
|
-
class UnknownRegion < ArgumentError; end
|
8
|
-
|
9
|
-
# @see https://developer-docs.amazon.com/sp-api/docs/sp-api-endpoints
|
10
|
-
ENDPOINTS = {
|
11
|
-
"us-east-1" => "https://sellingpartnerapi-na.amazon.com",
|
12
|
-
"us-west-2" => "https://sellingpartnerapi-fe.amazon.com",
|
13
|
-
"eu-west-1" => "https://sellingpartnerapi-eu.amazon.com",
|
14
|
-
}
|
15
|
-
|
16
|
-
attr_reader :name
|
17
|
-
|
18
|
-
# @param [String] name
|
19
|
-
def initialize(name)
|
20
|
-
@name = name
|
21
|
-
end
|
22
|
-
|
23
|
-
# @return [String]
|
24
|
-
def endpoint
|
25
|
-
ENDPOINTS.fetch(name) do
|
26
|
-
raise UnknownRegion, "#{name} not found"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|