peddler 1.3.0 → 1.4.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 +8 -22
- data/lib/mws/fulfillment_outbound_shipment/client.rb +12 -5
- data/lib/mws/merchant_fulfillment/client.rb +2 -2
- data/lib/mws/orders/client.rb +9 -1
- data/lib/mws/products/client.rb +14 -1
- data/lib/mws/reports/client.rb +1 -1
- data/lib/mws.rb +0 -3
- data/lib/peddler/client.rb +12 -19
- data/lib/peddler/errors/builder.rb +20 -0
- data/lib/peddler/errors/error.rb +13 -0
- data/lib/peddler/errors/handler.rb +45 -0
- data/lib/peddler/errors/parser.rb +28 -0
- data/lib/peddler/flat_file_parser.rb +1 -1
- data/lib/peddler/marketplace.rb +2 -2
- data/lib/peddler/parser.rb +0 -1
- data/lib/peddler/structured_list.rb +1 -0
- data/lib/peddler/version.rb +1 -1
- data/lib/peddler/xml_parser.rb +1 -1
- data/test/helper.rb +1 -82
- data/test/integration/test_errors.rb +36 -0
- data/test/integration/test_feeds.rb +1 -1
- data/test/integration/test_fulfillment_inbound_shipment.rb +1 -1
- data/test/integration/test_fulfillment_inventory.rb +1 -1
- data/test/integration/test_fulfillment_outbound_shipment.rb +1 -1
- data/test/integration/test_merchant_fulfillment.rb +1 -1
- data/test/integration/test_off_amazon_payments.rb +1 -1
- data/test/integration/test_orders.rb +3 -1
- data/test/integration/test_products.rb +1 -1
- data/test/integration/test_recommendations.rb +2 -4
- data/test/integration/test_reports.rb +1 -1
- data/test/integration/test_sellers.rb +1 -1
- data/test/integration/test_subscriptions.rb +1 -1
- data/test/integration_helper.rb +41 -0
- data/test/mws.yml +28 -8
- data/test/mws.yml.example +21 -1
- data/test/recorder.rb +34 -0
- data/test/unit/mws/test_fulfillment_inbound_shipment_client.rb +2 -1
- data/test/unit/mws/test_fulfillment_outbound_shipment_client.rb +9 -2
- data/test/unit/mws/test_orders_client.rb +12 -0
- data/test/unit/mws/test_products_client.rb +37 -0
- data/test/unit/peddler/errors/test_builder.rb +16 -0
- data/test/unit/peddler/errors/test_error.rb +16 -0
- data/test/unit/peddler/errors/test_handler.rb +60 -0
- data/test/unit/peddler/{test_error_parser.rb → errors/test_parser.rb} +3 -3
- data/test/unit/peddler/test_client.rb +3 -3
- data/test/unit/peddler/test_flat_file_parser.rb +39 -30
- data/test/unit/peddler/test_structured_list.rb +5 -0
- data/test/unit/peddler/test_vcr_matcher.rb +4 -0
- data/test/unit/test_mws.rb +1 -1
- data/test/vcr_cassettes/CartInformation.yml +263 -13
- data/test/vcr_cassettes/CustomerInformation.yml +255 -5
- data/test/vcr_cassettes/Errors.yml +885 -0
- data/test/vcr_cassettes/Feeds.yml +5588 -17
- data/test/vcr_cassettes/FulfillmentInboundShipment.yml +3474 -39
- data/test/vcr_cassettes/FulfillmentInventory.yml +504 -9
- data/test/vcr_cassettes/FulfillmentOutboundShipment.yml +255 -5
- data/test/vcr_cassettes/MerchantFulfillment.yml +254 -4
- data/test/vcr_cassettes/OffAmazonPayments.yml +255 -5
- data/test/vcr_cassettes/Orders.yml +2696 -36
- data/test/vcr_cassettes/Products.yml +5534 -180
- data/test/vcr_cassettes/Recommendations.yml +847 -9
- data/test/vcr_cassettes/Reports.yml +3994 -101
- data/test/vcr_cassettes/Sellers.yml +255 -5
- data/test/vcr_cassettes/Subscriptions.yml +875 -13
- metadata +37 -27
- data/lib/mws/cart_information/client.rb +0 -74
- data/lib/mws/cart_information.rb +0 -1
- data/lib/mws/customer_information/client.rb +0 -80
- data/lib/mws/customer_information.rb +0 -1
- data/lib/mws/webstore/client.rb +0 -89
- data/lib/mws/webstore.rb +0 -1
- data/lib/peddler/error_parser.rb +0 -26
- data/test/integration/test_cart_information.rb +0 -11
- data/test/integration/test_customer_information.rb +0 -11
- data/test/integration/test_webstore.rb +0 -18
- data/test/unit/mws/test_cart_information_client.rb +0 -61
- data/test/unit/mws/test_customer_information_client.rb +0 -59
- data/test/unit/mws/test_webstore_client.rb +0 -101
- data/test/vcr_cassettes/Webstore.yml +0 -383
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84124da0ccd902d671cdd3e218ad2bd179be938a
|
4
|
+
data.tar.gz: 46a57b829b701d7f697af73a7c7da4ae90d4de19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e074ac10cc315dc9640ec8c78da16c0b434a10822993f97c8a98bf74ec7963f56b06d416aed4f0d51a66860bb151392771cfeef072ff8911111534adbae7f727
|
7
|
+
data.tar.gz: a4465cc11113ce167446e5f483a838c23bb24a2fe8946dbfd8b90455c5410c48e711d1820f2e1c5cd3334e58dbd8d81fab75958d533310728196dc1d6416aca6
|
data/README.md
CHANGED
@@ -101,7 +101,7 @@ Alternatively, rescue.
|
|
101
101
|
```ruby
|
102
102
|
begin
|
103
103
|
client.some_method
|
104
|
-
rescue Excon::
|
104
|
+
rescue Excon::Error::ServiceUnavailable => e
|
105
105
|
logger.warn e.response.message
|
106
106
|
retry
|
107
107
|
end
|
@@ -109,20 +109,6 @@ end
|
|
109
109
|
|
110
110
|
## The APIs
|
111
111
|
|
112
|
-
### Cart Information
|
113
|
-
|
114
|
-
With the MWS Cart Information API, you can retrieve shopping carts that your Amazon Webstore customers have created. The Cart Information API enables you to programmatically integrate Amazon Webstore cart information with your CRM systems, marketing applications, and other systems that require cart data.
|
115
|
-
|
116
|
-
- [Amazon references](https://developer.amazonservices.com/gp/mws/api.html?group=cartinformation§ion=cartinformation)
|
117
|
-
- [Peddler API docs](http://www.rubydoc.info/gems/peddler/MWS/CartInformation/Client)
|
118
|
-
|
119
|
-
### Customer Information
|
120
|
-
|
121
|
-
With the MWS Customer Information API, you can retrieve information from the customer accounts of your Amazon Webstore customers. This customer information includes customer name, contact information, customer account type, and associated Amazon Webstore marketplaces. The Customer Information API enables you to programmatically integrate Amazon Webstore customer account information with your CRM systems, marketing applications, and other systems that require customer data.
|
122
|
-
|
123
|
-
- [Amazon references](https://developer.amazonservices.com/gp/mws/api.html?group=customerinformation§ion=customerinformation)
|
124
|
-
- [Peddler API docs](http://www.rubydoc.info/gems/peddler/MWS/CustomerInformation/Client)
|
125
|
-
|
126
112
|
### Feeds
|
127
113
|
|
128
114
|
The MWS Feeds API lets you upload inventory and order data to Amazon. You can also use this API to get information about the processing of feeds.
|
@@ -160,6 +146,13 @@ Support for creating and cancelling fulfillment orders has been implemented, but
|
|
160
146
|
- [Amazon references](https://developer.amazonservices.com/gp/mws/api.html?group=fulfillment§ion=outbound)
|
161
147
|
- [Peddler API docs](http://www.rubydoc.info/gems/peddler/MWS/FulfillmentOutboundShipment/Client)
|
162
148
|
|
149
|
+
### Merchant Fulfillment
|
150
|
+
|
151
|
+
The Merchant Fulfillment API provides programmatic access to Amazon’s fulfillment shipping services for sellers, including competitive rates with Amazon-partnered carriers. Sellers can find out what shipping services are available by submitting information about a proposed fulfillment shipment, such as package size and weight; shipment origin and destination; and delivery date requirements. Sellers can choose from the shipping service options returned by Amazon, and then receive shipping labels for fulfilling their orders.
|
152
|
+
|
153
|
+
- [Amazon references](https://developer.amazonservices.com/gp/mws/api.html?group=merchantfulfillment§ion=merchantfulfillment)
|
154
|
+
- [Peddler API docs](http://www.rubydoc.info/gems/peddler/MWS/MerchantFulfillment/Client)
|
155
|
+
|
163
156
|
### Off Amazon Payments
|
164
157
|
|
165
158
|
The MWS Off-Amazon Payments API helps you to process payments for purchases made by buyers on your website using the Login and Pay with Amazon service. This API enables you to programmatically retrieve shipping and payment information provided by the buyer from their Amazon account. It allows you to authorize, capture, and refund payments, enabling a variety of payments scenarios.
|
@@ -215,10 +208,3 @@ The Amazon MWS Subscriptions API section enables you to subscribe to receive not
|
|
215
208
|
|
216
209
|
- [Amazon references](https://developer.amazonservices.com/gp/mws/api.html?group=subscriptions§ion=subscriptions)
|
217
210
|
- [Peddler API docs](http://www.rubydoc.info/gems/peddler/MWS/Subscriptions/Client)
|
218
|
-
|
219
|
-
### Webstore
|
220
|
-
|
221
|
-
With the Webstore API section of Amazon Marketplace Web Service (Amazon MWS), you can get “Email Me When Available” subscription information for items listed on your Amazon Webstore. The Webstore API section can help you plan your inventory replenishment cycle by enabling you to query for items that your customers subscribed to when they clicked the Email Me When Available button on your Webstore. The Webstore API section can also return information about the notifications that were sent to your customers when out-of-stock items came back in stock. This information, when combined with sales information that your Webstore tracks, can help you determine how many notifications were converted into sales.
|
222
|
-
|
223
|
-
- [Amazon references](https://developer.amazonservices.com/gp/mws/api.html?group=webstore§ion=webstore)
|
224
|
-
- [Peddler API docs](http://www.rubydoc.info/gems/peddler/MWS/Webstore/Client)
|
@@ -61,8 +61,8 @@ module MWS
|
|
61
61
|
end
|
62
62
|
|
63
63
|
operation('CreateFulfillmentOrder')
|
64
|
-
.add(
|
65
|
-
.merge(
|
64
|
+
.add(
|
65
|
+
opts.merge(
|
66
66
|
'SellerFulfillmentOrderId' => seller_fulfillment_order_id,
|
67
67
|
'DisplayableOrderId' => displayable_order_id,
|
68
68
|
'DisplayableOrderDateTime' => displayable_order_date_time,
|
@@ -71,7 +71,7 @@ module MWS
|
|
71
71
|
'DestinationAddress' => destination_address,
|
72
72
|
'Items' => items
|
73
73
|
)
|
74
|
-
|
74
|
+
)
|
75
75
|
.structure!('Items', 'member')
|
76
76
|
.structure!('NotificationEmailList', 'member')
|
77
77
|
|
@@ -141,8 +141,15 @@ module MWS
|
|
141
141
|
|
142
142
|
# Returns delivery tracking information for a package in an outbound
|
143
143
|
# shipment for a Multi-Channel Fulfillment order
|
144
|
-
|
145
|
-
|
144
|
+
#
|
145
|
+
# @see http://docs.developer.amazonservices.com/en_US/fba_outbound/FBAOutbound_GetPackageTrackingDetails.html
|
146
|
+
# @param [String] package_number
|
147
|
+
# @return [Peddler::XMLParser]
|
148
|
+
def get_package_tracking_details(package_number)
|
149
|
+
operation('GetPackageTrackingDetails')
|
150
|
+
.add('PackageNumber' => package_number)
|
151
|
+
|
152
|
+
run
|
146
153
|
end
|
147
154
|
|
148
155
|
# Requests that Amazon stop attempting to fulfill an existing fulfillment
|
@@ -49,7 +49,7 @@ module MWS
|
|
49
49
|
# Returns an existing shipment for the ShipmentId value that you specify
|
50
50
|
#
|
51
51
|
# @see http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_GetShipment.html
|
52
|
-
# @
|
52
|
+
# @param [String] shipment_id
|
53
53
|
# @return [Peddler::XMLParser]
|
54
54
|
def get_shipment(shipment_id)
|
55
55
|
operation('GetShipment')
|
@@ -64,7 +64,7 @@ module MWS
|
|
64
64
|
# value that you specify
|
65
65
|
#
|
66
66
|
# @see http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_CancelShipment.html
|
67
|
-
# @
|
67
|
+
# @param [String] shipment_id
|
68
68
|
# @return [Peddler::XMLParser]
|
69
69
|
def cancel_shipment(shipment_id)
|
70
70
|
operation('CancelShipment')
|
data/lib/mws/orders/client.rb
CHANGED
@@ -33,7 +33,6 @@ module MWS
|
|
33
33
|
if opts.key?(:tfm_shipment_status)
|
34
34
|
opts['TFMShipmentStatus'] = opts.delete(:tfm_shipment_status)
|
35
35
|
end
|
36
|
-
|
37
36
|
operation('ListOrders')
|
38
37
|
.add(opts)
|
39
38
|
.structure!('OrderStatus', 'Status')
|
@@ -41,6 +40,7 @@ module MWS
|
|
41
40
|
.structure!('MarketplaceId', 'Id')
|
42
41
|
.structure!('PaymentMethod')
|
43
42
|
.structure!('TFMShipmentStatus', 'Status')
|
43
|
+
require_start_time!
|
44
44
|
|
45
45
|
run
|
46
46
|
end
|
@@ -102,6 +102,14 @@ module MWS
|
|
102
102
|
operation('GetServiceStatus')
|
103
103
|
run
|
104
104
|
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def require_start_time!
|
109
|
+
if operation.values_at('CreatedAfter', 'LastUpdatedAfter').compact.empty?
|
110
|
+
raise ArgumentError, 'specify created_after or last_updated_after'
|
111
|
+
end
|
112
|
+
end
|
105
113
|
end
|
106
114
|
end
|
107
115
|
end
|
data/lib/mws/products/client.rb
CHANGED
@@ -165,7 +165,7 @@ module MWS
|
|
165
165
|
# Gets lowest priced offers for a single product, based on ASIN
|
166
166
|
#
|
167
167
|
# @see http://docs.developer.amazonservices.com/en_MX/products/Products_GetLowestPricedOffersForASIN.html
|
168
|
-
# @overload
|
168
|
+
# @overload get_lowest_priced_offers_for_asin(asin, item_condition, opts = { marketplace_id: primary_marketplace_id })
|
169
169
|
# @param [String] asin
|
170
170
|
# @param [String] item_condition
|
171
171
|
# @param [Hash] opts
|
@@ -182,6 +182,19 @@ module MWS
|
|
182
182
|
run
|
183
183
|
end
|
184
184
|
|
185
|
+
# Gets the estimated fees for a list of products.
|
186
|
+
#
|
187
|
+
# @see http://docs.developer.amazonservices.com/en_US/products/Products_GetMyFeesEstimate.html
|
188
|
+
# @param [Hash] fees_estimate_request one or more fees estimate requests
|
189
|
+
# @return [Peddler::XMLParser]
|
190
|
+
def get_my_fees_estimate(*fees_estimate_requests)
|
191
|
+
operation('GetMyFeesEstimate')
|
192
|
+
.add('FeesEstimateRequestList' => fees_estimate_requests)
|
193
|
+
.structure!('FeesEstimateRequestList', 'FeesEstimateRequest')
|
194
|
+
|
195
|
+
run
|
196
|
+
end
|
197
|
+
|
185
198
|
# Gets pricing information for seller's own offer listings, based on
|
186
199
|
# Seller SKU
|
187
200
|
#
|
data/lib/mws/reports/client.rb
CHANGED
@@ -188,7 +188,7 @@ module MWS
|
|
188
188
|
# @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportScheduleListByNextToken.html
|
189
189
|
# @raise [NotImplementedError]
|
190
190
|
def get_report_schedule_list_by_next_token(*)
|
191
|
-
|
191
|
+
raise NotImplementedError
|
192
192
|
end
|
193
193
|
|
194
194
|
# Counts scheduled reports
|
data/lib/mws.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'forwardable'
|
2
|
-
require 'mws/cart_information'
|
3
|
-
require 'mws/customer_information'
|
4
2
|
require 'mws/feeds'
|
5
3
|
require 'mws/finances'
|
6
4
|
require 'mws/fulfillment_inbound_shipment'
|
@@ -14,7 +12,6 @@ require 'mws/recommendations'
|
|
14
12
|
require 'mws/reports'
|
15
13
|
require 'mws/sellers'
|
16
14
|
require 'mws/subscriptions'
|
17
|
-
require 'mws/webstore'
|
18
15
|
|
19
16
|
# The various Amazon MWS API sections.
|
20
17
|
module MWS
|
data/lib/peddler/client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
require 'jeff'
|
3
|
+
require 'peddler/errors/parser'
|
3
4
|
require 'peddler/marketplace'
|
4
5
|
require 'peddler/operation'
|
5
6
|
require 'peddler/parser'
|
@@ -37,14 +38,7 @@ module Peddler
|
|
37
38
|
|
38
39
|
class << self
|
39
40
|
# @api private
|
40
|
-
|
41
|
-
|
42
|
-
# @api private
|
43
|
-
def parser
|
44
|
-
@parser ||= Parser
|
45
|
-
end
|
46
|
-
|
47
|
-
attr_writer :parser
|
41
|
+
attr_accessor :error_handler, :parser
|
48
42
|
|
49
43
|
# @api private
|
50
44
|
def path(path = nil)
|
@@ -53,12 +47,11 @@ module Peddler
|
|
53
47
|
|
54
48
|
# @api private
|
55
49
|
def version(version = nil)
|
56
|
-
version ? @version = version : @version
|
50
|
+
version ? @version = version : @version ||= nil
|
57
51
|
end
|
58
52
|
|
59
53
|
# Sets an error handler
|
60
|
-
# @yieldparam [Excon::
|
61
|
-
# @yieldparam [Excon::Response] response
|
54
|
+
# @yieldparam [Excon::Error] error
|
62
55
|
def on_error(&blk)
|
63
56
|
@error_handler = blk
|
64
57
|
end
|
@@ -67,13 +60,14 @@ module Peddler
|
|
67
60
|
|
68
61
|
def inherited(base)
|
69
62
|
base.parser = parser
|
63
|
+
base.error_handler = error_handler
|
70
64
|
base.path(path)
|
71
65
|
base.params(params)
|
72
|
-
base.on_error(&@error_handler)
|
73
66
|
end
|
74
67
|
end
|
75
68
|
|
76
|
-
|
69
|
+
self.error_handler = proc { raise }
|
70
|
+
self.parser = Parser
|
77
71
|
|
78
72
|
# Creates a new client instance
|
79
73
|
#
|
@@ -155,15 +149,14 @@ module Peddler
|
|
155
149
|
end
|
156
150
|
|
157
151
|
# Sets an error handler
|
158
|
-
# @yieldparam [Excon::
|
159
|
-
# @yieldparam [Excon::Response] response
|
152
|
+
# @yieldparam [Excon::Error] error
|
160
153
|
def on_error(&blk)
|
161
154
|
@error_handler = blk
|
162
155
|
end
|
163
156
|
|
164
157
|
# @api private
|
165
158
|
def error_handler
|
166
|
-
@error_handler || self.class.error_handler
|
159
|
+
(@error_handler ||= nil) || self.class.error_handler
|
167
160
|
end
|
168
161
|
|
169
162
|
# @api private
|
@@ -178,7 +171,7 @@ module Peddler
|
|
178
171
|
res = post(opts)
|
179
172
|
|
180
173
|
parser.new(res, encoding)
|
181
|
-
rescue Excon::
|
174
|
+
rescue Excon::Error => e
|
182
175
|
handle_error(e)
|
183
176
|
end
|
184
177
|
|
@@ -215,8 +208,8 @@ module Peddler
|
|
215
208
|
end
|
216
209
|
|
217
210
|
def decorate_error(e)
|
218
|
-
if e.is_a?(::Excon::
|
219
|
-
e.instance_variable_set(:@response,
|
211
|
+
if e.is_a?(:: Excon::Error::HTTPStatus)
|
212
|
+
e.instance_variable_set(:@response, Errors::Parser.new(e.response))
|
220
213
|
end
|
221
214
|
|
222
215
|
e
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'peddler/errors/error'
|
3
|
+
|
4
|
+
module Peddler
|
5
|
+
module Errors
|
6
|
+
# @api private
|
7
|
+
class Builder
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
def self.build(name)
|
11
|
+
instance.build(name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def build(name)
|
15
|
+
return Errors.const_get(name) if Errors.const_defined?(name)
|
16
|
+
Errors.const_set(name, Class.new(Error))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'excon'
|
2
|
+
require 'peddler/errors/builder'
|
3
|
+
|
4
|
+
module Peddler
|
5
|
+
module Errors
|
6
|
+
# @api private
|
7
|
+
class Handler
|
8
|
+
def self.call(exception)
|
9
|
+
new(exception).handle
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parameters
|
13
|
+
1
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :exception
|
17
|
+
|
18
|
+
def initialize(exception)
|
19
|
+
@exception = exception
|
20
|
+
end
|
21
|
+
|
22
|
+
def handle
|
23
|
+
if http_status_error?
|
24
|
+
raise error_class.new(exception.response.message, exception)
|
25
|
+
else
|
26
|
+
raise exception
|
27
|
+
end
|
28
|
+
rescue NameError
|
29
|
+
raise exception
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def error_class
|
35
|
+
Errors.const_get(exception.response.code)
|
36
|
+
rescue NameError
|
37
|
+
Builder.build(exception.response.code)
|
38
|
+
end
|
39
|
+
|
40
|
+
def http_status_error?
|
41
|
+
exception.is_a?(::Excon::Error::HTTPStatus)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'peddler/xml_parser'
|
2
|
+
|
3
|
+
module Peddler
|
4
|
+
module Errors
|
5
|
+
# @api private
|
6
|
+
class Parser < XMLParser
|
7
|
+
def message
|
8
|
+
parse['Message']
|
9
|
+
end
|
10
|
+
|
11
|
+
def type
|
12
|
+
parse['Type']
|
13
|
+
end
|
14
|
+
|
15
|
+
def code
|
16
|
+
parse['Code']
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def find_data
|
22
|
+
xml
|
23
|
+
.fetch('ErrorResponse', {})
|
24
|
+
.fetch('Error', {})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/peddler/marketplace.rb
CHANGED
@@ -20,7 +20,7 @@ module Peddler
|
|
20
20
|
attr_reader :id
|
21
21
|
|
22
22
|
def initialize(id)
|
23
|
-
@id = id ||
|
23
|
+
@id = id || raise(BadId, 'missing MarketplaceId')
|
24
24
|
end
|
25
25
|
|
26
26
|
def host
|
@@ -44,7 +44,7 @@ module Peddler
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def find_host
|
47
|
-
HOSTS.fetch(id) {
|
47
|
+
HOSTS.fetch(id) { raise BadId, %("#{id}" is not a valid MarketplaceId) }
|
48
48
|
end
|
49
49
|
|
50
50
|
def japanese?
|
data/lib/peddler/parser.rb
CHANGED
data/lib/peddler/version.rb
CHANGED
data/lib/peddler/xml_parser.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -10,89 +10,8 @@ SimpleCov.start do
|
|
10
10
|
add_filter '/test/'
|
11
11
|
end
|
12
12
|
|
13
|
-
require 'dig_rb'
|
14
13
|
require 'minitest/autorun'
|
15
|
-
require 'peddler/vcr_matcher'
|
16
|
-
require 'yaml'
|
17
|
-
require 'vcr'
|
18
14
|
begin
|
19
15
|
require 'pry'
|
20
|
-
rescue LoadError
|
21
|
-
end
|
22
|
-
|
23
|
-
# Wraps MWS credentials to run integration tests against
|
24
|
-
#
|
25
|
-
# Replace entries in the fixture file with real credentials if adding new tests
|
26
|
-
# or otherwise testing against live data.
|
27
|
-
module Accounts
|
28
|
-
extend Enumerable
|
29
|
-
|
30
|
-
def self.each(&blk)
|
31
|
-
@data.each(&blk)
|
32
|
-
end
|
33
|
-
|
34
|
-
%w(mws.yml mws.yml.example).each do |path|
|
35
|
-
file = File.expand_path("../#{path}", __FILE__)
|
36
|
-
if File.exist?(file)
|
37
|
-
@data = YAML.load_file(file)
|
38
|
-
break
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Bootstraps VCR
|
44
|
-
module Recorder
|
45
|
-
def setup
|
46
|
-
ENV['LIVE'] ? VCR.turn_off! : VCR.insert_cassette(test_name)
|
47
|
-
end
|
48
|
-
|
49
|
-
def teardown
|
50
|
-
VCR.eject_cassette if VCR.turned_on?
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_name
|
54
|
-
self.class.name.sub('Test', '')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Sets up clients for integration testing
|
59
|
-
class IntegrationTest < MiniTest::Test
|
60
|
-
include Recorder
|
61
|
-
|
62
|
-
def clients
|
63
|
-
Accounts.map do |account|
|
64
|
-
klass = MWS.const_get("#{test_name}::Client")
|
65
|
-
klass.new(account)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
VCR.configure do |c|
|
71
|
-
c.hook_into :excon
|
72
|
-
c.cassette_library_dir = 'test/vcr_cassettes'
|
73
|
-
|
74
|
-
::Peddler::VCRMatcher.ignore_seller!
|
75
|
-
|
76
|
-
# HTTP errors are not Peddler's concern, so ignore them to ease development.
|
77
|
-
c.before_record do |interaction|
|
78
|
-
code = interaction.response.status.code
|
79
|
-
interaction.ignore! if code >= 400 && code != 414
|
80
|
-
end
|
81
|
-
c.default_cassette_options = {
|
82
|
-
match_requests_on: [::Peddler::VCRMatcher],
|
83
|
-
record: !ENV['RECORD'] ? :none : :new_episodes
|
84
|
-
}
|
85
|
-
|
86
|
-
# So that fixtures do not depend on merchant credentials
|
87
|
-
Accounts.each do |account|
|
88
|
-
c.filter_sensitive_data('MERCHANT_ID') { account['merchant_id'] }
|
89
|
-
c.filter_sensitive_data('AWS_ACCESS_KEY_ID') { account['aws_access_key_id'] }
|
90
|
-
c.before_record do |interaction|
|
91
|
-
%w(
|
92
|
-
BuyerName BuyerEmail Name AddressLine1 PostalCode Phone Amount
|
93
|
-
).each do |key|
|
94
|
-
interaction.response.body.gsub!(/<#{key}>[^<]+</, "<#{key}>FILTERED<")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
16
|
+
rescue LoadError
|
98
17
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'integration_helper'
|
2
|
+
require 'mws/orders'
|
3
|
+
require 'peddler/errors/handler'
|
4
|
+
|
5
|
+
class TestErrors < IntegrationTest
|
6
|
+
def setup
|
7
|
+
@previous_error_handler = MWS::Orders::Client.error_handler
|
8
|
+
MWS::Orders::Client.error_handler = Peddler::Errors::Handler
|
9
|
+
@api = 'Orders'
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
MWS::Orders::Client.error_handler = @previous_error_handler
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_invalid_key
|
19
|
+
clients.each do |client|
|
20
|
+
e = assert_raises Peddler::Errors::Error do
|
21
|
+
client.aws_access_key_id = 'foo'
|
22
|
+
client.get_order('bar')
|
23
|
+
end
|
24
|
+
assert_instance_of Peddler::Errors::InvalidAccessKeyId, e
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_request_throttled
|
29
|
+
clients.each do |client|
|
30
|
+
e = assert_raises Peddler::Errors::Error do
|
31
|
+
client.get_order('foo')
|
32
|
+
end
|
33
|
+
assert_instance_of Peddler::Errors::RequestThrottled, e
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'integration_helper'
|
2
2
|
require 'mws/orders'
|
3
3
|
|
4
4
|
class TestOrders < IntegrationTest
|
@@ -13,6 +13,8 @@ class TestOrders < IntegrationTest
|
|
13
13
|
.dig('Orders', 'Order')
|
14
14
|
.map { |order| order['AmazonOrderId'] }
|
15
15
|
|
16
|
+
next if order_ids.count < 2
|
17
|
+
|
16
18
|
orders = client
|
17
19
|
.get_order(*order_ids)
|
18
20
|
.parse
|