peddler 2.4.5 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +402 -140
  3. data/lib/peddler/api/amazon_warehousing_and_distribution_2024_05_09.rb +92 -0
  4. data/lib/peddler/api/aplus_content_2020_11_01.rb +246 -0
  5. data/lib/peddler/api/application_integrations_2024_04_01.rb +56 -0
  6. data/lib/peddler/api/application_management_2023_11_30.rb +35 -0
  7. data/lib/peddler/api/catalog_items_2020_12_01.rb +81 -0
  8. data/lib/peddler/api/catalog_items_2022_04_01.rb +93 -0
  9. data/lib/peddler/api/catalog_items_v0.rb +103 -0
  10. data/lib/peddler/api/data_kiosk_2023_11_15.rb +108 -0
  11. data/lib/peddler/api/easy_ship_2022_03_23.rb +127 -0
  12. data/lib/peddler/api/fba_inbound_eligibility_v1.rb +44 -0
  13. data/lib/peddler/api/fba_inventory_v1.rb +122 -0
  14. data/lib/peddler/api/feeds_2021_06_30.rb +122 -0
  15. data/lib/peddler/api/finances_2024_06_19.rb +50 -0
  16. data/lib/peddler/api/finances_v0.rb +148 -0
  17. data/lib/peddler/api/fulfillment_inbound_2024_03_20.rb +759 -0
  18. data/lib/peddler/api/fulfillment_inbound_v0.rb +352 -0
  19. data/lib/peddler/api/fulfillment_outbound_2020_07_01.rb +259 -0
  20. data/lib/peddler/api/invoices_2024_06_19.rb +180 -0
  21. data/lib/peddler/api/listings_items_2020_09_01.rb +95 -0
  22. data/lib/peddler/api/listings_items_2021_08_01.rb +170 -0
  23. data/lib/peddler/api/listings_restrictions_2021_08_01.rb +47 -0
  24. data/lib/peddler/api/merchant_fulfillment_v0.rb +80 -0
  25. data/lib/peddler/api/messaging_v1.rb +273 -0
  26. data/lib/peddler/api/notifications_v1.rb +145 -0
  27. data/lib/peddler/api/orders_v0.rb +279 -0
  28. data/lib/peddler/api/product_fees_v0.rb +77 -0
  29. data/lib/peddler/api/product_pricing_2022_05_01.rb +54 -0
  30. data/lib/peddler/api/product_pricing_v0.rb +162 -0
  31. data/lib/peddler/api/product_type_definitions_2020_09_01.rb +86 -0
  32. data/lib/peddler/api/replenishment_2022_11_07.rb +57 -0
  33. data/lib/peddler/api/reports_2021_06_30.rb +163 -0
  34. data/lib/peddler/api/sales_v1.rb +77 -0
  35. data/lib/peddler/api/sellers_v1.rb +45 -0
  36. data/lib/peddler/api/services_v1.rb +348 -0
  37. data/lib/peddler/api/shipment_invoicing_v0.rb +59 -0
  38. data/lib/peddler/api/shipping_v1.rb +132 -0
  39. data/lib/peddler/api/shipping_v2.rb +319 -0
  40. data/lib/peddler/api/solicitations_v1.rb +63 -0
  41. data/lib/peddler/api/supply_sources_2020_07_01.rb +100 -0
  42. data/lib/peddler/api/tokens_2021_03_01.rb +38 -0
  43. data/lib/peddler/api/uploads_2020_11_01.rb +50 -0
  44. data/lib/peddler/api/vendor_direct_fulfillment_inventory_v1.rb +32 -0
  45. data/lib/peddler/api/vendor_direct_fulfillment_orders_2021_12_28.rb +84 -0
  46. data/lib/peddler/api/vendor_direct_fulfillment_orders_v1.rb +84 -0
  47. data/lib/peddler/api/vendor_direct_fulfillment_payments_v1.rb +31 -0
  48. data/lib/peddler/api/vendor_direct_fulfillment_sandbox_test_data_2021_10_28.rb +45 -0
  49. data/lib/peddler/api/vendor_direct_fulfillment_shipping_2021_12_28.rb +203 -0
  50. data/lib/peddler/api/vendor_direct_fulfillment_shipping_v1.rb +189 -0
  51. data/lib/peddler/api/vendor_direct_fulfillment_transactions_2021_12_28.rb +32 -0
  52. data/lib/peddler/api/vendor_direct_fulfillment_transactions_v1.rb +32 -0
  53. data/lib/peddler/api/vendor_invoices_v1.rb +30 -0
  54. data/lib/peddler/api/vendor_orders_v1.rb +159 -0
  55. data/lib/peddler/api/vendor_shipments_v1.rb +132 -0
  56. data/lib/peddler/api/vendor_transaction_status_v1.rb +33 -0
  57. data/lib/peddler/api.rb +138 -0
  58. data/lib/peddler/endpoint.rb +51 -0
  59. data/lib/peddler/error.rb +31 -0
  60. data/lib/peddler/marketplace.rb +38 -68
  61. data/lib/peddler/token.rb +70 -0
  62. data/lib/peddler/version.rb +1 -1
  63. data/lib/peddler.rb +56 -1
  64. metadata +74 -80
  65. data/lib/mws/easy_ship/client.rb +0 -93
  66. data/lib/mws/easy_ship.rb +0 -3
  67. data/lib/mws/feeds/client.rb +0 -122
  68. data/lib/mws/feeds.rb +0 -3
  69. data/lib/mws/finances/client.rb +0 -82
  70. data/lib/mws/finances.rb +0 -3
  71. data/lib/mws/fulfillment_inbound_shipment/client.rb +0 -388
  72. data/lib/mws/fulfillment_inbound_shipment.rb +0 -3
  73. data/lib/mws/fulfillment_inventory/client.rb +0 -57
  74. data/lib/mws/fulfillment_inventory.rb +0 -3
  75. data/lib/mws/fulfillment_outbound_shipment/client.rb +0 -211
  76. data/lib/mws/fulfillment_outbound_shipment.rb +0 -3
  77. data/lib/mws/merchant_fulfillment/client.rb +0 -87
  78. data/lib/mws/merchant_fulfillment.rb +0 -3
  79. data/lib/mws/off_amazon_payments.rb +0 -3
  80. data/lib/mws/orders/client.rb +0 -120
  81. data/lib/mws/orders.rb +0 -3
  82. data/lib/mws/products/client.rb +0 -268
  83. data/lib/mws/products.rb +0 -3
  84. data/lib/mws/recommendations/client.rb +0 -72
  85. data/lib/mws/recommendations.rb +0 -3
  86. data/lib/mws/reports/client.rb +0 -236
  87. data/lib/mws/reports.rb +0 -3
  88. data/lib/mws/sellers/client.rb +0 -44
  89. data/lib/mws/sellers.rb +0 -3
  90. data/lib/mws/shipment_invoicing/client.rb +0 -74
  91. data/lib/mws/shipment_invoicing.rb +0 -3
  92. data/lib/mws/subscriptions/client.rb +0 -179
  93. data/lib/mws/subscriptions.rb +0 -3
  94. data/lib/mws.rb +0 -29
  95. data/lib/peddler/client.rb +0 -159
  96. data/lib/peddler/errors/builder.rb +0 -64
  97. data/lib/peddler/errors/class_generator.rb +0 -40
  98. data/lib/peddler/errors/error.rb +0 -45
  99. data/lib/peddler/errors/parser.rb +0 -28
  100. data/lib/peddler/flat_file_parser.rb +0 -56
  101. data/lib/peddler/headers.rb +0 -102
  102. data/lib/peddler/operation.rb +0 -78
  103. data/lib/peddler/parser.rb +0 -33
  104. data/lib/peddler/structured_list.rb +0 -23
  105. data/lib/peddler/vcr_matcher.rb +0 -97
  106. data/lib/peddler/xml_parser.rb +0 -38
  107. data/lib/peddler/xml_response_parser.rb +0 -25
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'peddler/client'
4
-
5
- module MWS
6
- module ShipmentInvoicing
7
- # With the Shipment Invoicing API section, you can integrate invoicing into
8
- # Amazon's shipping process for a seller's FBA order.
9
- #
10
- # @note This functionality is available only in the Brazil marketplace.
11
- class Client < ::Peddler::Client
12
- self.version = '2018-09-01'
13
- self.path = "/ShipmentInvoicing/#{version}"
14
-
15
- # Returns the information required to generate an invoice for the shipment
16
- # of a Fulfillment by Amazon order
17
- #
18
- # @see https://docs.developer.amazonservices.com/en_US/shipment_invoicing/ShipmentInvoicing_GetFBAOutboundShipmentDetail.html
19
- # @param [String] marketplace_id
20
- # @param [String] amazon_shipment_id
21
- # @return [Peddler::XMLParser]
22
- def get_fba_outbound_shipment_detail(marketplace_id, amazon_shipment_id)
23
- operation('GetFBAOutboundShipmentDetail')
24
- .add('MarketplaceId' => marketplace_id,
25
- 'AmazonShipmentId' => amazon_shipment_id)
26
-
27
- run
28
- end
29
-
30
- # Submits shipment invoice data for a given shipment
31
- #
32
- # @see https://docs.developer.amazonservices.com/en_US/shipment_invoicing/ShipmentInvoicing_SubmitFBAOutboundShipmentInvoice.html
33
- # @param [String] marketplace_id
34
- # @param [String] amazon_shipment_id
35
- # @param [String] invoice_content
36
- # @return [Peddler::XMLParser]
37
- def submit_fba_outbound_shipment_invoice(marketplace_id,
38
- amazon_shipment_id,
39
- invoice_content)
40
- self.body = invoice_content
41
-
42
- operation('SubmitFBAOutboundShipmentInvoice')
43
- .add('MarketplaceId' => marketplace_id,
44
- 'AmazonShipmentId' => amazon_shipment_id)
45
-
46
- run
47
- end
48
-
49
- # Gets the invoice processing status for the shipments that you specify
50
- #
51
- # @see https://docs.developer.amazonservices.com/en_US/shipment_invoicing/ShipmentInvoicing_GetFBAOutboundShipmentInvoiceStatus.html
52
- # @param [String] marketplace_id
53
- # @param [String] amazon_shipment_id
54
- # @return [Peddler::XMLParser]
55
- def get_fba_outbound_shipment_invoice_status(marketplace_id,
56
- amazon_shipment_id)
57
- operation('GetFBAOutboundShipmentInvoiceStatus')
58
- .add('MarketplaceId' => marketplace_id,
59
- 'AmazonShipmentId' => amazon_shipment_id)
60
-
61
- run
62
- end
63
-
64
- # Gets the operational status of the API
65
- #
66
- # @see https://docs.developer.amazonservices.com/en_US/shipment_invoicing/ShipmentInvoicing_GetServiceStatus.html
67
- # @return [Peddler::XMLParser]
68
- def get_service_status
69
- operation('GetServiceStatus')
70
- run
71
- end
72
- end
73
- end
74
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mws/shipment_invoicing/client'
@@ -1,179 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'peddler/client'
4
-
5
- module MWS
6
- module Subscriptions
7
- # The Amazon MWS Subscriptions API section enables you to subscribe to
8
- # receive notifications that are relevant to your business with Amazon. With
9
- # the operations in the Subscriptions API section, you can register to
10
- # receive important information from Amazon without having to poll the
11
- # Amazon MWS service. Instead, the information is sent directly to you when
12
- # an event occurs to which you are subscribed.
13
- class Client < ::Peddler::Client
14
- self.version = '2013-07-01'
15
- self.path = "/Subscriptions/#{version}"
16
-
17
- # Registers a new destination to receive notifications
18
- #
19
- # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_RegisterDestination.html
20
- # @param [String] sqs_queue_url
21
- # @param [String] marketplace_id
22
- # @return [Peddler::XMLParser]
23
- def register_destination(sqs_queue_url, marketplace_id)
24
- operation('RegisterDestination')
25
- .add('MarketplaceId' => marketplace_id)
26
- .add(build_destination(sqs_queue_url))
27
-
28
- run
29
- end
30
-
31
- # Removes an existing destination from the list of registered destinations
32
- #
33
- # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_DeregisterDestination.html
34
- # @param [String] sqs_queue_url
35
- # @param [String] marketplace_id
36
- # @return [Peddler::XMLParser]
37
- def deregister_destination(sqs_queue_url, marketplace_id)
38
- operation('DeregisterDestination')
39
- .add('MarketplaceId' => marketplace_id)
40
- .add(build_destination(sqs_queue_url))
41
-
42
- run
43
- end
44
-
45
- # Lists all registered destinations
46
- #
47
- # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_ListRegisteredDestinations.html
48
- # @param [String] marketplace_id
49
- # @return [Peddler::XMLParser]
50
- def list_registered_destinations(marketplace_id)
51
- operation('ListRegisteredDestinations')
52
- .add('MarketplaceId' => marketplace_id)
53
-
54
- run
55
- end
56
-
57
- # Sends a test notification to an existing destination
58
- #
59
- # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_SendTestNotificationToDestination.html
60
- # @param [String] sqs_queue_url
61
- # @param [String] marketplace_id
62
- # @return [Peddler::XMLParser]
63
- def send_test_notification_to_destination(sqs_queue_url, marketplace_id)
64
- operation('SendTestNotificationToDestination')
65
- .add('MarketplaceId' => marketplace_id)
66
- .add(build_destination(sqs_queue_url))
67
-
68
- run
69
- end
70
-
71
- # Creates a new subscription
72
- #
73
- # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_CreateSubscription.html
74
- # @param [String] notification_type
75
- # @param [String] sqs_queue_url
76
- # @param [String] marketplace_id
77
- # @return [Peddler::XMLParser]
78
- def create_subscription(notification_type, sqs_queue_url, marketplace_id)
79
- operation('CreateSubscription')
80
- .add('MarketplaceId' => marketplace_id)
81
- .add(build_subscription(notification_type, sqs_queue_url))
82
-
83
- run
84
- end
85
-
86
- # Gets a subscription
87
- #
88
- # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_GetSubscription.html
89
- # @param [String] notification_type
90
- # @param [String] sqs_queue_url
91
- # @param [String] marketplace_id
92
- # @return [Peddler::XMLParser]
93
- def get_subscription(notification_type, sqs_queue_url, marketplace_id)
94
- operation('GetSubscription')
95
- .add('MarketplaceId' => marketplace_id,
96
- 'NotificationType' => notification_type)
97
- .add(build_destination(sqs_queue_url))
98
-
99
- run
100
- end
101
-
102
- # Deletes a subscription
103
- #
104
- # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_DeleteSubscription.html
105
- # @param [String] notification_type
106
- # @param [String] sqs_queue_url
107
- # @param [String] marketplace_id
108
- # @return [Peddler::XMLParser]
109
- def delete_subscription(notification_type, sqs_queue_url, marketplace_id)
110
- operation('DeleteSubscription')
111
- .add('MarketplaceId' => marketplace_id,
112
- 'NotificationType' => notification_type)
113
- .add(build_destination(sqs_queue_url))
114
-
115
- run
116
- end
117
-
118
- # Lists current subscriptions
119
- #
120
- # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_ListSubscriptions.html
121
- # @param [String] marketplace_id
122
- # @return [Peddler::XMLParser]
123
- def list_subscriptions(marketplace_id)
124
- operation('ListSubscriptions')
125
- .add('MarketplaceId' => marketplace_id)
126
-
127
- run
128
- end
129
-
130
- # Updates a subscription
131
- #
132
- # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_UpdateSubscription.html
133
- # @param [String] notification_type
134
- # @param [String] sqs_queue_url
135
- # @param [Boolean] enabled
136
- # @param [String] marketplace_id
137
- # @return [Peddler::XMLParser]
138
- def update_subscription(notification_type, sqs_queue_url, enabled,
139
- marketplace_id)
140
- operation('UpdateSubscription')
141
- .add('MarketplaceId' => marketplace_id)
142
- .add(build_subscription(notification_type, sqs_queue_url, enabled: enabled))
143
-
144
- run
145
- end
146
-
147
- # Gets the service status of the API
148
- #
149
- # @see https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_GetServiceStatus.html
150
- # @return [Peddler::XMLParser]
151
- def get_service_status
152
- operation('GetServiceStatus')
153
- run
154
- end
155
-
156
- private
157
-
158
- def build_destination(sqs_queue_url)
159
- {
160
- 'Destination.DeliveryChannel' => 'SQS',
161
- 'Destination.AttributeList.member.1.Key' => 'sqsQueueUrl',
162
- 'Destination.AttributeList.member.1.Value' => sqs_queue_url
163
- }
164
- end
165
-
166
- def build_subscription(notification_type, sqs_queue_url, enabled: true)
167
- {
168
- 'Subscription.IsEnabled' => enabled,
169
- 'Subscription.NotificationType' => notification_type,
170
- 'Subscription.Destination.DeliveryChannel' => 'SQS',
171
- 'Subscription.Destination.AttributeList.member.1.Key' =>
172
- 'sqsQueueUrl',
173
- 'Subscription.Destination.AttributeList.member.1.Value' =>
174
- sqs_queue_url
175
- }
176
- end
177
- end
178
- end
179
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mws/subscriptions/client'
data/lib/mws.rb DELETED
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
- require 'mws/easy_ship'
5
- require 'mws/feeds'
6
- require 'mws/finances'
7
- require 'mws/fulfillment_inbound_shipment'
8
- require 'mws/fulfillment_inventory'
9
- require 'mws/fulfillment_outbound_shipment'
10
- require 'mws/merchant_fulfillment'
11
- require 'mws/orders'
12
- require 'mws/products'
13
- require 'mws/recommendations'
14
- require 'mws/reports'
15
- require 'mws/sellers'
16
- require 'mws/shipment_invoicing'
17
- require 'mws/subscriptions'
18
-
19
- # The various Amazon MWS API sections.
20
- module MWS
21
- class << self
22
- extend Forwardable
23
-
24
- MWS.constants.each do |klass|
25
- method_name = klass.to_s.gsub(/(.)([A-Z])/, '\1_\2').downcase
26
- def_delegator MWS.const_get(klass).const_get(:Client), :new, method_name
27
- end
28
- end
29
- end
@@ -1,159 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
- require 'jeff'
5
- require 'peddler/errors/builder'
6
- require 'peddler/marketplace'
7
- require 'peddler/operation'
8
- require 'peddler/parser'
9
-
10
- module Peddler
11
- # An abstract client
12
- #
13
- # Subclass this to implement an MWS API section.
14
- class Client
15
- extend Forwardable
16
- include Jeff
17
-
18
- class << self
19
- # @!visibility private
20
- attr_accessor :parser, :path, :version
21
-
22
- private
23
-
24
- def inherited(base)
25
- super
26
- base.parser = parser
27
- base.params params
28
- end
29
- end
30
-
31
- params 'SellerId' => -> { merchant_id },
32
- 'MWSAuthToken' => -> { auth_token },
33
- 'Version' => -> { version }
34
- self.parser = Parser
35
-
36
- def_delegators :marketplace, :host, :encoding
37
- def_delegators :'self.class', :parser, :version
38
-
39
- # Creates a new client
40
- # @param [Hash] opts
41
- # @option opts [String] :aws_access_key_id
42
- # @option opts [String] :aws_secret_access_key
43
- # @option opts [String, Peddler::Marketplace] :marketplace
44
- # @option opts [String] :merchant_id
45
- # @option opts [String] :auth_token
46
- def initialize(opts = {})
47
- opts.each { |k, v| send("#{k}=", v) }
48
- end
49
-
50
- # The MWS Auth Token for a seller's account
51
- # @note You can omit this if you are accessing your own seller account
52
- # @return [String]
53
- attr_accessor :auth_token
54
-
55
- # The seller's Merchant ID
56
- # @note Amazon also refers to this as Seller ID or Merchant Token
57
- # @return [String]
58
- attr_accessor :merchant_id
59
-
60
- # The marketplace where you signed up as application developer
61
- # @note You can pass the two-letter country code of the marketplace as
62
- # shorthand when setting
63
- # @return [Peddler::Marketplace]
64
- attr_reader :marketplace
65
-
66
- # @!parse attr_writer :marketplace
67
- def marketplace=(marketplace)
68
- @marketplace =
69
- if marketplace.is_a?(Marketplace)
70
- marketplace
71
- else
72
- Marketplace.find(marketplace)
73
- end
74
- end
75
-
76
- # The body of the HTTP request
77
- # @return [String]
78
- attr_reader :body
79
-
80
- # @!parse attr_writer :body
81
- def body=(str)
82
- str ? add_content(str) : clear_content!
83
- end
84
-
85
- # @!visibility private
86
- attr_writer :path
87
-
88
- # @!visibility private
89
- def path
90
- @path ||= self.class.path
91
- end
92
-
93
- # @!visibility private
94
- def defaults
95
- @defaults ||= { expects: 200 }
96
- end
97
-
98
- # @!visibility private
99
- def headers
100
- @headers ||= {}
101
- end
102
-
103
- # @!visibility private
104
- def aws_endpoint
105
- "https://#{host}#{path}"
106
- end
107
-
108
- # @!visibility private
109
- def operation(action = nil)
110
- action ? @operation = Operation.new(action) : @operation
111
- end
112
-
113
- # @!visibility private
114
- def run(&block)
115
- opts = build_options
116
- opts.store(:response_block, block) if block
117
- res = post(opts)
118
- self.body = nil if res.status == 200
119
-
120
- parser.new(res, encoding)
121
- rescue ::Excon::Error::HTTPStatus => e
122
- handle_http_status_error(e)
123
- end
124
-
125
- private
126
-
127
- def clear_content!
128
- headers.delete('Content-Type')
129
- @body = nil
130
- end
131
-
132
- def add_content(content)
133
- @body = content
134
- if content.encoding.names.include?('BINARY')
135
- headers['Content-Type'] = 'application/octet-stream'
136
- elsif content.start_with?('<?xml')
137
- headers['Content-Type'] = 'text/xml'
138
- else
139
- headers['Content-Type'] =
140
- "text/tab-separated-values; charset=#{encoding}"
141
- @body = @body.encode(encoding)
142
- end
143
- end
144
-
145
- def extract_options(args)
146
- args.last.is_a?(Hash) ? args.pop : {}
147
- end
148
-
149
- def build_options
150
- opts = defaults.merge(query: operation, headers: headers)
151
- body ? opts.update(body: body) : opts
152
- end
153
-
154
- def handle_http_status_error(error)
155
- new_error = Errors::Builder.call(error)
156
- raise new_error || error
157
- end
158
- end
159
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'excon'
4
- require 'forwardable'
5
- require 'peddler/errors/class_generator'
6
- require 'peddler/errors/parser'
7
-
8
- module Peddler
9
- module Errors
10
- # @!visibility private
11
- class Builder
12
- extend Forwardable
13
-
14
- DIGIT_AS_FIRST_CHAR = /^\d/.freeze
15
- private_constant :DIGIT_AS_FIRST_CHAR
16
-
17
- def_delegator :error, :response
18
-
19
- def self.call(error)
20
- new(error).build
21
- end
22
-
23
- attr_reader :error
24
-
25
- def initialize(error)
26
- @error = error
27
- end
28
-
29
- def build
30
- parse_original_response
31
- return if no_error_response?
32
- return if bad_class_name?
33
-
34
- error_class.new(error_message, error)
35
- end
36
-
37
- private
38
-
39
- def bad_class_name?
40
- error_name.match?(DIGIT_AS_FIRST_CHAR)
41
- end
42
-
43
- def no_error_response?
44
- response.parse.nil?
45
- end
46
-
47
- def error_class
48
- ClassGenerator.call(error_name)
49
- end
50
-
51
- def error_name
52
- response.code
53
- end
54
-
55
- def error_message
56
- response.message
57
- end
58
-
59
- def parse_original_response
60
- error.instance_variable_set :@response, Parser.new(error.response)
61
- end
62
- end
63
- end
64
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'singleton'
4
- require 'peddler/errors/error'
5
-
6
- module Peddler
7
- module Errors
8
- # @!visibility private
9
- class ClassGenerator
10
- include Singleton
11
-
12
- def self.call(name)
13
- instance.generate(name)
14
- end
15
-
16
- def initialize
17
- @mutex = Mutex.new
18
- end
19
-
20
- def generate(name)
21
- with_mutex do
22
- if Errors.const_defined?(name)
23
- error = Errors.const_get(name)
24
- return error if error <= Error
25
-
26
- raise TypeError, "#{name} must be a Peddler::Errors::Error"
27
- end
28
-
29
- Errors.const_set(name, Class.new(Error))
30
- end
31
- end
32
-
33
- private
34
-
35
- def with_mutex(&block)
36
- @mutex.synchronize(&block)
37
- end
38
- end
39
- end
40
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
-
5
- module Peddler
6
- # @!visibility private
7
- module Errors
8
- # These error codes are common to all Amazon MWS API sections.
9
- #
10
- # @see https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Errors.html
11
- #
12
- # There are quite a few other error types they do not explicitly document
13
- # above. I decided not to define any for the sake of consistency and future
14
- # maintenance.
15
- CODES = %w[
16
- AccessDenied
17
- InputStreamDisconnected
18
- InternalError
19
- InvalidAccessKeyId
20
- InvalidAddress
21
- InvalidParameterValue
22
- QuotaExceeded
23
- RequestThrottled
24
- SignatureDoesNotMatch
25
- ].freeze
26
-
27
- # @!visibility private
28
- class Error < StandardError
29
- extend Forwardable
30
-
31
- attr_reader :cause
32
-
33
- def initialize(msg = nil, cause = nil)
34
- @cause = cause
35
- super msg
36
- end
37
-
38
- def_delegator :cause, :response
39
- end
40
-
41
- CODES.each do |name|
42
- const_set name, Class.new(Error)
43
- end
44
- end
45
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'peddler/xml_parser'
4
-
5
- module Peddler
6
- module Errors
7
- # @!visibility private
8
- class Parser < XMLParser
9
- def message
10
- parse['Message']
11
- end
12
-
13
- def type
14
- parse['Type']
15
- end
16
-
17
- def code
18
- parse['Code']
19
- end
20
-
21
- private
22
-
23
- def find_data
24
- xml.dig('ErrorResponse', 'Error')
25
- end
26
- end
27
- end
28
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'delegate'
4
- require 'csv'
5
- require 'digest/md5'
6
- require 'peddler/headers'
7
-
8
- module Peddler
9
- # @!visibility private
10
- class FlatFileParser < SimpleDelegator
11
- include Headers
12
-
13
- # http://stackoverflow.com/questions/8073920/importing-csv-quoting-error-is-driving-me-nuts
14
- OPTIONS = { col_sep: "\t", quote_char: "\x00", headers: true }.freeze
15
- private_constant :OPTIONS
16
-
17
- attr_reader :content, :summary
18
-
19
- def initialize(res, encoding)
20
- super(res)
21
- scrub_body!(encoding)
22
- extract_content_and_summary
23
- end
24
-
25
- def parse(&blk)
26
- CSV.parse(content, **OPTIONS, &blk) unless content.empty?
27
- end
28
-
29
- def records_count
30
- summarize if summary
31
- end
32
-
33
- def valid?
34
- headers['Content-MD5'] == Digest::MD5.base64digest(body)
35
- end
36
-
37
- private
38
-
39
- def scrub_body!(encoding)
40
- return if body.encoding == Encoding::UTF_8
41
-
42
- self.body = body.dup.force_encoding(content_charset || encoding)
43
- end
44
-
45
- def extract_content_and_summary
46
- @content = body.encode('UTF-8', invalid: :replace, undef: :replace)
47
- return unless @content.match?(/\t\t.*\n\n/)
48
-
49
- @summary, @content = @content.split("\n\n", 2)
50
- end
51
-
52
- def summarize
53
- summary.split("\n\t")[1, 2].map { |line| line.split("\t\t") }.to_h
54
- end
55
- end
56
- end