peddler 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cda72505daf1765d33219d8c8f0172a896947438
4
- data.tar.gz: eb4e2949c291be4ce67391e77a1c51371dbefef2
3
+ metadata.gz: 9fe93b1e3df4edf8e6c43dff0c345c54c810dfc2
4
+ data.tar.gz: 7357b893235c06ca4770e693229c2bcaf3cdfb1a
5
5
  SHA512:
6
- metadata.gz: a15a7ca00095ff09099eda59af7afcfa7ee9d3bda1dd541767e8981eb5bfc2c86e6552e317af377007417e9905c1e0741dbd0d5c13b3e8e839d2b0d3c1c6ac68
7
- data.tar.gz: 6df5642273624a132ee07f7308bfaf577b508140260c73df841976d7a565fcb3e1cb146898af9d16c8e60174f0f64741a9e91c4afba94ac63348eb394c39e3ae
6
+ metadata.gz: 1a603aeeadcfc890cb58bce2d9930811a16e464c9133e900fc546ce446ee8ffd1471abab5b2c42591fa987e6fe8e5f2b7212386ac4b32d062d25330ea27b9293
7
+ data.tar.gz: a4e569716f65d6269cf39e1822b44313ec543cbee0e25f8e4fb9f42eb19a1d0774ec92f688db62509ae229bb59c12a96185862ea15b304da3c841467d11261fe
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2009-2014 Hakan Ensari
3
+ Copyright (c) Hakan Ensari
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -71,6 +71,8 @@ client = MWS.orders(
71
71
 
72
72
  Once you have a client with valid credentials, you should be able to make requests to the API. Clients map operation names in a flat structure. Methods have positional arguments for required input and keyword arguments for optional parameters. Both method and argument names are underscored but otherwise identical to the names of the corresponding operations and parameters documented in the API.
73
73
 
74
+ ### Parser
75
+
74
76
  Peddler wraps successful responses in a parser that handles both XML documents and flat files:
75
77
 
76
78
  ```ruby
@@ -86,7 +88,13 @@ MWS::Orders::Client.parser = MyParser
86
88
 
87
89
  For a sample implementation, see my [MWS Orders](https://github.com/hakanensari/mws-orders) library.
88
90
 
89
- Finally, you can handle network errors caused by throttling or other transient issues by defining an error handler.
91
+ ### Debugging
92
+
93
+ To introspect requests, set the `EXCON_DEBUG` environment variable to a truthy value.
94
+
95
+ ### Errors
96
+
97
+ Handle network errors caused by throttling or other transient issues by defining an error handler.
90
98
 
91
99
  ```ruby
92
100
  MWS::Orders::Client.on_error do |e|
@@ -10,6 +10,40 @@ module MWS
10
10
  version '2010-10-01'
11
11
  path "/FulfillmentInboundShipment/#{version}"
12
12
 
13
+ # Returns inbound guidance for a list of items by Seller SKU
14
+ #
15
+ # @see http://docs.developer.amazonservices.com/en_US/fba_inbound/FBAInbound_GetInboundGuidanceForSKU.html
16
+ # @param [String] marketplace_id
17
+ # @param [String] one or more seller_skus
18
+ # @return [Peddler::XMLParser]
19
+ def get_inbound_guidance_for_sku(marketplace_id, *seller_skus)
20
+ operation('GetInboundGuidanceForSKU')
21
+ .add(
22
+ 'MarketplaceId' => marketplace_id,
23
+ 'SellerSKUList' => seller_skus
24
+ )
25
+ .structure!('SellerSKUList', 'Id')
26
+
27
+ run
28
+ end
29
+
30
+ # Returns inbound guidance for a list of items by ASIN
31
+ #
32
+ # @see http://docs.developer.amazonservices.com/en_US/fba_inbound/FBAInbound_GetInboundGuidanceForASIN.html
33
+ # @param [String] marketplace_id
34
+ # @param [String] one or more asins
35
+ # @return [Peddler::XMLParser]
36
+ def get_inbound_guidance_for_asin(marketplace_id, *asins)
37
+ operation('GetInboundGuidanceForASIN')
38
+ .add(
39
+ 'MarketplaceId' => marketplace_id,
40
+ 'ASINList' => asins
41
+ )
42
+ .structure!('ASINList', 'Id')
43
+
44
+ run
45
+ end
46
+
13
47
  # Returns the information required to create an inbound shipment
14
48
  #
15
49
  # @see http://docs.developer.amazonservices.com/en_US/fba_inbound/FBAInbound_CreateInboundShipmentPlan.html
@@ -20,10 +54,12 @@ module MWS
20
54
  # @return [Peddler::XMLParser]
21
55
  def create_inbound_shipment_plan(ship_from_address, inbound_shipment_plan_request_items, opts = {})
22
56
  operation('CreateInboundShipmentPlan')
23
- .add(opts.update(
24
- 'ShipFromAddress' => ship_from_address,
25
- 'InboundShipmentPlanRequestItems' => inbound_shipment_plan_request_items
26
- ))
57
+ .add(
58
+ opts.update(
59
+ 'ShipFromAddress' => ship_from_address,
60
+ 'InboundShipmentPlanRequestItems' => inbound_shipment_plan_request_items
61
+ )
62
+ )
27
63
  .structure!('InboundShipmentPlanRequestItems', 'member')
28
64
 
29
65
  run
@@ -38,7 +74,13 @@ module MWS
38
74
  # @option opts [Array<Struct, Hash>] :inbound_shipment_items
39
75
  # @return [Peddler::XMLParser]
40
76
  def create_inbound_shipment(shipment_id, inbound_shipment_header, opts = {})
41
- build_inbound_shipment_operation('CreateInboundShipment', shipment_id, inbound_shipment_header, opts)
77
+ build_inbound_shipment_operation(
78
+ 'CreateInboundShipment',
79
+ shipment_id,
80
+ inbound_shipment_header,
81
+ opts
82
+ )
83
+
42
84
  run
43
85
  end
44
86
 
@@ -51,7 +93,77 @@ module MWS
51
93
  # @option opts [Array<Struct, Hash>] :inbound_shipment_items
52
94
  # @return [Peddler::XMLParser]
53
95
  def update_inbound_shipment(shipment_id, inbound_shipment_header, opts = {})
54
- build_inbound_shipment_operation('UpdateInboundShipment', shipment_id, inbound_shipment_header, opts)
96
+ build_inbound_shipment_operation(
97
+ 'UpdateInboundShipment',
98
+ shipment_id,
99
+ inbound_shipment_header,
100
+ opts
101
+ )
102
+
103
+ run
104
+ end
105
+
106
+ # Returns pre-order information, including dates
107
+ #
108
+ # @see http://docs.developer.amazonservices.com/en_US/fba_inbound/FBAInbound_GetPreorderInfo.html
109
+ # @param [String] shipment_id
110
+ # @return [Peddler::XMLParser]
111
+ def get_preorder_info(shipment_id)
112
+ operation('GetPreorderInfo')
113
+ .add(
114
+ 'ShipmentId' => shipment_id
115
+ )
116
+
117
+ run
118
+ end
119
+
120
+ # Confirms a shipment for pre-order
121
+ #
122
+ # @see http://docs.developer.amazonservices.com/en_US/fba_inbound/FBAInbound_ConfirmPreorder.html
123
+ # @param [String] shipment_id
124
+ # @param [#iso8601] need_by_date
125
+ # @return [Peddler::XMLParser]
126
+ def confirm_preorder(shipment_id, need_by_date)
127
+ operation('ConfirmPreorder')
128
+ .add(
129
+ 'ShipmentId' => shipment_id,
130
+ 'NeedByDate' => need_by_date
131
+ )
132
+
133
+ run
134
+ end
135
+
136
+ # Returns labeling requirements and item preparation instructions to help you prepare items for an inbound shipment
137
+ #
138
+ # @see http://docs.developer.amazonservices.com/en_US/fba_inbound/FBAInbound_GetPrepInstructionsForSKU.html
139
+ # @param [String] ship_to_country_code
140
+ # @param [String] one or more seller_skus
141
+ # @return [Peddler::XMLParser]
142
+ def get_prep_instructions_for_sku(ship_to_country_code, *seller_skus)
143
+ operation('GetPrepInstructionsForSKU')
144
+ .add(
145
+ 'SellerSKUList' => seller_skus,
146
+ 'ShipToCountryCode' => ship_to_country_code
147
+ )
148
+ .structure!('SellerSKUList', 'Id')
149
+
150
+ run
151
+ end
152
+
153
+ # Returns item preparation instructions to help with item sourcing decisions
154
+ #
155
+ # @see http://docs.developer.amazonservices.com/en_US/fba_inbound/FBAInbound_GetPrepInstructionsForASIN.html
156
+ # @param [String] ship_to_country_code
157
+ # @param [String] one or more asins
158
+ # @return [Peddler::XMLParser]
159
+ def get_prep_instructions_for_asin(ship_to_country_code, *asins)
160
+ operation('GetPrepInstructionsForASIN')
161
+ .add(
162
+ 'ASINList' => asins,
163
+ 'ShipToCountryCode' => ship_to_country_code
164
+ )
165
+ .structure!('ASINList', 'Id')
166
+
55
167
  run
56
168
  end
57
169
 
@@ -138,6 +250,43 @@ module MWS
138
250
  run
139
251
  end
140
252
 
253
+ # Returns unique package labels for faster and more accurate shipment processing at the Amazon fulfillment centre
254
+ #
255
+ # @see http://docs.developer.amazonservices.com/en_US/fba_inbound/FBAInbound_GetUniquePackageLabels.html
256
+ # @param [String] shipment_id
257
+ # @param [String] page_type
258
+ # @param [Array<String>] package_labels_to_print
259
+ # @return [Peddler::XMLParser]
260
+ def get_unique_package_labels(shipment_id, page_type, package_labels_to_print)
261
+ operation('GetUniquePackageLabels')
262
+ .add(
263
+ 'ShipmentId' => shipment_id,
264
+ 'PageType' => page_type,
265
+ 'PackageLabelsToPrint' => package_labels_to_print
266
+ )
267
+ .structure!('PackageLabelsToPrint', 'member')
268
+
269
+ run
270
+ end
271
+
272
+ # Returns pallet labels
273
+ #
274
+ # @see http://docs.developer.amazonservices.com/en_US/fba_inbound/FBAInbound_GetPalletLabels.html
275
+ # @param [String] shipment_id
276
+ # @param [String] page_type
277
+ # @param [Integer] number_of_pallets
278
+ # @return [Peddler::XMLParser]
279
+ def get_pallet_labels(shipment_id, page_type, number_of_pallets)
280
+ operation('GetPalletLabels')
281
+ .add(
282
+ 'ShipmentId' => shipment_id,
283
+ 'PageType' => page_type,
284
+ 'NumberOfPallets' => number_of_pallets
285
+ )
286
+
287
+ run
288
+ end
289
+
141
290
  # Returns PDF document data for printing a bill of lading for an inbound
142
291
  # shipment
143
292
  #
@@ -19,6 +19,7 @@ module MWS
19
19
  # @option opts [Array<String>, String] :seller_skus
20
20
  # @option opts [String, #iso8601] :query_start_date_time
21
21
  # @option opts [String] :response_group
22
+ # @option opts [String] :marketplace_id
22
23
  # @return [Peddler::XMLParser]
23
24
  def list_inventory_supply(opts = {})
24
25
  operation('ListInventorySupply')
@@ -185,6 +185,7 @@ module MWS
185
185
  # Gets the estimated fees for a list of products.
186
186
  #
187
187
  # @see http://docs.developer.amazonservices.com/en_US/products/Products_GetMyFeesEstimate.html
188
+ # @see http://docs.developer.amazonservices.com/en_US/products/Products_Datatypes.html#FeesEstimateRequest
188
189
  # @param [Hash] fees_estimate_request one or more fees estimate requests
189
190
  # @return [Peddler::XMLParser]
190
191
  def get_my_fees_estimate(*fees_estimate_requests)
@@ -1,5 +1,14 @@
1
1
  module Peddler
2
+ # @api private
2
3
  module Errors
4
+ KNOWN = %w(
5
+ AccessDenied
6
+ InvalidMarketplace
7
+ InvalidParameterValue
8
+ QuotaExceeded
9
+ RequestThrottled
10
+ ).freeze
11
+
3
12
  # @api private
4
13
  class Error < StandardError
5
14
  attr_reader :cause
@@ -9,5 +18,9 @@ module Peddler
9
18
  super msg
10
19
  end
11
20
  end
21
+
22
+ KNOWN.each do |name|
23
+ const_set name, Class.new(Error)
24
+ end
12
25
  end
13
26
  end
@@ -5,6 +5,8 @@ require 'peddler/structured_list'
5
5
  module Peddler
6
6
  # @api private
7
7
  class Operation < SimpleDelegator
8
+ CAPITAL_LETTERS = /[A-Z]/
9
+
8
10
  def initialize(action)
9
11
  super('Action' => action)
10
12
  end
@@ -45,6 +47,8 @@ module Peddler
45
47
  private
46
48
 
47
49
  def camelize(sym)
50
+ return sym.to_s if sym =~ CAPITAL_LETTERS
51
+
48
52
  sym
49
53
  .to_s
50
54
  .split('_')
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Peddler
3
- VERSION = '1.4.1'.freeze
3
+ VERSION = '1.5.0'.freeze
4
4
  end
@@ -3,6 +3,9 @@ require 'peddler/xml_parser'
3
3
  module Peddler
4
4
  # @api private
5
5
  class XMLResponseParser < XMLParser
6
+ MATCHER = /Message|Report|Result/
7
+ private_constant :MATCHER
8
+
6
9
  def next_token
7
10
  parse.fetch('NextToken', false)
8
11
  end
@@ -11,8 +14,7 @@ module Peddler
11
14
 
12
15
  def find_data
13
16
  payload = xml.values.first
14
- found = payload.find { |k, _| k.include?('Result') } ||
15
- payload.find { |k, _| k == 'Message' }
17
+ found = payload.find { |k, _| k.match(MATCHER) }
16
18
 
17
19
  found.last if found
18
20
  end
data/test/helper.rb CHANGED
@@ -1,13 +1,15 @@
1
- require 'simplecov'
2
- require 'coveralls'
1
+ if RUBY_ENGINE == 'ruby'
2
+ require 'simplecov'
3
+ require 'coveralls'
3
4
 
4
- SimpleCov.formatters = [
5
- SimpleCov::Formatter::HTMLFormatter,
6
- Coveralls::SimpleCov::Formatter
7
- ]
5
+ SimpleCov.formatters = [
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
8
9
 
9
- SimpleCov.start do
10
- add_filter '/test/'
10
+ SimpleCov.start do
11
+ add_filter '/test/'
12
+ end
11
13
  end
12
14
 
13
15
  require 'minitest/autorun'
@@ -51,10 +51,47 @@ class TestProducts < IntegrationTest
51
51
  end
52
52
  end
53
53
 
54
+ def test_gets_my_fees_estimate
55
+ clients.each do |client|
56
+ res = client.get_my_fees_estimate(
57
+ marketplace_id: client.primary_marketplace_id,
58
+ id_type: 'ASIN',
59
+ id_value: '1780935374',
60
+ price_to_estimate_fees: {
61
+ listing_price: {
62
+ currency_code: currency_code_for(client.primary_marketplace_id),
63
+ amount: 100
64
+ }
65
+ },
66
+ identifier: '123',
67
+ is_amazon_fulfilled: false
68
+ )
69
+ assert res
70
+ .parse
71
+ .dig('FeesEstimateResultList', 'FeesEstimateResult', 'FeesEstimate')
72
+ end
73
+ end
74
+
54
75
  def test_gets_service_status
55
76
  clients.each do |client|
56
77
  res = client.get_service_status
57
78
  refute_empty res.parse
58
79
  end
59
80
  end
81
+
82
+ private
83
+
84
+ CURRENCY_CODES = {
85
+ 'A2EUQ1WTGCTBG2' => 'CAD',
86
+ 'AAHKV2X7AFYLW' => 'CNY',
87
+ 'A1F83G8C2ARO7P' => 'GBP',
88
+ 'A21TJRUUN4KGV' => 'INR',
89
+ 'A1VC38T7YXB528' => 'JPY',
90
+ 'A1AM78C64UM0Y8' => 'MXN',
91
+ 'ATVPDKIKX0DER' => 'USD'
92
+ }.freeze
93
+
94
+ def currency_code_for(marketplace_id)
95
+ CURRENCY_CODES.fetch(marketplace_id, 'EUR')
96
+ end
60
97
  end
@@ -6,6 +6,34 @@ class TestMWSFulfillmentInboundShipmentClient < MiniTest::Test
6
6
  @client = MWS::FulfillmentInboundShipment::Client.new
7
7
  end
8
8
 
9
+ def test_gets_inbound_guidance_for_sku
10
+ operation = {
11
+ 'Action' => 'GetInboundGuidanceForSKU',
12
+ 'MarketplaceId' => 'ATVPDKIKX0DER',
13
+ 'SellerSKUList.Id.1' => 'us001'
14
+ }
15
+
16
+ @client.stub(:run, nil) do
17
+ @client.get_inbound_guidance_for_sku('ATVPDKIKX0DER', 'us001')
18
+ end
19
+
20
+ assert_equal operation, @client.operation
21
+ end
22
+
23
+ def test_gets_inbound_guidance_for_asin
24
+ operation = {
25
+ 'Action' => 'GetInboundGuidanceForASIN',
26
+ 'MarketplaceId' => 'ATVPDKIKX0DER',
27
+ 'ASINList.Id.1' => 'B00005N5PF'
28
+ }
29
+
30
+ @client.stub(:run, nil) do
31
+ @client.get_inbound_guidance_for_asin('ATVPDKIKX0DER', 'B00005N5PF')
32
+ end
33
+
34
+ assert_equal operation, @client.operation
35
+ end
36
+
9
37
  def test_creates_inbound_shipment_plan
10
38
  operation = {
11
39
  'Action' => 'CreateInboundShipmentPlan',
@@ -50,6 +78,62 @@ class TestMWSFulfillmentInboundShipmentClient < MiniTest::Test
50
78
  assert_equal operation, @client.operation
51
79
  end
52
80
 
81
+ def test_gets_preorder_info
82
+ operation = {
83
+ 'Action' => 'GetPreorderInfo',
84
+ 'ShipmentId' => '1'
85
+ }
86
+
87
+ @client.stub(:run, nil) do
88
+ @client.get_preorder_info('1')
89
+ end
90
+
91
+ assert_equal operation, @client.operation
92
+ end
93
+
94
+ def test_confirms_preorder
95
+ operation = {
96
+ 'Action' => 'ConfirmPreorder',
97
+ 'ShipmentId' => '1',
98
+ 'NeedByDate' => '2015-12-27'
99
+ }
100
+
101
+ @client.stub(:run, nil) do
102
+ @client.confirm_preorder('1', Date.new(2015, 12, 27))
103
+ end
104
+
105
+ assert_equal operation, @client.operation
106
+ end
107
+
108
+ def test_gets_prep_instructions_for_sku
109
+ operation = {
110
+ 'Action' => 'GetPrepInstructionsForSKU',
111
+ 'ShipToCountryCode' => 'US',
112
+ 'SellerSKUList.Id.1' => 'ca_001'
113
+ }
114
+
115
+ @client.stub(:run, nil) do
116
+ @client.get_prep_instructions_for_sku('US', 'ca_001')
117
+ end
118
+
119
+ assert_equal operation, @client.operation
120
+ end
121
+
122
+ def test_gets_prep_instructions_for_asin
123
+ operation = {
124
+ 'Action' => 'GetPrepInstructionsForASIN',
125
+ 'ShipToCountryCode' => 'US',
126
+ 'ASINList.Id.1' => 'B00005N5PF',
127
+ 'ASINList.Id.2' => 'B0INVALIDF'
128
+ }
129
+
130
+ @client.stub(:run, nil) do
131
+ @client.get_prep_instructions_for_asin('US', 'B00005N5PF', 'B0INVALIDF')
132
+ end
133
+
134
+ assert_equal operation, @client.operation
135
+ end
136
+
53
137
  def test_puts_transport_content_with_package_list
54
138
  transport_details = {
55
139
  parcel_data: {
@@ -168,6 +252,43 @@ class TestMWSFulfillmentInboundShipmentClient < MiniTest::Test
168
252
  assert_equal operation, @client.operation
169
253
  end
170
254
 
255
+ def test_gets_unique_package_labels
256
+ operation = {
257
+ 'Action' => 'GetUniquePackageLabels',
258
+ 'ShipmentId' => 'FBAQFGQZ',
259
+ 'PageType' => 'PackageLabel_Letter_6',
260
+ 'PackageLabelsToPrint.member.1' => 'CartonA',
261
+ 'PackageLabelsToPrint.member.2' => 'CartonB',
262
+ 'PackageLabelsToPrint.member.3' => 'CartonC',
263
+ 'PackageLabelsToPrint.member.4' => 'CartonD'
264
+ }
265
+
266
+ @client.stub(:run, nil) do
267
+ @client.get_unique_package_labels(
268
+ 'FBAQFGQZ',
269
+ 'PackageLabel_Letter_6',
270
+ %w(CartonA CartonB CartonC CartonD)
271
+ )
272
+ end
273
+
274
+ assert_equal operation, @client.operation
275
+ end
276
+
277
+ def test_gets_pallet_labels
278
+ operation = {
279
+ 'Action' => 'GetPalletLabels',
280
+ 'ShipmentId' => 'FBAQFGQZ',
281
+ 'PageType' => 'PackageLabel_Letter_4',
282
+ 'NumberOfPallets' => 4
283
+ }
284
+
285
+ @client.stub(:run, nil) do
286
+ @client.get_pallet_labels('FBAQFGQZ', 'PackageLabel_Letter_4', 4)
287
+ end
288
+
289
+ assert_equal operation, @client.operation
290
+ end
291
+
171
292
  def test_gets_bill_of_lading
172
293
  operation = {
173
294
  'Action' => 'GetBillOfLading',
@@ -141,7 +141,9 @@ class TestMWSProductsClient < MiniTest::Test
141
141
  'Action' => 'GetMyFeesEstimate',
142
142
  'FeesEstimateRequestList.FeesEstimateRequest.1.MarketplaceId' => '123',
143
143
  'FeesEstimateRequestList.FeesEstimateRequest.1.IdType' => 'ASIN',
144
- 'FeesEstimateRequestList.FeesEstimateRequest.1.IdValue' => '123',
144
+ 'FeesEstimateRequestList.FeesEstimateRequest.1.IdValue' => '1234567890',
145
+ 'FeesEstimateRequestList.FeesEstimateRequest.1.Identifier' => 'foo',
146
+ 'FeesEstimateRequestList.FeesEstimateRequest.1.IsAmazonFulfilled' => true,
145
147
  'FeesEstimateRequestList.FeesEstimateRequest.1.PriceToEstimateFees.ListingPrice.CurrencyCode' => 'USD',
146
148
  'FeesEstimateRequestList.FeesEstimateRequest.1.PriceToEstimateFees.ListingPrice.Amount' => 30.00,
147
149
  'FeesEstimateRequestList.FeesEstimateRequest.1.PriceToEstimateFees.Shipping.CurrencyCode' => 'USD',
@@ -153,7 +155,9 @@ class TestMWSProductsClient < MiniTest::Test
153
155
  @client.get_my_fees_estimate(
154
156
  marketplace_id: '123',
155
157
  id_type: 'ASIN',
156
- id_value: '123',
158
+ id_value: '1234567890',
159
+ identifier: 'foo',
160
+ is_amazon_fulfilled: true,
157
161
  price_to_estimate_fees: {
158
162
  listing_price: {
159
163
  currency_code: 'USD',
@@ -13,4 +13,10 @@ class TestPeddlerErrorsError < MiniTest::Test
13
13
  def test_sets_cause
14
14
  assert_equal 'cause', @error.cause
15
15
  end
16
+
17
+ def test_defines_common_errors
18
+ Peddler::Errors::KNOWN.each do |name|
19
+ assert ::Peddler::Errors.const_defined?(name)
20
+ end
21
+ end
16
22
  end
@@ -21,12 +21,23 @@ class TestPeddlerOperation < MiniTest::Test
21
21
  assert_equal 1, @operation['Foo.Status.Bar.1']
22
22
  end
23
23
 
24
- def test_store_camelizes_key
24
+ def test_store_camelizes_symbol_key
25
25
  @operation.store(:foo_bar, 'baz')
26
26
  assert @operation.key?('FooBar')
27
27
  refute @operation.key?(:foo_bar)
28
28
  end
29
29
 
30
+ def test_store_wont_camelize_string_key
31
+ @operation.store('foo_bar', 'baz')
32
+ assert @operation.key?('foo_bar')
33
+ refute @operation.key?('FooBar')
34
+ end
35
+
36
+ def test_store_wont_camelize_symbol_key_with_capital_letter
37
+ @operation.store('MarketplaceId'.to_sym, '1')
38
+ assert @operation.key?('MarketplaceId')
39
+ end
40
+
30
41
  def test_store_upcases_sku
31
42
  @operation.store(:seller_sku, 'baz')
32
43
  assert @operation.key?('SellerSKU')
@@ -2,32 +2,36 @@ require 'helper'
2
2
  require 'peddler/xml_response_parser'
3
3
 
4
4
  class TestPeddlerXMLResponseParser < MiniTest::Test
5
- def setup
6
- body = '<Response><Result><NextToken>123</NextToken>'\
7
- '<Foo>Bar</Foo></Result></Response>'
8
-
9
- @parser = Peddler::XMLResponseParser.new(response(body))
5
+ def test_parses_responses
6
+ body = '<Response><Result><Foo>Bar</Foo></Result></Response>'
7
+ parser = Peddler::XMLResponseParser.new(response(body))
8
+ assert_equal 'Bar', parser.parse['Foo']
10
9
  end
11
10
 
12
- def response(body)
13
- OpenStruct.new(
14
- body: body,
15
- headers: { 'Content-Type' => 'text/xml', 'Content-Length' => '78' }
16
- )
11
+ def test_parses_messages
12
+ body = '<Response><Message><Foo>Bar</Foo></Message></Response>'
13
+ parser = Peddler::XMLResponseParser.new(response(body))
14
+ assert_equal 'Bar', parser.parse['Foo']
17
15
  end
18
16
 
19
- def test_parses_data
20
- assert_equal 'Bar', @parser.parse['Foo']
17
+ def test_parses_reports
18
+ body = '<fooReports><fooReport><foo>Bar</foo></fooReport></fooReports>'
19
+ parser = Peddler::XMLResponseParser.new(response(body))
20
+ assert_equal 'Bar', parser.parse['foo']
21
21
  end
22
22
 
23
- def test_parses_message_data
24
- body_with_message = '<Response><Message><NextToken>123</NextToken>'\
25
- '<Foo>Bar</Foo></Message></Response>'
26
- parser = Peddler::XMLResponseParser.new(response(body_with_message))
27
- assert_equal 'Bar', parser.parse['Foo']
23
+ def test_parses_next_token
24
+ body = '<Response><Result><NextToken>123</NextToken></Result></Response>'
25
+ parser = Peddler::XMLResponseParser.new(response(body))
26
+ assert_equal '123', parser.next_token
28
27
  end
29
28
 
30
- def test_next_token
31
- assert_equal '123', @parser.next_token
29
+ private
30
+
31
+ def response(body)
32
+ OpenStruct.new(
33
+ body: body,
34
+ headers: { 'Content-Type' => 'text/xml', 'Content-Length' => '78' }
35
+ )
32
36
  end
33
37
  end