peddler 1.6.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +69 -67
  3. data/lib/mws/feeds/client.rb +15 -12
  4. data/lib/mws/finances/client.rb +12 -11
  5. data/lib/mws/fulfillment_inbound_shipment/client.rb +79 -107
  6. data/lib/mws/fulfillment_inventory/client.rb +5 -5
  7. data/lib/mws/fulfillment_outbound_shipment/client.rb +36 -44
  8. data/lib/mws/merchant_fulfillment/client.rb +11 -17
  9. data/lib/mws/off_amazon_payments/client.rb +38 -68
  10. data/lib/mws/orders/client.rb +28 -24
  11. data/lib/mws/products/client.rb +118 -153
  12. data/lib/mws/recommendations/client.rb +13 -17
  13. data/lib/mws/reports/client.rb +24 -23
  14. data/lib/mws/sellers/client.rb +5 -5
  15. data/lib/mws/subscriptions/client.rb +25 -36
  16. data/lib/peddler/client.rb +47 -124
  17. data/lib/peddler/errors/builder.rb +40 -14
  18. data/lib/peddler/errors/class_generator.rb +34 -0
  19. data/lib/peddler/errors/error.rb +13 -3
  20. data/lib/peddler/headers.rb +27 -11
  21. data/lib/peddler/marketplace.rb +30 -11
  22. data/lib/peddler/vcr_matcher.rb +11 -1
  23. data/lib/peddler/version.rb +1 -1
  24. data/lib/peddler/xml_parser.rb +4 -2
  25. data/lib/peddler/xml_response_parser.rb +1 -1
  26. data/test/helper.rb +0 -1
  27. data/test/integration/test_errors.rb +2 -14
  28. data/test/integration/test_feeds.rb +0 -3
  29. data/test/integration/test_multibyte_queries.rb +1 -1
  30. data/test/integration/test_mws_headers.rb +3 -2
  31. data/test/integration/test_orders.rb +2 -1
  32. data/test/integration/test_products.rb +9 -9
  33. data/test/integration/test_recommendations.rb +1 -1
  34. data/test/integration/test_subscriptions.rb +2 -2
  35. data/test/integration_helper.rb +1 -1
  36. data/test/mws.yml +36 -0
  37. data/test/mws.yml.example +8 -12
  38. data/test/null_client.rb +10 -8
  39. data/test/unit/mws/test_feeds_client.rb +1 -2
  40. data/test/unit/mws/test_fulfillment_outbound_shipment_client.rb +1 -1
  41. data/test/unit/mws/test_off_amazon_payments_client.rb +1 -1
  42. data/test/unit/mws/test_orders_client.rb +7 -6
  43. data/test/unit/mws/test_products_client.rb +13 -28
  44. data/test/unit/mws/test_recommendations_client.rb +1 -2
  45. data/test/unit/mws/test_reports_client.rb +1 -1
  46. data/test/unit/mws/test_subscriptions_client.rb +1 -130
  47. data/test/unit/peddler/errors/test_builder.rb +54 -7
  48. data/test/unit/peddler/errors/test_class_generator.rb +18 -0
  49. data/test/unit/peddler/errors/test_error.rb +7 -2
  50. data/test/unit/peddler/test_client.rb +136 -190
  51. data/test/unit/peddler/test_flat_file_parser.rb +2 -2
  52. data/test/unit/peddler/test_headers.rb +19 -9
  53. data/test/unit/peddler/test_marketplace.rb +18 -5
  54. data/test/unit/peddler/test_vcr_matcher.rb +3 -1
  55. data/test/vcr_cassettes/Feeds.yml +4816 -5224
  56. data/test/vcr_cassettes/Reports.yml +3278 -2604
  57. metadata +8 -9
  58. data/lib/peddler/errors.rb +0 -12
  59. data/lib/peddler/errors/handler.rb +0 -59
  60. data/test/unit/peddler/errors/test_handler.rb +0 -62
  61. data/test/unit/peddler/test_errors.rb +0 -26
