snl-peddler 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/History.txt +2 -0
- data/LICENSE +22 -0
- data/README.rdoc +104 -0
- data/Rakefile +17 -0
- data/VERSION.yml +4 -0
- data/lib/peddler.rb +25 -0
- data/lib/peddler/client.rb +240 -0
- data/lib/peddler/feeds.rb +181 -0
- data/lib/peddler/handlers.rb +58 -0
- data/lib/peddler/inventory.rb +108 -0
- data/lib/peddler/legacy_reports.rb +107 -0
- data/lib/peddler/refunds.rb +54 -0
- data/lib/peddler/reports.rb +94 -0
- data/lib/peddler/transport.rb +135 -0
- data/peddler.gemspec +78 -0
- data/spec/peddler/client_spec.rb +47 -0
- data/spec/peddler/feeds_spec.rb +70 -0
- data/spec/peddler/handlers_spec.rb +15 -0
- data/spec/peddler/inventory_spec.rb +74 -0
- data/spec/peddler/legacy_reports_spec.rb +86 -0
- data/spec/peddler/refunds_spec.rb +35 -0
- data/spec/peddler/reports_spec.rb +19 -0
- data/spec/peddler/transport_spec.rb +58 -0
- data/spec/spec_helper.rb +3 -0
- metadata +106 -0
data/peddler.gemspec
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{peddler}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Hakan Senol Ensari"]
|
12
|
+
s.date = %q{2009-08-15}
|
13
|
+
s.description = %q{Peddler is a Ruby wrapper to the Amazon Inventory Management API.}
|
14
|
+
s.email = %q{hakan.ensari@papercavalier.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"History.txt",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION.yml",
|
26
|
+
"lib/peddler.rb",
|
27
|
+
"lib/peddler/client.rb",
|
28
|
+
"lib/peddler/feeds.rb",
|
29
|
+
"lib/peddler/handlers.rb",
|
30
|
+
"lib/peddler/inventory.rb",
|
31
|
+
"lib/peddler/legacy_reports.rb",
|
32
|
+
"lib/peddler/refunds.rb",
|
33
|
+
"lib/peddler/reports.rb",
|
34
|
+
"lib/peddler/transport.rb",
|
35
|
+
"peddler.gemspec",
|
36
|
+
"spec/peddler/client_spec.rb",
|
37
|
+
"spec/peddler/feeds_spec.rb",
|
38
|
+
"spec/peddler/handlers_spec.rb",
|
39
|
+
"spec/peddler/inventory_spec.rb",
|
40
|
+
"spec/peddler/legacy_reports_spec.rb",
|
41
|
+
"spec/peddler/refunds_spec.rb",
|
42
|
+
"spec/peddler/reports_spec.rb",
|
43
|
+
"spec/peddler/transport_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.homepage = %q{http://github.com/snl/peddler}
|
47
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = %q{1.3.3}
|
50
|
+
s.summary = %q{Peddler is a Ruby wrapper to the Amazon Inventory Management API.}
|
51
|
+
s.test_files = [
|
52
|
+
"spec/peddler/client_spec.rb",
|
53
|
+
"spec/peddler/feeds_spec.rb",
|
54
|
+
"spec/peddler/handlers_spec.rb",
|
55
|
+
"spec/peddler/inventory_spec.rb",
|
56
|
+
"spec/peddler/legacy_reports_spec.rb",
|
57
|
+
"spec/peddler/refunds_spec.rb",
|
58
|
+
"spec/peddler/reports_spec.rb",
|
59
|
+
"spec/peddler/transport_spec.rb",
|
60
|
+
"spec/spec_helper.rb"
|
61
|
+
]
|
62
|
+
|
63
|
+
if s.respond_to? :specification_version then
|
64
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
65
|
+
s.specification_version = 3
|
66
|
+
|
67
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
68
|
+
s.add_runtime_dependency(%q<xmlsimple>, [">= 0"])
|
69
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<xmlsimple>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<xmlsimple>, [">= 0"])
|
76
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
module Peddler
|
4
|
+
|
5
|
+
describe Client do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@client = Peddler::Client.new :username => "seller@example.com",
|
9
|
+
:password => "secret",
|
10
|
+
:region => "us"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return a new inventory batch" do
|
14
|
+
@client.new_inventory_batch.should be_an_instance_of(Peddler::Inventory::Batch)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return a new inventory item" do
|
18
|
+
@client.new_inventory_item.should be_an_instance_of(Peddler::Inventory::Item)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return a new order fulfillment feed" do
|
22
|
+
@client.new_order_fulfillment_feed.should be_an_instance_of(Peddler::Feeds::OrderFulfillment::Batch)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return a new fulfilled order" do
|
26
|
+
@client.new_fulfilled_order.should be_an_instance_of(Peddler::Feeds::OrderFulfillment::Item)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return a new order cancellation feed" do
|
30
|
+
@client.new_order_cancellation_feed.should be_an_instance_of(Peddler::Feeds::OrderCancellation::Batch)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return a new cancelled order" do
|
34
|
+
@client.new_cancelled_order.should be_an_instance_of(Peddler::Feeds::OrderCancellation::Item)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return a new refund batch" do
|
38
|
+
@client.new_refund_batch.should be_an_instance_of(Peddler::Refunds::Batch)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return a new report" do
|
42
|
+
@client.new_report(:foo).should be_an_instance_of(Peddler::LegacyReports::Report)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
module Peddler
|
4
|
+
module Feeds
|
5
|
+
module OrderFulfillment
|
6
|
+
describe Batch do
|
7
|
+
before(:each) do
|
8
|
+
@transport = Peddler::Transport.new
|
9
|
+
@transport.modernize_request
|
10
|
+
@feed = Peddler::Feeds::OrderFulfillment::Batch.new(@transport)
|
11
|
+
@fulfilled_order = Peddler::Feeds::OrderFulfillment::Item.new :order_id => "123-1234567-1234567",
|
12
|
+
:ship_date => Date.parse("2009-08-11").to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should add items to batch" do
|
16
|
+
@feed.batch.size.should == 0
|
17
|
+
@feed << @fulfilled_order
|
18
|
+
@feed.batch.size.should == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create content for upload" do
|
22
|
+
@feed << @fulfilled_order
|
23
|
+
@feed.file_content.should == "order-id\torder-item-id\tquantity\tship-date\tcarrier-code\tcarrier-name\ttracking-number\tship-method\r\n123-1234567-1234567\t\t\t2009-08-11\t\t\t\t\r\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should upload" do
|
27
|
+
@feed.id.should == nil
|
28
|
+
@transport.stub!(:execute_request).and_return('<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://merchant-query.amazon.com/query/schema/MerchantQueryResponses.xsd"><Upload> <UploadId>130895733</UploadId><UploadType>_POST_FLAT_FILE_FULFILLMENT_DATA_</UploadType><UploadStatus>_SUBMITTED_</UploadStatus><SubmittedDate>2007-04-05T00:34:00+0000</SubmittedDate></Upload></Response>')
|
29
|
+
@feed.upload
|
30
|
+
@feed.id.should == "130895733"
|
31
|
+
@feed.status.should == "_SUBMITTED_"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should refresh status" do
|
35
|
+
@transport.stub!(:execute_request).and_return('<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://merchant-query.amazon.com/query/schema/MerchantQueryResponses.xsd"><Upload> <UploadId>130895733</UploadId><UploadType>_POST_FLAT_FILE_FULFILLMENT_DATA_</UploadType><UploadStatus>_SUBMITTED_</UploadStatus><SubmittedDate>2007-04-05T00:34:00+0000</SubmittedDate></Upload></Response>')
|
36
|
+
@feed.upload
|
37
|
+
@transport.stub!(:execute_request).and_return('<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://merchant-query.amazon.com/query/schema/MerchantQueryResponses.xsd"><UploadsStatusList><Upload><UploadId>130895733</UploadId><UploadType>_POST_FLAT_FILE_FULFILLMENT_DATA_</UploadType><UploadStatus>_IN_PROGRESS_</UploadStatus><SubmittedDate>2007-04-05T00:34:00+0000</SubmittedDate><StartedProcessingDate>2007-04-05T00:39:00+0000</StartedProcessingDate></Upload></UploadsStatusList></Response>')
|
38
|
+
@feed.status.should == "_SUBMITTED_"
|
39
|
+
@feed.status!.should == "_IN_PROGRESS_"
|
40
|
+
@transport.stub!(:execute_request).and_return('<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://merchant-query.amazon.com/query/schema/MerchantQueryResponses.xsd"><UploadsStatusList><Upload><UploadId>130895733</UploadId><UploadType>_POST_FLAT_FILE_FULFILLMENT_DATA_</UploadType><UploadStatus>_DONE_</UploadStatus><SubmittedDate>2007-04-05T00:34:00+0000</SubmittedDate><StartedProcessingDate>2007-04-05T00:39:00+0000</StartedProcessingDate><CompletedProcessingDate>2007-04-05T01:02:00+0000</CompletedProcessingDate><MessagesProcessed>2</MessagesProcessed><MessagesSuccessful>2</MessagesSuccessful><MessagesWithErrors>0</MessagesWithErrors><MessagesWithWarnings>0</MessagesWithWarnings><RelatedDownloadsList><Download><DownloadId>3404021</DownloadId><DownloadType>FeedSummaryReport</DownloadType><RelatedReferenceId>4307285844</RelatedReferenceId><AvailableDate>2009-04-24T23:47:24+00:00</AvailableDate><Acknowledged>FALSE</Acknowledged></Download></RelatedDownloadsList></Upload></UploadsStatusList></Response>')
|
41
|
+
@feed.status!.should == "_DONE_"
|
42
|
+
@feed.download.id.should == "3404021"
|
43
|
+
@feed.download.available_at.to_s.should == "Sat Apr 25 00:47:24 +0100 2009"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module OrderCancellation
|
49
|
+
describe Batch do
|
50
|
+
before(:each) do
|
51
|
+
@transport = Peddler::Transport.new
|
52
|
+
@transport.modernize_request
|
53
|
+
@feed = Peddler::Feeds::OrderCancellation::Batch.new(@transport)
|
54
|
+
@cancelled_order = Peddler::Feeds::OrderCancellation::Item.new :order_id => "123-1234567-1234567"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should add items to batch" do
|
58
|
+
@feed.batch.size.should == 0
|
59
|
+
@feed << @cancelled_order
|
60
|
+
@feed.batch.size.should == 1
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should create content for upload" do
|
64
|
+
@feed << @cancelled_order
|
65
|
+
@feed.file_content.should == "TemplateType=OrderCancellation Version=1.0/1.0.3 This row for Amazon.com use only. Do not modify or delete.\r\norder-id\tcancellation-reason-code\tamazon-order-item-code\r\n123-1234567-1234567\t\t\r\n"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
module Peddler
|
3
|
+
module Handlers
|
4
|
+
describe XMLHandler do
|
5
|
+
it "should parse a legacy report" do
|
6
|
+
xml = Peddler::Handlers::XMLHandler.decode_response("<Reports> <Report>reportstarttime=08-13-2009:06-16-06 reportendtime=12-31-1969:16-00-00 reportid=2599221990 </Report></Reports>")
|
7
|
+
statuses = Peddler::Handlers::XMLHandler.parse_legacy(xml)
|
8
|
+
statuses[0].id.should == "2599221990"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe TabDelimitedHandler do
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
module Peddler
|
4
|
+
|
5
|
+
module Inventory
|
6
|
+
|
7
|
+
describe Queue do
|
8
|
+
|
9
|
+
it "should show queue count" do
|
10
|
+
transport = Peddler::Transport.new
|
11
|
+
transport.legacize_request
|
12
|
+
transport.stub!(:execute_request).and_return("<PendingUploadsCount>1</PendingUploadsCount>")
|
13
|
+
Peddler::Inventory::Queue.count(transport).should == 1
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe Batch do
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
@transport = Peddler::Transport.new
|
22
|
+
@transport.legacize_request
|
23
|
+
@inventory = Peddler::Inventory::Batch.new(@transport)
|
24
|
+
@item = Peddler::Inventory::Item.new :product_id => "1234567890",
|
25
|
+
:price => 100.00,
|
26
|
+
:sku => "FOO-SKU",
|
27
|
+
:quantity => 10
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should add items to batch" do
|
31
|
+
@inventory.batch.size.should == 0
|
32
|
+
@inventory << @item
|
33
|
+
@inventory.batch.size.should == 1
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should generate an upload file" do
|
37
|
+
@inventory << @item
|
38
|
+
@inventory.file_content.should == "product-id\tproduct-id-type\titem-condition\tprice\tsku\tquantity\tadd-delete\twill-ship-internationally\texpedited-shipping\titem-note\titem-is-marketplace\tfulfillment-center-id\titem-name\titem-description\tcategory1\timage-url\tshipping-fee\tbrowse-path\tstorefront-feature\tboldface\tasin1\tasin2\tasin3\r\n1234567890\t\t\t100.0\tFOO-SKU\t10\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should generate a modify-only upload file" do
|
42
|
+
@inventory << @item
|
43
|
+
@inventory.file_content(:short).should == "sku\tprice\tquantity\r\nFOO-SKU\t100.0\t10\r\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should generate default headers for uploading" do
|
47
|
+
params = @inventory.defaultize :file_format => "UIEE",
|
48
|
+
:enable_expedited_shipping => "N"
|
49
|
+
params[:method].should be_nil
|
50
|
+
params[:upload_for].should == "Marketplace"
|
51
|
+
params[:email].should == "Y"
|
52
|
+
params[:file_format].should == "UIEE"
|
53
|
+
params["enable-expedited-shipping"].should == "N"
|
54
|
+
params[:enable_expedited_shipping].should be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should upload batch" do
|
58
|
+
@transport.stub!(:execute_request).and_return("<BatchID>2585199250</BatchID>")
|
59
|
+
@inventory.upload.should == true
|
60
|
+
@inventory.id.should == "2585199250"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should raise error if a subsequent upload is attempted" do
|
64
|
+
@transport.stub!(:execute_request).and_return("<BatchID>2585199250</BatchID>")
|
65
|
+
@inventory.upload.should == true
|
66
|
+
@inventory.id.should_not == nil
|
67
|
+
lambda { @inventory.upload }.should raise_error(PeddlerError)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
module Peddler
|
4
|
+
describe LegacyReports do
|
5
|
+
before(:each) do
|
6
|
+
@transport = Peddler::Transport.new
|
7
|
+
@transport.legacize_request
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should generate an order report" do
|
11
|
+
@transport.stub!(:execute_request).and_return("<Status>SUCCESS</Status>")
|
12
|
+
res = Peddler::LegacyReports.generate(@transport, :order, :number_of_days => 30)
|
13
|
+
res.should be_an_instance_of(Peddler::LegacyReports::Report)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should show most recent order reports" do
|
17
|
+
@transport.stub!(:execute_request).and_return("<Reports> <Report>reportstarttime=07-23-2009:08-33-48 reportendtime=08-07-2009:08-33-48 reportid=1234567890 </Report></Reports>")
|
18
|
+
report_status = Peddler::LegacyReports.latest(@transport, :order, :count => 1)[0]
|
19
|
+
report_status.starts_at.should == "07-23-2009:08-33-48"
|
20
|
+
report_status.id.should == "1234567890"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should show most recent uploads" do
|
24
|
+
@transport.stub!(:execute_request).and_return("<Batches> <Batch>batchid=2586376232 status=Done dateandtime=08/07/2009 01:48:23 PDT activateditems=1020 numberofwarnings=0 itemsnotacivated=0 </Batch></Batches>")
|
25
|
+
upload = Peddler::LegacyReports.latest(@transport, :upload, :count => 1)[0]
|
26
|
+
upload.id.should == "2586376232"
|
27
|
+
upload.status.should == "Done"
|
28
|
+
upload.datetime.should == "08/07/2009 01:48:23 PDT"
|
29
|
+
upload.activated_items.should == "1020"
|
30
|
+
upload.number_of_warnings.should == "0"
|
31
|
+
upload.items_not_activated.should == "0"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module LegacyReports
|
36
|
+
describe Report do
|
37
|
+
before(:each) do
|
38
|
+
@transport = Peddler::Transport.new
|
39
|
+
@transport.legacize_request
|
40
|
+
@report = Peddler::LegacyReports::Report.new(@transport)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should download an inventory upload error log" do
|
44
|
+
@transport.stub!(:execute_request).and_return("Feed Processing Summary:\n\tNumber of records processed\t\t82\n\tNumber of records successful\t\t81\n\noriginal-record-number\tsku\terror-code\terror-type\terror-message\n27\t1111111111\t8026\tError\tSeller is not authorized to list products in this category. For more details, see http://sellercentral.amazon.com/gp/errorcode/8026\n")
|
45
|
+
|
46
|
+
@report.name = :upload
|
47
|
+
@report.id = "1234567890"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should download an inventory upload error log" do
|
51
|
+
@transport.stub!(:execute_request).and_return("Feed Processing Summary:\n\tNumber of records processed\t\t82\n\tNumber of records successful\t\t81\n\noriginal-record-number\tsku\terror-code\terror-type\terror-message\n27\t1111111111\t8026\tError\tSeller is not authorized to list products in this category. For more details, see http://sellercentral.amazon.com/gp/errorcode/8026\n")
|
52
|
+
@report.name = :upload
|
53
|
+
@report.id = "1234567890"
|
54
|
+
@report.body.should =~ /Feed Processing Summary/
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should retrieve an order report by id" do
|
58
|
+
@transport.stub!(:execute_request).and_return("payments-status\torder-id\torder-item-id\tpayments-date\tpayments-transaction-id\titem-name\tlisting-id\tsku\tprice\tshipping-fee\tquantity-purchased\ttotal-price\tpurchase-date\tbatch-id\tbuyer-email\tbuyer-name\trecipient-name\tship-address-1\tship-address-2\tship-city\tship-state\tship-zip\tship-country\tspecial-comments\tupc\tship-method\n\t001-1234567-1234567\t12345678901234\t2009-07-23 08:59:03 PST\t\tFoo Bar\t000000000000\t1234567890\t10.00\t3.99\t1\t13.99\t2009-07-23 08:59:03 PST\t\tfoo@bar.com\tJOHN DOE\tJohn Doe\t1 MAIN ST\t\tNEW YORK\tNY\t10001-1000\tUS\t\t\tstandard\n")
|
59
|
+
@report.name = :order
|
60
|
+
@report.id = "1234567890"
|
61
|
+
res = Peddler::Handlers::TabDelimitedHandler.decode_response(@report.body)
|
62
|
+
res.size.should == 1
|
63
|
+
res[0].order_id.should == "001-1234567-1234567"
|
64
|
+
res[0].buyer_name.should == "JOHN DOE"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should retrieve an order report by report name" do
|
68
|
+
@transport.stub!(:execute_request).and_return("payments-status\torder-id\torder-item-id\tpayments-date\tpayments-transaction-id\titem-name\tlisting-id\tsku\tprice\tshipping-fee\tquantity-purchased\ttotal-price\tpurchase-date\tbatch-id\tbuyer-email\tbuyer-name\trecipient-name\tship-address-1\tship-address-2\tship-city\tship-state\tship-zip\tship-country\tspecial-comments\tupc\tship-method\n\t001-1234567-1234567\t12345678901234\t2009-07-23 08:59:03 PST\t\tFoo Bar\t000000000000\t1234567890\t10.00\t3.99\t1\t13.99\t2009-07-23 08:59:03 PST\t\tfoo@bar.com\tJOHN DOE\tJohn Doe\t1 MAIN ST\t\tNEW YORK\tNY\t10001-1000\tUS\t\t\tstandard\n")
|
69
|
+
@report.name = :order
|
70
|
+
res = Peddler::Handlers::TabDelimitedHandler.decode_response(@report.body)
|
71
|
+
res.size.should == 1
|
72
|
+
res[0].order_id.should == "001-1234567-1234567"
|
73
|
+
res[0].buyer_name.should == "JOHN DOE"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should retrieve an open listings liter report by id" do
|
77
|
+
@transport.stub!(:execute_request).and_return("seller-sku\tquantity\nSKU-FOO\t14\n")
|
78
|
+
@report.name = :open_listings_liter
|
79
|
+
@report.id = "1234567890"
|
80
|
+
res = Peddler::Handlers::TabDelimitedHandler.decode_response(@report.body)
|
81
|
+
res.size.should == 1
|
82
|
+
res[0].seller_sku.should == "SKU-FOO"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
module Peddler
|
4
|
+
module Refunds
|
5
|
+
describe Batch do
|
6
|
+
before(:each) do
|
7
|
+
@transport = Peddler::Transport.new
|
8
|
+
@transport.legacize_request
|
9
|
+
@refunds = Peddler::Refunds::Batch.new(@transport)
|
10
|
+
@refund = Peddler::Refunds::Item.new :order_id => "123-1234567-1234567",
|
11
|
+
:payments_transaction_id => "12341234567890",
|
12
|
+
:refund_amount => 10.00,
|
13
|
+
:reason => "CouldNotShip",
|
14
|
+
:message => "With our apologies"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should add items to batch" do
|
18
|
+
@refunds.batch.size.should == 0
|
19
|
+
@refunds << @refund
|
20
|
+
@refunds.batch.size.should == 1
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should generate an upload file" do
|
24
|
+
@refunds << @refund
|
25
|
+
@refunds.file_content.should == "order-id\tpayments-transaction-id\trefund-amount\treason\tmessage\r\n123-1234567-1234567\t12341234567890\t10.0\tCouldNotShip\tWith our apologies\r\n"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should upload batch" do
|
29
|
+
@transport.stub!(:execute_request).and_return("<Success>SUCCESS</Success>")
|
30
|
+
@refunds << @refund
|
31
|
+
@refunds.upload.should == true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
module Peddler
|
4
|
+
module Reports
|
5
|
+
describe UnshippedOrdersReport do
|
6
|
+
before(:each) do
|
7
|
+
@transport = Peddler::Transport.new
|
8
|
+
@transport.modernize_request
|
9
|
+
@transport.stub!(:execute_request).and_return("<?xml version=\"1.0\"?>\n<Response xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://merchant-query.amazon.com/query/schema/MerchantQueryResponses.xsd\"><Report><ReportID>2597613290</ReportID><DownloadType>_GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_</DownloadType><StartDate>2009-08-05T19:54:31+00:00</StartDate><EndDate>2009-08-12T19:54:31+00:00</EndDate><Scheduled>false</Scheduled><ReportStatus>_SUBMITTED_</ReportStatus><SubmittedDate>2009-08-12T19:54:31+00:00</SubmittedDate></Report></Response>")
|
10
|
+
@report = Peddler::Reports::UnshippedOrdersReport.new(@transport)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should add generate a request" do
|
14
|
+
@report.id.should == "2597613290"
|
15
|
+
@report.status.should == "_SUBMITTED_"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
module Peddler
|
4
|
+
|
5
|
+
describe Transport do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@transport = Peddler::Transport.new
|
9
|
+
@transport.username = "user"
|
10
|
+
@transport.password = "secret"
|
11
|
+
@transport.region = "us"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should switch regions" do
|
15
|
+
@transport.legacize_request
|
16
|
+
@transport.region = "uk"
|
17
|
+
@transport.url.host.should == "secure.amazon.co.uk"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise error when region is invalid" do
|
21
|
+
lambda { @transport.region = "foo" }.should raise_error(PeddlerError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should add path to legacy URL" do
|
25
|
+
@transport.legacize_request
|
26
|
+
@transport.path << "foo"
|
27
|
+
@transport.url.to_s.should == "https://secure.amazon.com/exec/panama/seller-admin/foo/"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should add path to modern URL" do
|
31
|
+
@transport.modernize_request
|
32
|
+
@transport.path << "foo"
|
33
|
+
@transport.url.to_s.should == "https://secure.amazon.com/query/foo/?Service=MerchantQueryService"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should add query parameters to the modern URL" do
|
37
|
+
@transport.modernize_request
|
38
|
+
@transport.query_params["key1"] = "val1"
|
39
|
+
@transport.query_params["key2"] = "val2"
|
40
|
+
@transport.url.to_s.should == "https://secure.amazon.com/query/?key1=val1&key2=val2&Service=MerchantQueryService"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should url_encode query parameters" do
|
44
|
+
@transport.modernize_request
|
45
|
+
@transport.query_params["key"] = "!@#"
|
46
|
+
@transport.url.to_s.should == "https://secure.amazon.com/query/?key=%21%40%23&Service=MerchantQueryService"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should authenticate request" do
|
50
|
+
@transport.legacize_request
|
51
|
+
req = @transport.request
|
52
|
+
req["authorization"].should_not be(nil)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|