peddler 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +62 -81
- data/lib/mws/cart_information.rb +13 -0
- data/lib/mws/customer_information.rb +16 -0
- data/lib/mws/feeds.rb +110 -1
- data/lib/mws/fulfillment_inbound_shipment.rb +13 -1
- data/lib/mws/fulfillment_inventory.rb +15 -1
- data/lib/mws/fulfillment_outbound_shipment.rb +17 -1
- data/lib/mws/off_amazon_payments.rb +15 -1
- data/lib/mws/orders.rb +100 -1
- data/lib/mws/products.rb +238 -1
- data/lib/mws/recommendations.rb +13 -1
- data/lib/mws/reports.rb +221 -1
- data/lib/mws/sellers.rb +40 -1
- data/lib/mws/subscriptions.rb +175 -1
- data/lib/peddler/client.rb +77 -37
- data/lib/peddler/csv_parser.rb +42 -0
- data/lib/peddler/operation.rb +44 -0
- data/lib/peddler/parser.rb +21 -0
- data/lib/peddler/structured_list.rb +22 -0
- data/lib/peddler/version.rb +1 -1
- data/lib/peddler/xml_parser.rb +25 -0
- data/lib/peddler.rb +2 -0
- data/test/helper.rb +1 -1
- data/test/integration/test_feeds.rb +18 -0
- data/test/integration/test_orders.rb +22 -0
- data/test/integration/test_products.rb +53 -0
- data/test/integration/test_reports.rb +47 -0
- data/test/integration/test_sellers.rb +18 -0
- data/test/integration/test_subscriptions.rb +26 -0
- data/test/integration_helper.rb +41 -8
- data/test/mws.yml +32 -0
- data/test/mws.yml.example +4 -0
- data/test/unit/peddler/test_client.rb +97 -0
- data/test/unit/peddler/test_csv_parser.rb +24 -0
- data/test/unit/peddler/test_operation.rb +34 -0
- data/test/{peddler/request → unit/peddler}/test_structured_list.rb +5 -5
- data/test/unit/peddler/test_xml_parser.rb +19 -0
- data/test/{test_peddler.rb → unit/test_peddler.rb} +2 -2
- data/test/vcr_cassettes/Feeds.yml +695 -0
- data/test/vcr_cassettes/Orders.yml +29855 -0
- data/test/vcr_cassettes/Products.yml +8597 -0
- data/test/vcr_cassettes/Reports.yml +1881 -0
- data/test/vcr_cassettes/Sellers.yml +697 -0
- data/test/vcr_cassettes/Subscriptions.yml +1369 -0
- metadata +91 -297
- data/lib/mws/feeds/client.rb +0 -116
- data/lib/mws/feeds/parsers/feed.rb +0 -14
- data/lib/mws/feeds/parsers/feed_submission_count.rb +0 -10
- data/lib/mws/feeds/parsers/feed_submission_info.rb +0 -25
- data/lib/mws/feeds/parsers/feed_submission_list.rb +0 -23
- data/lib/mws/feeds/parsers/feed_submission_result.rb +0 -10
- data/lib/mws/feeds/parsers/feed_submissions.rb +0 -18
- data/lib/mws/feeds/requests/feed.rb +0 -38
- data/lib/mws/feeds/requests/feed_submission_count.rb +0 -20
- data/lib/mws/feeds/requests/feed_submission_list.rb +0 -30
- data/lib/mws/feeds/requests/feed_submission_result.rb +0 -18
- data/lib/mws/feeds/requests/feed_submissions.rb +0 -20
- data/lib/mws/fulfillment_inbound_shipment/client.rb +0 -7
- data/lib/mws/fulfillment_inventory/client.rb +0 -7
- data/lib/mws/fulfillment_outbound_shipment/client.rb +0 -7
- data/lib/mws/off_amazon_payments/client.rb +0 -7
- data/lib/mws/orders/client.rb +0 -98
- data/lib/mws/orders/parsers/invoice_data.rb +0 -25
- data/lib/mws/orders/parsers/order.rb +0 -113
- data/lib/mws/orders/parsers/order_item.rb +0 -110
- data/lib/mws/orders/parsers/order_items.rb +0 -23
- data/lib/mws/orders/parsers/orders.rb +0 -23
- data/lib/mws/orders/parsers/payment_execution_detail.rb +0 -20
- data/lib/mws/orders/parsers/payment_execution_detail_item.rb +0 -17
- data/lib/mws/orders/parsers/service_status.rb +0 -36
- data/lib/mws/orders/parsers/service_status_message.rb +0 -17
- data/lib/mws/orders/parsers/shipping_address.rb +0 -37
- data/lib/mws/orders/requests/order_items.rb +0 -28
- data/lib/mws/orders/requests/orders.rb +0 -41
- data/lib/mws/orders/requests/service_status.rb +0 -15
- data/lib/mws/products/client.rb +0 -7
- data/lib/mws/recommendations/client.rb +0 -7
- data/lib/mws/reports/client.rb +0 -249
- data/lib/mws/reports/parsers/report.rb +0 -10
- data/lib/mws/reports/parsers/report_acknowledgements.rb +0 -20
- data/lib/mws/reports/parsers/report_count.rb +0 -10
- data/lib/mws/reports/parsers/report_info.rb +0 -29
- data/lib/mws/reports/parsers/report_list.rb +0 -23
- data/lib/mws/reports/parsers/report_request.rb +0 -14
- data/lib/mws/reports/parsers/report_request_count.rb +0 -10
- data/lib/mws/reports/parsers/report_request_info.rb +0 -49
- data/lib/mws/reports/parsers/report_request_list.rb +0 -23
- data/lib/mws/reports/parsers/report_requests.rb +0 -18
- data/lib/mws/reports/parsers/report_schedule.rb +0 -21
- data/lib/mws/reports/parsers/report_schedule_count.rb +0 -10
- data/lib/mws/reports/parsers/report_schedule_list.rb +0 -23
- data/lib/mws/reports/parsers/report_scheduler.rb +0 -19
- data/lib/mws/reports/requests/report.rb +0 -18
- data/lib/mws/reports/requests/report_acknowledgements.rb +0 -27
- data/lib/mws/reports/requests/report_count.rb +0 -20
- data/lib/mws/reports/requests/report_list.rb +0 -30
- data/lib/mws/reports/requests/report_request.rb +0 -21
- data/lib/mws/reports/requests/report_request_count.rb +0 -20
- data/lib/mws/reports/requests/report_request_list.rb +0 -30
- data/lib/mws/reports/requests/report_requests.rb +0 -20
- data/lib/mws/reports/requests/report_schedule_count.rb +0 -19
- data/lib/mws/reports/requests/report_schedule_list.rb +0 -23
- data/lib/mws/reports/requests/report_scheduler.rb +0 -29
- data/lib/mws/sellers/client.rb +0 -53
- data/lib/mws/sellers/parsers/marketplace.rb +0 -33
- data/lib/mws/sellers/parsers/marketplace_participations.rb +0 -32
- data/lib/mws/sellers/parsers/participation.rb +0 -21
- data/lib/mws/sellers/parsers/service_status.rb +0 -36
- data/lib/mws/sellers/parsers/service_status_message.rb +0 -17
- data/lib/mws/sellers/requests/marketplace_participations.rb +0 -27
- data/lib/mws/sellers/requests/service_status.rb +0 -15
- data/lib/mws/subscriptions/client.rb +0 -7
- data/lib/peddler/parsers/base.rb +0 -15
- data/lib/peddler/parsers/collection.rb +0 -23
- data/lib/peddler/parsers/counter.rb +0 -13
- data/lib/peddler/parsers/model.rb +0 -42
- data/lib/peddler/parsers/text.rb +0 -8
- data/lib/peddler/parsers/tokenable.rb +0 -13
- data/lib/peddler/parsers/xml.rb +0 -30
- data/lib/peddler/request/parameters.rb +0 -57
- data/lib/peddler/request/structured_list.rb +0 -48
- data/lib/peddler/request.rb +0 -52
- data/lib/peddler/response/base.rb +0 -0
- data/lib/peddler/response/payload/base.rb +0 -0
- data/lib/peddler/response/payload/csv.rb +0 -0
- data/lib/peddler/response/payload/xml.rb +0 -0
- data/lib/peddler/response.rb +0 -27
- data/test/fixtures/feeds/feed_submission.xml +0 -14
- data/test/fixtures/feeds/feed_submission_count.xml +0 -9
- data/test/fixtures/feeds/feed_submission_list.xml +0 -17
- data/test/fixtures/feeds/feed_submissions.xml +0 -15
- data/test/fixtures/mws.yml +0 -12
- data/test/fixtures/mws.yml.example +0 -4
- data/test/fixtures/orders/order_items.xml +0 -83
- data/test/fixtures/orders/orders.xml +0 -109
- data/test/fixtures/orders/service_status.xml +0 -19
- data/test/fixtures/reports/report.xml +0 -8
- data/test/fixtures/reports/report_acknowledgements.xml +0 -18
- data/test/fixtures/reports/report_count.xml +0 -9
- data/test/fixtures/reports/report_list.xml +0 -17
- data/test/fixtures/reports/report_request_count.xml +0 -9
- data/test/fixtures/reports/report_request_list.xml +0 -24
- data/test/fixtures/reports/report_requests.xml +0 -19
- data/test/fixtures/reports/report_schedule_count.xml +0 -10
- data/test/fixtures/reports/report_schedule_list.xml +0 -16
- data/test/fixtures/reports/report_scheduler.xml +0 -15
- data/test/fixtures/sellers/market_participations.xml +0 -27
- data/test/fixtures/sellers/service_status.xml +0 -9
- data/test/integration/feeds/test_feed_submission_count.rb +0 -13
- data/test/integration/feeds/test_feed_submission_list.rb +0 -17
- data/test/integration/feeds/test_feed_submission_result.rb +0 -15
- data/test/integration/orders/test_order_items.rb +0 -19
- data/test/integration/orders/test_orders.rb +0 -23
- data/test/integration/orders/test_service_status.rb +0 -12
- data/test/integration/reports/test_report.rb +0 -15
- data/test/integration/reports/test_report_count.rb +0 -13
- data/test/integration/reports/test_report_list.rb +0 -17
- data/test/integration/reports/test_report_request_count.rb +0 -13
- data/test/integration/reports/test_report_request_list.rb +0 -17
- data/test/integration/reports/test_report_schedule_count.rb +0 -13
- data/test/integration/reports/test_report_schedule_list.rb +0 -13
- data/test/integration/reports/test_report_scheduler.rb +0 -16
- data/test/integration/sellers/test_marketplace_participations.rb +0 -13
- data/test/integration/sellers/test_service_status.rb +0 -12
- data/test/mws/feeds/parsers/test_feed.rb +0 -13
- data/test/mws/feeds/parsers/test_feed_submission_count.rb +0 -13
- data/test/mws/feeds/parsers/test_feed_submission_info.rb +0 -25
- data/test/mws/feeds/parsers/test_feed_submission_list.rb +0 -18
- data/test/mws/feeds/parsers/test_feed_submission_result.rb +0 -13
- data/test/mws/feeds/parsers/test_feed_submissions.rb +0 -17
- data/test/mws/feeds/requests/test_feed.rb +0 -63
- data/test/mws/feeds/requests/test_feed_submission_count.rb +0 -23
- data/test/mws/feeds/requests/test_feed_submission_list.rb +0 -37
- data/test/mws/feeds/requests/test_feed_submissions.rb +0 -29
- data/test/mws/orders/parsers/test_order.rb +0 -86
- data/test/mws/orders/parsers/test_order_item.rb +0 -69
- data/test/mws/orders/parsers/test_order_items.rb +0 -18
- data/test/mws/orders/parsers/test_orders.rb +0 -18
- data/test/mws/orders/parsers/test_payment_execution_detail.rb +0 -14
- data/test/mws/orders/parsers/test_payment_execution_detail_item.rb +0 -17
- data/test/mws/orders/parsers/test_service_status.rb +0 -39
- data/test/mws/orders/parsers/test_service_status_message.rb +0 -17
- data/test/mws/orders/parsers/test_shipping_address.rb +0 -36
- data/test/mws/orders/requests/test_order_items.rb +0 -36
- data/test/mws/orders/requests/test_orders.rb +0 -46
- data/test/mws/orders/requests/test_service_status.rb +0 -25
- data/test/mws/reports/parsers/test_report_acknowledgments.rb +0 -14
- data/test/mws/reports/parsers/test_report_count.rb +0 -13
- data/test/mws/reports/parsers/test_report_info.rb +0 -29
- data/test/mws/reports/parsers/test_report_list.rb +0 -18
- data/test/mws/reports/parsers/test_report_request.rb +0 -13
- data/test/mws/reports/parsers/test_report_request_count.rb +0 -13
- data/test/mws/reports/parsers/test_report_request_info.rb +0 -49
- data/test/mws/reports/parsers/test_report_request_list.rb +0 -18
- data/test/mws/reports/parsers/test_report_requests.rb +0 -17
- data/test/mws/reports/parsers/test_report_schedule_count.rb +0 -13
- data/test/mws/reports/parsers/test_report_schedule_list.rb +0 -18
- data/test/mws/reports/parsers/test_report_scheduler.rb +0 -17
- data/test/mws/reports/requests/test_acknowledgements.rb +0 -36
- data/test/mws/reports/requests/test_report_count.rb +0 -23
- data/test/mws/reports/requests/test_report_list.rb +0 -39
- data/test/mws/reports/requests/test_report_request.rb +0 -31
- data/test/mws/reports/requests/test_report_request_count.rb +0 -23
- data/test/mws/reports/requests/test_report_request_list.rb +0 -44
- data/test/mws/reports/requests/test_report_requests.rb +0 -29
- data/test/mws/reports/requests/test_report_schedule_count.rb +0 -22
- data/test/mws/reports/requests/test_report_schedule_list.rb +0 -36
- data/test/mws/reports/requests/test_report_scheduler.rb +0 -33
- data/test/mws/sellers/parsers/test_market_participations.rb +0 -19
- data/test/mws/sellers/parsers/test_service_status.rb +0 -35
- data/test/mws/sellers/requests/test_marketplace_participation_list.rb +0 -39
- data/test/mws/sellers/requests/test_service_status.rb +0 -25
- data/test/parser_helper.rb +0 -11
- data/test/peddler/parsers/test_collection.rb +0 -8
- data/test/peddler/parsers/test_model.rb +0 -70
- data/test/peddler/request/test_parameters.rb +0 -35
- data/test/peddler/test_client.rb +0 -42
- data/test/request_helper.rb +0 -20
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'excon'
|
3
|
+
require 'peddler/client'
|
4
|
+
|
5
|
+
class ClientTest < MiniTest::Test
|
6
|
+
module Parser
|
7
|
+
def self.parse(res); res; end
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@body = 'foo'
|
12
|
+
Excon.defaults[:mock] = true
|
13
|
+
Excon.stub({}, body: @body, status: 200)
|
14
|
+
|
15
|
+
@klass = Class.new(Peddler::Client)
|
16
|
+
@client = @klass.new
|
17
|
+
@client.marketplace_id = 'A1F83G8C2ARO7P'
|
18
|
+
@client.operation('Foo')
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
Excon.stubs.clear
|
23
|
+
Excon.defaults.delete(:mock)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_configures_path
|
27
|
+
@klass.path('Foo')
|
28
|
+
assert @client.aws_endpoint.match(/Foo$/)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_has_user_agent
|
32
|
+
assert @client.connection.data[:headers].has_key?('User-Agent')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_inherits_parents_params
|
36
|
+
assert_equal Peddler::Client.params, @klass.params
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_configures
|
40
|
+
@client.configure do |config|
|
41
|
+
config.aws_access_key_id = '123'
|
42
|
+
end
|
43
|
+
|
44
|
+
assert_equal '123', @client.aws_access_key_id
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_guards_against_bad_marketplace_id
|
48
|
+
assert_raises(Peddler::Client::BadMarketplaceId) do
|
49
|
+
client = Peddler::Client.new
|
50
|
+
client.marketplace_id = '123'
|
51
|
+
client.get
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_sets_content_type_header_for_latin_flat_file_body
|
56
|
+
@client.body = 'foo'
|
57
|
+
content_type = @client.headers.fetch('Content-Type')
|
58
|
+
|
59
|
+
assert_equal 'text/tab-separated-values; charset=ISO-8859-1', content_type
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_sets_content_type_header_for_chinese_flat_file_body
|
63
|
+
@client.marketplace_id = 'AAHKV2X7AFYLW'
|
64
|
+
@client.body = 'foo'
|
65
|
+
content_type = @client.headers.fetch('Content-Type')
|
66
|
+
|
67
|
+
assert_equal 'text/tab-separated-values; charset=UTF-16', content_type
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_sets_content_type_header_for_japanese_flat_file_body
|
71
|
+
@client.marketplace_id = 'A1VC38T7YXB528'
|
72
|
+
@client.body = 'foo'
|
73
|
+
content_type = @client.headers.fetch('Content-Type')
|
74
|
+
|
75
|
+
assert_equal 'text/tab-separated-values; charset=Shift_JIS', content_type
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_sets_content_type_header_for_xml_body
|
79
|
+
@client.body = '<?xml version="1.0"?><Foo></Foo>'
|
80
|
+
content_type = @client.headers.fetch('Content-Type')
|
81
|
+
|
82
|
+
assert_equal 'text/xml', content_type
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_runs_a_request
|
86
|
+
res = @client.run(Parser)
|
87
|
+
assert_equal @body, res.body
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_streams_response
|
91
|
+
chunks = ''
|
92
|
+
streamer = -> (chunk, _, _) { chunks << chunk }
|
93
|
+
@client.run(Parser, &streamer)
|
94
|
+
|
95
|
+
assert_equal @body, chunks
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'peddler/parser'
|
3
|
+
|
4
|
+
class CSVParserTest < MiniTest::Test
|
5
|
+
def setup
|
6
|
+
body = "Feed Processing Summary:\n\tNumber of records processed\t\t11006\n\tNumber of records successful\t\t11006\n\noriginal-record-number\tsku\terror-code\terror-type\terror-message\n1822\t85da472e-ba6c-11e3-95af-002590a74356\t5000\tWarning\tThe update for Sku '85da472e-ba6c-11e3-95af-002590a74356' was skipped because it is identical to the update in feed '9518995390'.\n"
|
7
|
+
headers = { 'Content-Type' => 'application/octet-stream', 'Content-MD5' => 'SmZIMTs2mCO8u8QzR5LE7Q==' }
|
8
|
+
res = OpenStruct.new(body: body, headers: headers)
|
9
|
+
|
10
|
+
@parser = Peddler::Parser.parse(res)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_parses_data
|
14
|
+
assert_kind_of CSV::Table, @parser.parse
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_summarises
|
18
|
+
refute_empty @parser.records_count
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_validates
|
22
|
+
assert @parser.valid?
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'peddler/operation'
|
3
|
+
|
4
|
+
class OperationTest < MiniTest::Test
|
5
|
+
def setup
|
6
|
+
@operation = Peddler::Operation.new('Foo')
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_converts_key_to_structured_list
|
10
|
+
@operation.store('FooStatus', [1, 2])
|
11
|
+
@operation.structure!('FooStatus', 'Foo')
|
12
|
+
refute @operation.has_key?('FooStatus')
|
13
|
+
assert_equal 1, @operation['FooStatus.Foo.1']
|
14
|
+
assert_equal 2, @operation['FooStatus.Foo.2']
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_store_camelizes_key
|
18
|
+
@operation.store(:foo_bar, 'baz')
|
19
|
+
assert @operation.has_key?('FooBar')
|
20
|
+
refute @operation.has_key?(:foo_bar)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_store_timestamps_time_values
|
24
|
+
ts = Minitest::Mock.new
|
25
|
+
ts.expect(:iso8601, 'foo')
|
26
|
+
@operation.store('time', ts)
|
27
|
+
|
28
|
+
assert_equal 'foo', @operation.fetch('time')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_update_returns_delegator
|
32
|
+
assert_kind_of Peddler::Operation, @operation.add(foo: 'bar')
|
33
|
+
end
|
34
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'helper'
|
2
|
-
require 'peddler/
|
2
|
+
require 'peddler/structured_list'
|
3
3
|
|
4
|
-
class
|
4
|
+
class StructuredListTest < MiniTest::Test
|
5
5
|
def setup
|
6
|
-
@
|
6
|
+
@list = Peddler::StructuredList.new('OrderStatus', 'Status')
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_builds_a_structured_list_for_a_single_value
|
10
10
|
exp = { 'OrderStatus.Status.1' => 'foo' }
|
11
|
-
assert_equal
|
11
|
+
assert_equal exp, @list.build('foo')
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_builds_a_structured_list_for_an_array_of_values
|
15
15
|
exp = { 'OrderStatus.Status.1' => 'foo', 'OrderStatus.Status.2' => 'bar' }
|
16
|
-
assert_equal
|
16
|
+
assert_equal exp, @list.build(%w(foo bar))
|
17
17
|
end
|
18
18
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'peddler/parser'
|
3
|
+
|
4
|
+
class XMLParserTest < MiniTest::Test
|
5
|
+
def setup
|
6
|
+
body = '<Response><Result><NextToken>123</NextToken><Foo>Bar</Foo></Result></Response>'
|
7
|
+
res = OpenStruct.new(body: body, headers: { 'Content-Type' => 'text/xml'})
|
8
|
+
|
9
|
+
@parser = Peddler::Parser.parse(res)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_parses_data
|
13
|
+
assert_equal 'Bar', @parser.parse['Foo']
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_next_token
|
17
|
+
assert_equal '123', @parser.next_token
|
18
|
+
end
|
19
|
+
end
|