@@ -9,18 +9,17 @@ module MWS
9
9
  # is an actionable, timely, and personalized opportunity to increase your
10
10
  # sales and performance.
11
11
  class Client < ::Peddler::Client
12
- version '2013-04-01'
13
- path "/Recommendations/#{version}"
12
+ self.version = '2013-04-01'
13
+ self.path = "/Recommendations/#{version}"
14
14
 
15
15
  # Checks whether there are active recommendations for each category for
16
16
  # the given marketplace, and if there are, returns the time when
17
17
  # recommendations were last updated for each category
18
18
  #
19
- # @see http://docs.developer.amazonservices.com/en_US/recommendations/Recommendations_GetLastUpdatedTimeForRecommendations.html
19
+ # @see https://docs.developer.amazonservices.com/en_US/recommendations/Recommendations_GetLastUpdatedTimeForRecommendations.html
20
20
  # @param [String] marketplace_id
21
21
  # @return [Peddler::XMLParser]
22
- def get_last_updated_time_for_recommendations(marketplace_id =
23
- primary_marketplace_id)
22
+ def get_last_updated_time_for_recommendations(marketplace_id)
24
23
  operation('GetLastUpdatedTimeForRecommendations')
25
24
  .add('MarketplaceId' => marketplace_id)
26
25
 
@@ -30,19 +29,16 @@ module MWS
30
29
  # Lists active recommendations for a specific category or for all
31
30
  # categories for a specific marketplace
32
31
  #
33
- # @see http://docs.developer.amazonservices.com/en_US/recommendations/Recommendations_ListRecommendations.html
34
- # @overload list_recommendations(opts = { marketplace_id:
35
- # primary_marketplace_id })
36
- # @param [Hash] opts
37
- # @option opts [String] :marketplace_id
38
- # @option opts [String] :recommendation_category
39
- # @option opts [Array<Struct, Hash>] :category_query_list
32
+ # @see https://docs.developer.amazonservices.com/en_US/recommendations/Recommendations_ListRecommendations.html
33
+ # @param [String] marketplace_id
34
+ # @param [Hash] opts
35
+ # @option opts [String] :recommendation_category
36
+ # @option opts [Array<Struct, Hash>] :category_query_list
40
37
  # @return [Peddler::XMLParser]
41
- def list_recommendations(opts = {})
42
- opts[:marketplace_id] ||= primary_marketplace_id
43
-
38
+ def list_recommendations(marketplace_id, opts = {})
44
39
  operation('ListRecommendations')
45
40
  .add(opts)
