peddler 2.4.5 → 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 +402 -140
- data/lib/peddler/api/amazon_warehousing_and_distribution_2024_05_09.rb +92 -0
- data/lib/peddler/api/aplus_content_2020_11_01.rb +246 -0
- data/lib/peddler/api/application_integrations_2024_04_01.rb +56 -0
- data/lib/peddler/api/application_management_2023_11_30.rb +35 -0
- data/lib/peddler/api/catalog_items_2020_12_01.rb +81 -0
- data/lib/peddler/api/catalog_items_2022_04_01.rb +93 -0
- data/lib/peddler/api/catalog_items_v0.rb +103 -0
- data/lib/peddler/api/data_kiosk_2023_11_15.rb +108 -0
- data/lib/peddler/api/easy_ship_2022_03_23.rb +127 -0
- data/lib/peddler/api/fba_inbound_eligibility_v1.rb +44 -0
- data/lib/peddler/api/fba_inventory_v1.rb +122 -0
- data/lib/peddler/api/feeds_2021_06_30.rb +122 -0
- data/lib/peddler/api/finances_2024_06_19.rb +50 -0
- data/lib/peddler/api/finances_v0.rb +148 -0
- data/lib/peddler/api/fulfillment_inbound_2024_03_20.rb +759 -0
- data/lib/peddler/api/fulfillment_inbound_v0.rb +352 -0
- data/lib/peddler/api/fulfillment_outbound_2020_07_01.rb +259 -0
- data/lib/peddler/api/invoices_2024_06_19.rb +180 -0
- data/lib/peddler/api/listings_items_2020_09_01.rb +95 -0
- data/lib/peddler/api/listings_items_2021_08_01.rb +170 -0
- data/lib/peddler/api/listings_restrictions_2021_08_01.rb +47 -0
- data/lib/peddler/api/merchant_fulfillment_v0.rb +80 -0
- data/lib/peddler/api/messaging_v1.rb +273 -0
- data/lib/peddler/api/notifications_v1.rb +145 -0
- data/lib/peddler/api/orders_v0.rb +279 -0
- data/lib/peddler/api/product_fees_v0.rb +77 -0
- data/lib/peddler/api/product_pricing_2022_05_01.rb +54 -0
- data/lib/peddler/api/product_pricing_v0.rb +162 -0
- data/lib/peddler/api/product_type_definitions_2020_09_01.rb +86 -0
- data/lib/peddler/api/replenishment_2022_11_07.rb +57 -0
- data/lib/peddler/api/reports_2021_06_30.rb +163 -0
- data/lib/peddler/api/sales_v1.rb +77 -0
- data/lib/peddler/api/sellers_v1.rb +45 -0
- data/lib/peddler/api/services_v1.rb +348 -0
- data/lib/peddler/api/shipment_invoicing_v0.rb +59 -0
- data/lib/peddler/api/shipping_v1.rb +132 -0
- data/lib/peddler/api/shipping_v2.rb +319 -0
- data/lib/peddler/api/solicitations_v1.rb +63 -0
- data/lib/peddler/api/supply_sources_2020_07_01.rb +100 -0
- data/lib/peddler/api/tokens_2021_03_01.rb +38 -0
- data/lib/peddler/api/uploads_2020_11_01.rb +50 -0
- data/lib/peddler/api/vendor_direct_fulfillment_inventory_v1.rb +32 -0
- data/lib/peddler/api/vendor_direct_fulfillment_orders_2021_12_28.rb +84 -0
- data/lib/peddler/api/vendor_direct_fulfillment_orders_v1.rb +84 -0
- data/lib/peddler/api/vendor_direct_fulfillment_payments_v1.rb +31 -0
- data/lib/peddler/api/vendor_direct_fulfillment_sandbox_test_data_2021_10_28.rb +45 -0
- data/lib/peddler/api/vendor_direct_fulfillment_shipping_2021_12_28.rb +203 -0
- data/lib/peddler/api/vendor_direct_fulfillment_shipping_v1.rb +189 -0
- data/lib/peddler/api/vendor_direct_fulfillment_transactions_2021_12_28.rb +32 -0
- data/lib/peddler/api/vendor_direct_fulfillment_transactions_v1.rb +32 -0
- data/lib/peddler/api/vendor_invoices_v1.rb +30 -0
- data/lib/peddler/api/vendor_orders_v1.rb +159 -0
- data/lib/peddler/api/vendor_shipments_v1.rb +132 -0
- data/lib/peddler/api/vendor_transaction_status_v1.rb +33 -0
- data/lib/peddler/api.rb +138 -0
- data/lib/peddler/endpoint.rb +51 -0
- data/lib/peddler/error.rb +31 -0
- data/lib/peddler/marketplace.rb +38 -68
- data/lib/peddler/token.rb +70 -0
- data/lib/peddler/version.rb +1 -1
- data/lib/peddler.rb +56 -1
- metadata +74 -80
- data/lib/mws/easy_ship/client.rb +0 -93
- data/lib/mws/easy_ship.rb +0 -3
- data/lib/mws/feeds/client.rb +0 -122
- data/lib/mws/feeds.rb +0 -3
- data/lib/mws/finances/client.rb +0 -82
- data/lib/mws/finances.rb +0 -3
- data/lib/mws/fulfillment_inbound_shipment/client.rb +0 -388
- data/lib/mws/fulfillment_inbound_shipment.rb +0 -3
- data/lib/mws/fulfillment_inventory/client.rb +0 -57
- data/lib/mws/fulfillment_inventory.rb +0 -3
- data/lib/mws/fulfillment_outbound_shipment/client.rb +0 -211
- data/lib/mws/fulfillment_outbound_shipment.rb +0 -3
- data/lib/mws/merchant_fulfillment/client.rb +0 -87
- data/lib/mws/merchant_fulfillment.rb +0 -3
- data/lib/mws/off_amazon_payments.rb +0 -3
- data/lib/mws/orders/client.rb +0 -120
- data/lib/mws/orders.rb +0 -3
- data/lib/mws/products/client.rb +0 -268
- data/lib/mws/products.rb +0 -3
- data/lib/mws/recommendations/client.rb +0 -72
- data/lib/mws/recommendations.rb +0 -3
- data/lib/mws/reports/client.rb +0 -236
- data/lib/mws/reports.rb +0 -3
- data/lib/mws/sellers/client.rb +0 -44
- data/lib/mws/sellers.rb +0 -3
- data/lib/mws/shipment_invoicing/client.rb +0 -74
- data/lib/mws/shipment_invoicing.rb +0 -3
- data/lib/mws/subscriptions/client.rb +0 -179
- data/lib/mws/subscriptions.rb +0 -3
- data/lib/mws.rb +0 -29
- data/lib/peddler/client.rb +0 -159
- data/lib/peddler/errors/builder.rb +0 -64
- data/lib/peddler/errors/class_generator.rb +0 -40
- data/lib/peddler/errors/error.rb +0 -45
- data/lib/peddler/errors/parser.rb +0 -28
- data/lib/peddler/flat_file_parser.rb +0 -56
- data/lib/peddler/headers.rb +0 -102
- data/lib/peddler/operation.rb +0 -78
- data/lib/peddler/parser.rb +0 -33
- data/lib/peddler/structured_list.rb +0 -23
- data/lib/peddler/vcr_matcher.rb +0 -97
- data/lib/peddler/xml_parser.rb +0 -38
- data/lib/peddler/xml_response_parser.rb +0 -25
data/lib/peddler/headers.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
module Peddler
|
6
|
-
# Parses useful metadata returned in response headers
|
7
|
-
module Headers
|
8
|
-
# The size of the response body in bytes
|
9
|
-
# @return [String, nil]
|
10
|
-
def content_length
|
11
|
-
return unless headers['Content-Length']
|
12
|
-
|
13
|
-
headers['Content-Length'].to_i
|
14
|
-
end
|
15
|
-
|
16
|
-
# The MD5 digest of the response body
|
17
|
-
# @return [String, nil]
|
18
|
-
def content_md5
|
19
|
-
headers['Content-MD5']
|
20
|
-
end
|
21
|
-
|
22
|
-
# The MIME type of the response
|
23
|
-
# @return [String, nil]
|
24
|
-
def content_media_type
|
25
|
-
return unless headers['Content-Type']
|
26
|
-
|
27
|
-
headers['Content-Type'].split(';').first
|
28
|
-
end
|
29
|
-
|
30
|
-
# The general category into which the MIME type falls
|
31
|
-
# @return [String, nil]
|
32
|
-
def content_type
|
33
|
-
return unless content_media_type
|
34
|
-
|
35
|
-
content_media_type.split('/').first
|
36
|
-
end
|
37
|
-
|
38
|
-
# The exact kind of data of the specified type the MIME type represents
|
39
|
-
# @return [String, nil]
|
40
|
-
def content_subtype
|
41
|
-
return unless content_media_type
|
42
|
-
|
43
|
-
content_media_type.split('/').last
|
44
|
-
end
|
45
|
-
|
46
|
-
# The character encoding of the response
|
47
|
-
# @return [Encoding, nil]
|
48
|
-
def content_charset
|
49
|
-
match_data = headers['Content-Type']&.match(/charset=(.*);?/)
|
50
|
-
return unless match_data
|
51
|
-
|
52
|
-
string = match_data[1].upcase
|
53
|
-
string = 'UTF-8' if string == 'UTF8'
|
54
|
-
|
55
|
-
Encoding.find(string)
|
56
|
-
end
|
57
|
-
|
58
|
-
# The max hourly request quota for the requested operation
|
59
|
-
# @return [Integer, nil]
|
60
|
-
def mws_quota_max
|
61
|
-
return unless headers['x-mws-quota-max']
|
62
|
-
|
63
|
-
headers['x-mws-quota-max'].to_i
|
64
|
-
end
|
65
|
-
|
66
|
-
# The remaining hourly request quota for the requested operation
|
67
|
-
# @return [Integer, nil]
|
68
|
-
def mws_quota_remaining
|
69
|
-
return unless headers['x-mws-quota-remaining']
|
70
|
-
|
71
|
-
headers['x-mws-quota-remaining'].to_i
|
72
|
-
end
|
73
|
-
|
74
|
-
# When the hourly request quota for the requested operation resets
|
75
|
-
# @return [Time, nil]
|
76
|
-
def mws_quota_resets_on
|
77
|
-
return unless headers['x-mws-quota-resetsOn']
|
78
|
-
|
79
|
-
Time.parse(headers['x-mws-quota-resetsOn'])
|
80
|
-
end
|
81
|
-
|
82
|
-
# The ID of the request
|
83
|
-
# @return [String, nil]
|
84
|
-
def mws_request_id
|
85
|
-
headers['x-mws-request-id']
|
86
|
-
end
|
87
|
-
|
88
|
-
# The timestamp of the request
|
89
|
-
# @return [Time, nil]
|
90
|
-
def mws_timestamp
|
91
|
-
return unless headers['x-mws-timestamp']
|
92
|
-
|
93
|
-
Time.parse(headers['x-mws-timestamp'])
|
94
|
-
end
|
95
|
-
|
96
|
-
# The context of the response
|
97
|
-
# @return [String, nil]
|
98
|
-
def mws_response_context
|
99
|
-
headers['x-mws-response-context']
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
data/lib/peddler/operation.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'delegate'
|
4
|
-
require 'time'
|
5
|
-
require 'peddler/structured_list'
|
6
|
-
|
7
|
-
module Peddler
|
8
|
-
# @!visibility private
|
9
|
-
class Operation < SimpleDelegator
|
10
|
-
CAPITAL_LETTERS = /[A-Z]/.freeze
|
11
|
-
ALL_CAPS = %w[sku cod].freeze
|
12
|
-
private_constant :CAPITAL_LETTERS, :ALL_CAPS
|
13
|
-
|
14
|
-
def initialize(action)
|
15
|
-
super('Action' => action)
|
16
|
-
end
|
17
|
-
|
18
|
-
def structure!(*list_keys)
|
19
|
-
list_key = list_keys.shift
|
20
|
-
keys
|
21
|
-
.find_all { |key| key.end_with?(list_key) }
|
22
|
-
.each do |found_key|
|
23
|
-
builder = StructuredList.new(found_key, *list_keys)
|
24
|
-
vals = delete(found_key)
|
25
|
-
update(builder.build(vals))
|
26
|
-
end
|
27
|
-
|
28
|
-
self
|
29
|
-
end
|
30
|
-
|
31
|
-
def store(key, val, parent = nil)
|
32
|
-
key = [parent, camelize(key)].compact.join('.')
|
33
|
-
val = format_known_types(val)
|
34
|
-
|
35
|
-
if val.is_a?(Hash)
|
36
|
-
val.each { |keyval| store(*keyval, key) }
|
37
|
-
else
|
38
|
-
__getobj__.store(key, val)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def update(hsh)
|
43
|
-
hsh.each { |key, val| store(key, val) }
|
44
|
-
self
|
45
|
-
end
|
46
|
-
|
47
|
-
alias add update
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def camelize(key)
|
52
|
-
return key unless key.is_a?(Symbol)
|
53
|
-
return key.to_s if key.match?(CAPITAL_LETTERS)
|
54
|
-
|
55
|
-
key
|
56
|
-
.to_s
|
57
|
-
.split('_')
|
58
|
-
.map { |token| capitalize(token) }
|
59
|
-
.join
|
60
|
-
end
|
61
|
-
|
62
|
-
def capitalize(word)
|
63
|
-
if ALL_CAPS.any?(word)
|
64
|
-
word.upcase
|
65
|
-
else
|
66
|
-
word.capitalize
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def format_known_types(val)
|
71
|
-
val = val.utc.iso8601(2) if val.is_a?(Time)
|
72
|
-
val = val.iso8601 if val.is_a?(Date)
|
73
|
-
val = val.to_h if val.is_a?(Struct)
|
74
|
-
|
75
|
-
val
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/lib/peddler/parser.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'peddler/flat_file_parser'
|
4
|
-
require 'peddler/xml_response_parser'
|
5
|
-
|
6
|
-
module Peddler
|
7
|
-
# @!visibility private
|
8
|
-
module Parser
|
9
|
-
class << self
|
10
|
-
# We're massaging data produced by a motley army of developers. It's
|
11
|
-
# messy.
|
12
|
-
def new(res, encoding)
|
13
|
-
# Don't parse if there's no body
|
14
|
-
return res unless res.body
|
15
|
-
|
16
|
-
if xml?(res)
|
17
|
-
XMLResponseParser.new(res)
|
18
|
-
else
|
19
|
-
# Amazon returns a variety of content types for flat files. I simply
|
20
|
-
# assume anything not XML is a flat file.
|
21
|
-
FlatFileParser.new(res, encoding)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def xml?(res)
|
26
|
-
return true if res.headers['Content-Type'].start_with?('text/xml')
|
27
|
-
return true if res.body.start_with?('<?xml')
|
28
|
-
|
29
|
-
false
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Peddler
|
4
|
-
# @!visibility private
|
5
|
-
class StructuredList
|
6
|
-
def initialize(*keys)
|
7
|
-
@keys = keys
|
8
|
-
end
|
9
|
-
|
10
|
-
def build(vals)
|
11
|
-
Array(vals)
|
12
|
-
.flatten
|
13
|
-
.each_with_index
|
14
|
-
.reduce({}) { |hsh, (v, i)| hsh.merge(compose_key(i + 1) => v) }
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def compose_key(index)
|
20
|
-
(@keys.dup << index).join('.')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/peddler/vcr_matcher.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Peddler
|
4
|
-
# A custom matcher that can be used to record MWS interactions when
|
5
|
-
# writing integration tests
|
6
|
-
class VCRMatcher
|
7
|
-
# @!visibility private
|
8
|
-
TRANSIENT_PARAMS = %w[
|
9
|
-
Signature Timestamp StartDate CreatedAfter QueryStartDateTime
|
10
|
-
].freeze
|
11
|
-
|
12
|
-
# @!visibility private
|
13
|
-
SELLER_PARAMS = %w[
|
14
|
-
AWSAccessKeyId SellerId
|
15
|
-
].freeze
|
16
|
-
|
17
|
-
class << self
|
18
|
-
# @!visibility private
|
19
|
-
def call(*requests)
|
20
|
-
new(*requests).compare
|
21
|
-
end
|
22
|
-
|
23
|
-
# @!visibility private
|
24
|
-
def ignored_params
|
25
|
-
@ignored_params ||= TRANSIENT_PARAMS.dup
|
26
|
-
end
|
27
|
-
|
28
|
-
# Ignore seller specific attributes when recording
|
29
|
-
# @return [void]
|
30
|
-
def ignore_seller!
|
31
|
-
ignored_params.concat(SELLER_PARAMS)
|
32
|
-
ignored_params.uniq!
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# @!visibility private
|
37
|
-
attr_reader :requests
|
38
|
-
|
39
|
-
# @!visibility private
|
40
|
-
def initialize(*requests)
|
41
|
-
@requests = requests
|
42
|
-
end
|
43
|
-
|
44
|
-
# @!visibility private
|
45
|
-
def compare
|
46
|
-
compare_uris && compare_bodies
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def compare_uris
|
52
|
-
return false if hosts.reduce(:!=) || paths.reduce(:!=)
|
53
|
-
return true if queries.all?(&:empty?)
|
54
|
-
|
55
|
-
queries.reduce(:==)
|
56
|
-
end
|
57
|
-
|
58
|
-
def compare_bodies
|
59
|
-
bodies.reduce(:==)
|
60
|
-
end
|
61
|
-
|
62
|
-
def extract_params(string)
|
63
|
-
return {} unless string
|
64
|
-
|
65
|
-
params = ::CGI.parse(string)
|
66
|
-
self.class.ignored_params.each do |k|
|
67
|
-
params.delete(k)
|
68
|
-
end
|
69
|
-
|
70
|
-
params
|
71
|
-
end
|
72
|
-
|
73
|
-
def uris
|
74
|
-
requests.map { |r| URI.parse(r.uri) }
|
75
|
-
end
|
76
|
-
|
77
|
-
def hosts
|
78
|
-
uris.map(&:host)
|
79
|
-
end
|
80
|
-
|
81
|
-
def paths
|
82
|
-
uris.map(&:path)
|
83
|
-
end
|
84
|
-
|
85
|
-
def queries
|
86
|
-
uris.map { |uri| extract_params(uri.query) }
|
87
|
-
end
|
88
|
-
|
89
|
-
def bodies
|
90
|
-
if queries.all?(&:empty?)
|
91
|
-
requests.map { |request| extract_params(request.body) }
|
92
|
-
else
|
93
|
-
requests.map(&:body)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
data/lib/peddler/xml_parser.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'delegate'
|
4
|
-
require 'forwardable'
|
5
|
-
require 'peddler/headers'
|
6
|
-
require 'multi_xml'
|
7
|
-
|
8
|
-
module Peddler
|
9
|
-
# @!visibility private
|
10
|
-
class XMLParser < SimpleDelegator
|
11
|
-
extend Forwardable
|
12
|
-
include Headers
|
13
|
-
|
14
|
-
def_delegator :parse, :dig
|
15
|
-
|
16
|
-
def data
|
17
|
-
@data ||= find_data
|
18
|
-
end
|
19
|
-
|
20
|
-
alias parse data
|
21
|
-
|
22
|
-
def xml
|
23
|
-
MultiXml.parse(body)
|
24
|
-
end
|
25
|
-
|
26
|
-
def valid?
|
27
|
-
return unless headers['Content-Length']
|
28
|
-
|
29
|
-
headers['Content-Length'].to_i == body.size
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def find_data
|
35
|
-
raise NotImplementedError
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'peddler/xml_parser'
|
4
|
-
|
5
|
-
module Peddler
|
6
|
-
# @!visibility private
|
7
|
-
class XMLResponseParser < XMLParser
|
8
|
-
MATCHER = /^Message$|^Node$|Report|Result/.freeze
|
9
|
-
private_constant :MATCHER
|
10
|
-
|
11
|
-
def next_token
|
12
|
-
parse.fetch('NextToken', false)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
# FIXME: In next major version bump, stop assuming we know report internals.
|
18
|
-
def find_data
|
19
|
-
payload = xml.values.first
|
20
|
-
found = payload.find { |k, _| k.match(MATCHER) }
|
21
|
-
|
22
|
-
found&.last
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|