41
+ .add('MarketplaceId' => marketplace_id)
46
42
  .structure!(
47
43
  'CategoryQueryList', 'CategoryQuery', '1', 'FilterOptions',
48
44
  'FilterOption'
@@ -53,7 +49,7 @@ module MWS
53
49
 
54
50
  # Lists the next page of active recommendations
55
51
  #
56
- # @see http://docs.developer.amazonservices.com/en_US/recommendations/Recommendations_ListRecommendationsByNextToken.html
52
+ # @see https://docs.developer.amazonservices.com/en_US/recommendations/Recommendations_ListRecommendationsByNextToken.html
57
53
  # @param [String] next_token
58
54
  # @return [Peddler::XMLParser]
59
55
  def list_recommendations_by_next_token(next_token)
@@ -65,7 +61,7 @@ module MWS
65
61
 
66
62
  # Gets the service status of the API
67
63
  #
68
- # @see http://docs.developer.amazonservices.com/en_US/recommendations/Recommendations_GetServiceStatus.html
64
+ # @see https://docs.developer.amazonservices.com/en_US/recommendations/Recommendations_GetServiceStatus.html
69
65
  # @return [Peddler::XMLParser]
70
66
  def get_service_status
71
67
  operation('GetServiceStatus')
@@ -6,11 +6,12 @@ module MWS
6
6
  module Reports
7
7
  # The Reports API lets you request reports about your inventory and orders.
8
8
  class Client < ::Peddler::Client
9
- version '2009-01-01'
9
+ self.version = '2009-01-01'
10
+ self.path = "/Reports/#{version}"
10
11
 
11
12
  # Creates a report request
12
13
  #
13
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_RequestReport.html
14
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_RequestReport.html
14
15
  # @param [String] report_type
15
16
  # @param [Hash] opts
16
17
  # @option opts [String, #iso8601] :start_date
@@ -20,7 +21,8 @@ module MWS
20
21
  # @return [Peddler::XMLParser]
21
22
  def request_report(report_type, opts = {})
22
23
  operation('RequestReport')
23
- .add(opts.update('ReportType' => report_type))
24
+ .add(opts)
25
+ .add('ReportType' => report_type)
24
26
  .structure!('MarketplaceIdList', 'Id')
25
27
 
26
28
  run
@@ -28,7 +30,7 @@ module MWS
28
30
 
29
31
  # Lists report requests
30
32
  #
31
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportRequestList.html
33
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportRequestList.html
32
34
  # @param [Hash] opts
33
35
  # @option opts [Array<String>, String] :report_request_id_list
34
36
  # @option opts [Array<String>, String] :report_type_list
@@ -49,7 +51,7 @@ module MWS
49
51
 
50
52
  # Lists the next page of the report requests
51
53
  #
52
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportRequestListByNextToken.html
54
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportRequestListByNextToken.html
53
55
  # @param [String] next_token
54
56
  # @return [Peddler::XMLParser]
55
57
  def get_report_request_list_by_next_token(next_token)
@@ -61,7 +63,7 @@ module MWS
61
63
 
62
64
  # Counts requested reports
63
65
  #
64
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportRequestCount.html
66
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportRequestCount.html
65
67
  # @param [Hash] opts
66
68
  # @option opts [Array<String>, String] :report_type_list
67
69
  # @option opts [Array<String>, String] :report_processing_status_list
@@ -79,7 +81,7 @@ module MWS
79
81
 
80
82
  # Cancels one or more report requests
81
83
  #
82
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_CancelReportRequests.html
84
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_CancelReportRequests.html
83
85
  # @param [Hash] opts
84
86
  # @option opts [Array<String>, String] :report_type_list
85
87
  # @option opts [Array<String>, String] :report_processing_status_list
@@ -97,7 +99,7 @@ module MWS
97
99
 
98
100
  # Lists reports
99
101
  #
100
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportList.html
102
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportList.html
101
103
  # @param [Hash] opts
102
104
  # @option opts [Integer] :max_count
103
105
  # @option opts [Array<String>, String] :report_type_list
@@ -117,7 +119,7 @@ module MWS
117
119
 
118
120
  # Lists the next page of reports
119
121
  #
120
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportListByNextToken.html
122
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportListByNextToken.html
121
123
  # @param [String] next_token
122
124
  # @return [Peddler::XMLParser]
123
125
  def get_report_list_by_next_token(next_token)
@@ -129,7 +131,7 @@ module MWS
129
131
 
130
132
  # Counts reports
131
133
  #
132
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportCount.html
134
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportCount.html
133
135
  # @param [Hash] opts
134
136
  # @option opts [Array<String>, String] :report_type_list
135
137
  # @option opts [Boolean] :acknowledged
@@ -146,7 +148,7 @@ module MWS
146
148
 
147
149
  # Gets a report and its Content-MD5 header
148
150
  #
149
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReport.html
151
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_GetReport.html
150
152
  # @param [String] report_id
151
153
  # @return [Peddler::XMLParser] if report is in XML format
152
154
  # @return [Peddler::FlatFileParser] if report is a flat file
@@ -159,7 +161,7 @@ module MWS
159
161
 
160
162
  # Creates, updates, or deletes a report request schedule
161
163
  #
162
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_ManageReportSchedule.html
164
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_ManageReportSchedule.html
163
165
  # @param [String] report_type
164
166
  # @param [String] schedule
165
167
  # @param [Hash] opts
@@ -167,15 +169,16 @@ module MWS
167
169
  # @return [Peddler::XMLParser]
168
170
  def manage_report_schedule(report_type, schedule, opts = {})
169
171
  operation('ManageReportSchedule')
170
- .add(opts.update('ReportType' => report_type, 'Schedule' => schedule))
172
+ .add(opts)
173
+ .add('ReportType' => report_type, 'Schedule' => schedule)
171
174
 
172
175
  run
173
176
  end
174
177
 
175
178
  # Lists scheduled reports
176
179
  #
177
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportScheduleList.html
178
- # @param [*Array<String>] report_type_list
180
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportScheduleList.html
181
+ # @param [Array<String>] report_type_list
179
182
  # @return [Peddler::XMLParser]
180
183
  def get_report_schedule_list(*report_type_list)
181
184
  operation('GetReportScheduleList')
@@ -187,7 +190,7 @@ module MWS
187
190
 
188
191
  # Lists next page of scheduled reports
189
192
  #
190
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportScheduleListByNextToken.html
193
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportScheduleListByNextToken.html
191
194
  # @raise [NotImplementedError]
192
195
  def get_report_schedule_list_by_next_token(*)
193
196
  raise NotImplementedError
@@ -195,9 +198,8 @@ module MWS
195
198
 
196
199
  # Counts scheduled reports
197
200
  #
198
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportScheduleCount.html
199
- # @overload get_report_schedule_count(*report_types)
200
- # @param [String] report_type one or more report_types
201
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportScheduleCount.html
202
+ # @param [Array<String>] report_type_list
201
203
  # @return [Peddler::XMLParser]
202
204
  def get_report_schedule_count(*report_type_list)
203
205
  operation('GetReportScheduleCount')
@@ -209,10 +211,9 @@ module MWS
209
211
 
210
212
  # Updates acknowledged status of one or more reports
211
213
  #
212
- # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_UpdateReportAcknowledgements.html
213
- # @overload update_report_acknowledgements(acknowledged, *report_ids)
214
- # @param [Boolean] acknowledged
215
- # @param [String] report_id one or more report_ids
214
+ # @see https://docs.developer.amazonservices.com/en_US/reports/Reports_UpdateReportAcknowledgements.html
215
+ # @param [Boolean] acknowledged
216
+ # @param [Array<String>] report_id_list
216
217
  # @return [Peddler::XMLParser]
217
218
  def update_report_acknowledgements(acknowledged, *report_id_list)
218
219
  operation('UpdateReportAcknowledgements')
@@ -7,12 +7,12 @@ module MWS
7
7
  # The Sellers API lets sellers retrieve information about their seller
8
8
  # account, such as the marketplaces they participate in.
9
9
  class Client < ::Peddler::Client
10
- version '2011-07-01'
11
- path "/Sellers/#{version}"
10
+ self.version = '2011-07-01'
11
+ self.path = "/Sellers/#{version}"
12
12
 
13
13
  # Lists the marketplaces the seller participates in
14
14
  #
15
- # @see http://docs.developer.amazonservices.com/en_US/sellers/Sellers_ListMarketplaceParticipations.html
15
+ # @see https://docs.developer.amazonservices.com/en_US/sellers/Sellers_ListMarketplaceParticipations.html
16
16
  # @return [Peddler::XMLParser]
17
17
  def list_marketplace_participations
18
18
  operation('ListMarketplaceParticipations')
@@ -21,7 +21,7 @@ module MWS
21
21
 
22
22
  # Lists the next page of marketplaces the seller participates in
23
23
  #
24
- # @see http://docs.developer.amazonservices.com/en_US/sellers/Sellers_ListMarketplaceParticipationsByNextToken.html
24
+ # @see https://docs.developer.amazonservices.com/en_US/sellers/Sellers_ListMarketplaceParticipationsByNextToken.html
25
25
  # @param [String] next_token
26
26
  # @return [Peddler::XMLParser]
27
27
  def list_marketplace_participations_by_next_token(next_token)
@@ -33,7 +33,7 @@ module MWS
33
33
 
34
34
  # Gets the service status of the API
35
35
  #
36
- # @see http://docs.developer.amazonservices.com/en_US/sellers/Sellers_GetServiceStatus.html
36
+ # @see https://docs.developer.amazonservices.com/en_US/sellers/Sellers_GetServiceStatus.html
37
37
  # @return [Peddler::XMLParser]
38
38
  def get_service_status
39
39
  operation('GetServiceStatus')
@@ -11,17 +11,16 @@ module MWS
11
11
  # Amazon MWS service. Instead, the information is sent directly to you when
12
12
  # an event occurs to which you are subscribed.
13
13
  class Client < ::Peddler::Client
14
- version '2013-07-01'
15
- path "/Subscriptions/#{version}"
14
+ self.version = '2013-07-01'
15
+ self.path = "/Subscriptions/#{version}"
16
16
 
17
17
  # Registers a new destination to receive notifications
18
18
  #
19
- # @see http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_RegisterDestination.html
19
+ # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_RegisterDestination.html
20
20
  # @param [String] sqs_queue_url
21
21
  # @param [String] marketplace_id
22
22
  # @return [Peddler::XMLParser]
23
- def register_destination(sqs_queue_url,
24
- marketplace_id = primary_marketplace_id)
23
+ def register_destination(sqs_queue_url, marketplace_id)
25
24
  operation('RegisterDestination')
26
25
  .add('MarketplaceId' => marketplace_id)
27
26
  .add(build_destination(sqs_queue_url))
@@ -31,12 +30,11 @@ module MWS
31
30
 
32
31
  # Removes an existing destination from the list of registered destinations
33
32
  #
34
- # @see http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_DeregisterDestination.html
33
+ # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_DeregisterDestination.html
35
34
  # @param [String] sqs_queue_url
36
35
  # @param [String] marketplace_id
37
36
  # @return [Peddler::XMLParser]
38
- def deregister_destination(sqs_queue_url,
39
- marketplace_id = primary_marketplace_id)
37
+ def deregister_destination(sqs_queue_url, marketplace_id)
40
38
  operation('DeregisterDestination')
41
39
  .add('MarketplaceId' => marketplace_id)
42
40
  .add(build_destination(sqs_queue_url))
@@ -46,10 +44,10 @@ module MWS
46
44
 
47
45
  # Lists all registered destinations
48
46
  #
49
- # @see http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_ListRegisteredDestinations.html
47
+ # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_ListRegisteredDestinations.html
50
48
  # @param [String] marketplace_id
51
49
  # @return [Peddler::XMLParser]
52
- def list_registered_destinations(marketplace_id = primary_marketplace_id)
50
+ def list_registered_destinations(marketplace_id)
53
51
  operation('ListRegisteredDestinations')
54
52
  .add('MarketplaceId' => marketplace_id)
55
53
 
@@ -58,13 +56,11 @@ module MWS
58
56
 
59
57
  # Sends a test notification to an existing destination
60
58
  #
61
- # @see http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_SendTestNotificationToDestination.html
59
+ # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_SendTestNotificationToDestination.html
62
60
  # @param [String] sqs_queue_url
63
61
  # @param [String] marketplace_id
64
62
  # @return [Peddler::XMLParser]
65
- def send_test_notification_to_destination(sqs_queue_url,
66
- marketplace_id =
67
- primary_marketplace_id)
63
+ def send_test_notification_to_destination(sqs_queue_url, marketplace_id)
68
64
  operation('SendTestNotificationToDestination')
69
65
  .add('MarketplaceId' => marketplace_id)
70
66
  .add(build_destination(sqs_queue_url))
@@ -74,13 +70,12 @@ module MWS
74
70
 
75
71
  # Creates a new subscription
76
72
  #
77
- # @see http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_CreateSubscription.html
73
+ # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_CreateSubscription.html
78
74
  # @param [String] notification_type
79
75
  # @param [String] sqs_queue_url
80
76
  # @param [String] marketplace_id
81
77
  # @return [Peddler::XMLParser]
82
- def create_subscription(notification_type, sqs_queue_url,
83
- marketplace_id = primary_marketplace_id)
78
+ def create_subscription(notification_type, sqs_queue_url, marketplace_id)
84
79
  operation('CreateSubscription')
85
80
  .add('MarketplaceId' => marketplace_id)
86
81
  .add(build_subscription(notification_type, sqs_queue_url))
@@ -90,18 +85,15 @@ module MWS
90
85
 
91
86
  # Gets a subscription
92
87
  #
93
- # @see http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_GetSubscription.html
88
+ # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_GetSubscription.html
94
89
  # @param [String] notification_type
95
90
  # @param [String] sqs_queue_url
96
91
  # @param [String] marketplace_id
97
92
  # @return [Peddler::XMLParser]
98
- def get_subscription(notification_type, sqs_queue_url,
99
- marketplace_id = primary_marketplace_id)
93
+ def get_subscription(notification_type, sqs_queue_url, marketplace_id)
100
94
  operation('GetSubscription')
101
- .add(
102
- 'MarketplaceId' => marketplace_id,
103
- 'NotificationType' => notification_type
104
- )
95
+ .add('MarketplaceId' => marketplace_id,
96
+ 'NotificationType' => notification_type)
105
97
  .add(build_destination(sqs_queue_url))
106
98
 
107
99
  run
@@ -109,18 +101,15 @@ module MWS
109
101
 
110
102
  # Deletes a subscription
111
103
  #
112
- # @see http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_DeleteSubscription.html
104
+ # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_DeleteSubscription.html
113
105
  # @param [String] notification_type
114
106
  # @param [String] sqs_queue_url
115
107
  # @param [String] marketplace_id
116
108
  # @return [Peddler::XMLParser]
117
- def delete_subscription(notification_type, sqs_queue_url,
118
- marketplace_id = primary_marketplace_id)
109
+ def delete_subscription(notification_type, sqs_queue_url, marketplace_id)
119
110
  operation('DeleteSubscription')
120
- .add(
121
- 'MarketplaceId' => marketplace_id,
122
- 'NotificationType' => notification_type
123
- )
111
+ .add('MarketplaceId' => marketplace_id,
112
+ 'NotificationType' => notification_type)
124
113
  .add(build_destination(sqs_queue_url))
125
114
 
126
115
  run
@@ -128,10 +117,10 @@ module MWS
128
117
 
129
118
  # Lists current subscriptions
130
119
  #
131
- # @see http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_ListSubscriptions.html
120
+ # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_ListSubscriptions.html
132
121
  # @param [String] marketplace_id
133
122
  # @return [Peddler::XMLParser]
134
- def list_subscriptions(marketplace_id = primary_marketplace_id)
123
+ def list_subscriptions(marketplace_id)
135
124
  operation('ListSubscriptions')
136
125
  .add('MarketplaceId' => marketplace_id)
137
126
 
@@ -140,14 +129,14 @@ module MWS
140
129
 
141
130
  # Updates a subscription
142
131
  #
143
- # @see http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_UpdateSubscription.html
132
+ # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_UpdateSubscription.html
144
133
  # @param [String] notification_type
145
134
  # @param [String] sqs_queue_url
146
135
  # @param [Boolean] enabled
147
136
  # @param [String] marketplace_id
148
137
  # @return [Peddler::XMLParser]
149
138
  def update_subscription(notification_type, sqs_queue_url, enabled,
150
- marketplace_id = primary_marketplace_id)
139
+ marketplace_id)
151
140
  operation('UpdateSubscription')
152
141
  .add('MarketplaceId' => marketplace_id)
153
142
  .add(build_subscription(notification_type, sqs_queue_url, enabled))
@@ -157,7 +146,7 @@ module MWS
157
146
 
158
147
  # Gets the service status of the API
159
148
  #
160
- # @see http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_GetServiceStatus.html
149
+ # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_GetServiceStatus.html
161
150
  # @return [Peddler::XMLParser]
162
151
  def get_service_status
163
152
  operation('GetServiceStatus')
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'forwardable'
4
4
  require 'jeff'
5
- require 'peddler/errors/parser'
5
+ require 'peddler/errors/builder'
6
6
  require 'peddler/marketplace'
7
7
  require 'peddler/operation'
8
8
  require 'peddler/parser'
@@ -10,130 +10,84 @@ require 'peddler/parser'
10
10
  module Peddler
11
11
  # An abstract client
12
12
  #
13
- # Subclass to implement an MWS API section.
13
+ # Subclass this to implement an MWS API section.
14
14
  class Client
15
15
  extend Forwardable
16
16
  include Jeff
17
17
 
18
- # The MWSAuthToken used to access another seller's account
19
- # @return [String]
20
- attr_accessor :auth_token
21
-
22
- attr_writer :merchant_id, :primary_marketplace_id, :path
23
-
24
- # @api private
25
- attr_writer :version
26
-
27
- # The body of the HTTP request
28
- # @return [String]
29
- attr_reader :body
30
-
31
- alias configure tap
32
-
33
- def_delegators :marketplace, :host, :encoding
34
-
35
- params(
36
- 'SellerId' => -> { merchant_id },
37
- 'MWSAuthToken' => -> { auth_token },
38
- 'Version' => -> { version }
39
- )
40
-
41
18
  class << self
42
19
  # @api private
43
- attr_accessor :error_handler, :parser
44
-
45
- # @api private
46
- def path(path = nil)
47
- path ? @path = path : @path ||= '/'
48
- end
49
-
50
- # @api private
51
- def version(version = nil)
52
- version ? @version = version : @version ||= nil
53
- end
54
-
55
- # Sets an error handler
56
- # @yieldparam [Excon::Error] error
57
- def on_error(&blk)
58
- @error_handler = blk
59
- end
20
+ attr_accessor :parser, :path, :version
60
21
 
61
22
  private
62
23
 
63
24
  def inherited(base)
64
25
  base.parser = parser
65
- base.error_handler = error_handler
66
- base.path(path)
67
- base.params(params)
26
+ base.params params
68
27
  end
69
28
  end
70
29
 
71
- self.error_handler = proc { raise }
30
+ params 'SellerId' => -> { merchant_id },
31
+ 'MWSAuthToken' => -> { auth_token },
32
+ 'Version' => -> { version }
72
33
  self.parser = Parser
73
34
 
74
- # Creates a new client instance
75
- #
35
+ def_delegators :marketplace, :host, :encoding
36
+ def_delegators :'self.class', :parser, :version
37
+
38
+ # Creates a new client
76
39
  # @param [Hash] opts
77
- # @option opts [String] :primary_marketplace_id
78
- # @option opts [String] :merchant_id
79
40
  # @option opts [String] :aws_access_key_id
80
41
  # @option opts [String] :aws_secret_access_key
42
+ # @option opts [String, Peddler::Marketplace] :marketplace
43
+ # @option opts [String] :merchant_id
81
44
  # @option opts [String] :auth_token
82
45
  def initialize(opts = {})
83
46
  opts.each { |k, v| send("#{k}=", v) }
84
47
  end
85
48
 
86
- # @api private
87
- def aws_endpoint
88
- "https://#{host}#{path}"
89
- end
49
+ # The MWS Auth Token for a seller's account
50
+ # @note You can omit this if you are accessing your own seller account
51
+ # @return [String]
52
+ attr_accessor :auth_token
90
53
 
91
- # The merchant's Marketplace ID
92
- # @!parse attr_reader :primary_marketplace_id
54
+ # The seller's Merchant ID
93
55
  # @return [String]
94
- def primary_marketplace_id
95
- @primary_marketplace_id ||= ENV['MWS_MARKETPLACE_ID']
96
- end
56
+ attr_accessor :merchant_id
97
57
 
98
- # @deprecated Use {#primary_marketplace_id}.
99
- def marketplace_id
100
- @primary_marketplace_id
101
- end
58
+ # The marketplace where you signed up as application developer
59
+ # @note You can pass the two-letter country code of the marketplace as
60
+ # shorthand when setting
61
+ # @return [Peddler::Marketplace]
62
+ attr_reader :marketplace
102
63
 
103
- # @deprecated Use {#primary_marketplace_id=}.
104
- def marketplace_id=(marketplace_id)
105
- @primary_marketplace_id = marketplace_id
64
+ # @!parse attr_writer :marketplace
65
+ def marketplace=(marketplace)
66
+ @marketplace =
67
+ if marketplace.is_a?(Marketplace)
68
+ marketplace
69
+ else
70
+ Marketplace.find(marketplace)
71
+ end
106
72
  end
107
73
 
108
- # The merchant's Seller ID
109
- # @!parse attr_reader :merchant_id
74
+ # The body of the HTTP request
110
75
  # @return [String]
111
- def merchant_id
112
- @merchant_id ||= ENV['MWS_MERCHANT_ID']
76
+ attr_reader :body
77
+
78
+ # @!parse attr_writer :body
79
+ def body=(str)
80
+ str ? add_content(str) : clear_content!
113
81
  end
114
82
 
115
83
  # @api private
116
- def marketplace
117
- @marketplace ||= find_marketplace
118
- end
84
+ attr_writer :path
119
85
 
120
- # The HTTP path of the API
121
- # @!parse attr_reader :path
122
- # @return [String]
86
+ # @api private
123
87
  def path
124
88
  @path ||= self.class.path
125
89
  end
126
90
 
127
- # @api private
128
- def version
129
- @version ||= self.class.version
130
- end
131
-
132
- # @!parse attr_writer :body
133
- def body=(str)
134
- str ? add_content(str) : clear_content!
135
- end
136
-
137
91
  # @api private
138
92
  def defaults
139
93
  @defaults ||= { expects: 200 }
@@ -144,15 +98,9 @@ module Peddler
144
98
  @headers ||= {}
145
99
  end
146
100
 
147
- # Sets an error handler
148
- # @yieldparam [Excon::Error] error
149
- def on_error(&blk)
150
- @error_handler = blk
151
- end
152
-
153
101
  # @api private
154
- def error_handler
155
- (@error_handler ||= nil) || self.class.error_handler
102
+ def aws_endpoint
103
+ "https://#{host}#{path}"
156
104
  end
157
105
 
158
106
  # @api private
@@ -168,16 +116,12 @@ module Peddler
168
116
  self.body = nil if res.status == 200
169
117
 
170
118
  parser.new(res, encoding)
171
- rescue Excon::Error => e
172
- handle_error(e)
119
+ rescue ::Excon::Error::HTTPStatus => error
120
+ handle_http_status_error(error)
173
121
  end
174
122
 
175
123
  private
176
124
 
177
- def find_marketplace
178
- Marketplace.find(primary_marketplace_id)
179
- end
180
-
181
125
  def clear_content!
182
126
  headers.delete('Content-Type')
183
127
  @body = nil
@@ -198,35 +142,14 @@ module Peddler
198
142
  args.last.is_a?(Hash) ? args.pop : {}
199
143
  end
200
144
 
201
- def parser
202
- self.class.parser
203
- end
204
-
205
145
  def build_options
206
146
  opts = defaults.merge(query: operation, headers: headers)
207
147
  body ? opts.update(body: body) : opts
208
148
  end
209
149
 
210
- def handle_error(e)
211
- e = decorate_error(e)
212
- error_handler.call(*deprecate_error_handler_arguments(e))
213
- end
214
-
215
- def decorate_error(e)
216
- if e.is_a?(:: Excon::Error::HTTPStatus)
217
- e.instance_variable_set(:@response, Errors::Parser.new(e.response))
218
- end
219
-
220
- e
221
- end
222
-
223
- def deprecate_error_handler_arguments(e)
224
- if error_handler.parameters.size == 2
225
- warn '[DEPRECATION] Error handler now expects exception as argument.'
226
- [e.request, e.response]
227
- else
228
- [e]
229
- end
150
+ def handle_http_status_error(error)
151
+ new_error = Errors::Builder.call(error)
152
+ raise new_error || error
230
153
  end
231
154
  end
232
155
  end