ruby-mws 0.0.4 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -11,4 +11,5 @@ gem 'rash'
11
11
 
12
12
  gem 'rspec'
13
13
  gem 'ephemeral_response'
14
- gem 'awesome_print'
14
+ gem 'awesome_print'
15
+ gem 'pry'
@@ -66,10 +66,12 @@ Here, there are more orders to be returned. You can call `has_next?` on the same
66
66
 
67
67
  Repeat as necessary. You can keep calling `next` on the API instance as long as `has_next?` returns true.
68
68
 
69
- Or if you need to, you can save the next_token and go about the manual way as per Amazon's docs:
69
+ Or if you need to, you can save `next_token` and go about the manual way as per Amazon's docs:
70
70
 
71
71
  next_response = mws.orders.list_orders_by_next_token :next_token => response.next_token
72
72
 
73
+ ***
74
+
73
75
  API
74
76
  ---
75
77
 
@@ -79,23 +81,37 @@ This object can be used to access all API services. Below are examples on how to
79
81
 
80
82
  ### Orders API
81
83
 
82
- * ListOrders - gets orders by time range and other parameters
84
+ * ListOrders - Gets orders by time range and other parameters
83
85
 
84
86
  `@mws.orders.list_orders :last_updated_after => Time.now-4.hours, :order_status => 'Shipped'`
85
87
 
86
- * GetOrder - gets orders by Amazon order ID
88
+ * GetOrder - Gets orders by Amazon order ID
87
89
 
88
90
  `@mws.orders.get_order :amazon_order_id => "002-EXAMPLE-0031387"`
89
91
 
90
92
  `:amazon_order_id` can be an array to retrieve multiple orders.
91
93
 
92
- * ListOrderItems - gets order items for one order ID (only one order at a time here)
94
+ * ListOrderItems - Gets order items for one order ID (only one order at a time here)
93
95
 
94
96
  `@mws.orders.list_order_items :amazon_order_id => "002-EXAMPLE-0031387"`
95
97
 
96
98
  ### Fulfillment Inventory API
97
99
 
98
- * ListInventorySupply - returns availability of inventory, only returns items based on list of SKUs or last change date
100
+ * ListInventorySupply - Returns availability of inventory, only returns items based on list of SKUs or last change date
99
101
 
100
102
  `@mws.inventory.list_inventory_supply :seller_skus => ['PF-5VZN-04XR', 'V4-03EY-LAL1', 'OC-TUKC-031P']`
101
- `@mws.inventory.list_inventory_supply :query_start_date_time => Time.now-1.day`
103
+ `@mws.inventory.list_inventory_supply :query_start_date_time => Time.now-1.day`
104
+
105
+ ### Reports API
106
+
107
+ * RequestReport - Used to submit a request for a report by [report type](http://docs.developer.amazonservices.com/en_US/reports/Reports_ReportType.html). Returns report request info.
108
+
109
+ `@mws.reports.request_report :report_type => "_GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA_", :start_date => 1.day.ago, :end_date => Time.now`
110
+
111
+ * GetReportRequestList - Returns a list of the most recently requested reports. Use `report_request_id` to find the status of your report. Once `report_processing_status` for your request is "_DONE_", use `generated_report_id` to get your results.
112
+
113
+ `@mws.reports.get_report_request_list`
114
+
115
+ * GetReport - Used to request a report by report ID. All reports are currently returned as a flat file string.
116
+
117
+ `@mws.reports.get_report :report_id => '11223344'`
File without changes
@@ -51,8 +51,12 @@ require 'ruby-mws/connection'
51
51
  require 'ruby-mws/exceptions'
52
52
  require 'ruby-mws/version'
53
53
 
54
+ require 'ruby-mws/api/binary_parser'
55
+
54
56
  require 'ruby-mws/api/base'
55
57
  require 'ruby-mws/api/inventory'
56
58
  require 'ruby-mws/api/order'
59
+ require 'ruby-mws/api/report'
57
60
  require 'ruby-mws/api/query'
58
- require 'ruby-mws/api/response'
61
+ require 'ruby-mws/api/response'
62
+ require 'ruby-mws/api/binary_response'
@@ -6,8 +6,9 @@ module MWS
6
6
 
7
7
  class Base
8
8
  include HTTParty
9
- # debug_output $stderr # only in development
10
- format :xml
9
+ parser MWS::API::BinaryParser
10
+ debug_output $stderr # only in development
11
+ #format :xml
11
12
  headers "User-Agent" => "ruby-mws/#{MWS::VERSION} (Language=Ruby/1.9.3-p0)"
12
13
  headers "Content-Type" => "text/xml"
13
14
 
@@ -31,28 +32,34 @@ module MWS
31
32
  end
32
33
  end
33
34
 
34
- def send_request(name, params, options)
35
+ def send_request(name, params, options={})
35
36
  # prepare all required params...
36
- params = [params, options, @connection.to_hash].inject :merge
37
-
38
- # default/common params
39
- params[:action] ||= name.to_s.camelize
40
- params[:signature_method] ||= 'HmacSHA256'
41
- params[:signature_version] ||= '2'
42
- params[:timestamp] ||= Time.now.iso8601
43
- params[:version] ||= '2009-01-01'
37
+ params = [default_params(name), params, options, @connection.to_hash].inject :merge
44
38
 
45
39
  params[:lists] ||= {}
46
40
  params[:lists][:marketplace_id] = "MarketplaceId.Id"
47
41
 
48
42
  query = Query.new params
49
- @response = Response.parse self.class.send(params[:verb], query.request_uri), name, params
43
+ resp = self.class.send(params[:verb], query.request_uri)
44
+
45
+ @response = Response.parse resp, name, params
46
+
50
47
  if @response.respond_to?(:next_token) and @next[:token] = @response.next_token # modifying, not comparing
51
48
  @next[:action] = name.match(/_by_next_token/) ? name : "#{name}_by_next_token"
52
49
  end
53
50
  @response
54
51
  end
55
52
 
53
+ def default_params(name)
54
+ {
55
+ :action => name.to_s.camelize,
56
+ :signature_method => 'HmacSHA256',
57
+ :signature_version => '2',
58
+ :timestamp => Time.now.iso8601,
59
+ :version => '2009-01-01'
60
+ }
61
+ end
62
+
56
63
  def has_next?
57
64
  not @next[:token].nil?
58
65
  end
@@ -0,0 +1,16 @@
1
+ module MWS
2
+ module API
3
+
4
+ class BinaryParser < HTTParty::Parser
5
+ SupportedFormats.merge!({ "application/octet-stream" => :binary })
6
+
7
+ protected
8
+
9
+ def binary
10
+ body
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module MWS
2
+ module API
3
+
4
+ class BinaryResponse < Struct.new(:body)
5
+
6
+ def self.parse(response, name, params)
7
+ new(response.parsed_response)
8
+ end
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ module MWS
2
+ module API
3
+
4
+ class Report < Base
5
+ def_request [:request_report],
6
+ :verb => :post,
7
+ :uri => '/',
8
+ :version => '2009-01-01'
9
+
10
+ def_request [:get_report],
11
+ :verb => :get,
12
+ :uri => '/',
13
+ :version => '2009-01-01'
14
+
15
+ def_request [:get_report_request_list, :get_report_request_list_by_next_token],
16
+ :verb => :get,
17
+ :uri => '/',
18
+ :version => '2009-01-01'
19
+ end
20
+
21
+ end
22
+ end
@@ -3,8 +3,10 @@ module MWS
3
3
 
4
4
  class Response < Hashie::Rash
5
5
 
6
- def self.parse(hash, name, params)
7
- rash = self.new(hash)
6
+ def self.parse(body, name, params)
7
+ return body unless body.is_a?(Hash)
8
+
9
+ rash = self.new(body)
8
10
  handle_error_response(rash["error_response"]["error"]) unless rash["error_response"].nil?
9
11
  raise BadResponseError, "received non-matching response type #{rash.keys}" if rash["#{name}_response"].nil?
10
12
  rash = rash["#{name}_response"]
@@ -16,6 +16,10 @@ module MWS
16
16
  @inventory ||= MWS::API::Inventory.new(@connection)
17
17
  end
18
18
 
19
+ def reports
20
+ @reports ||= MWS::API::Report.new(@connection)
21
+ end
22
+
19
23
 
20
24
  # serves as a server ping
21
25
  def self.server_time
@@ -1,3 +1,3 @@
1
1
  module MWS
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1"
3
3
  end
@@ -5,21 +5,20 @@ describe MWS::API::Inventory do
5
5
  before :all do
6
6
  EphemeralResponse.activate
7
7
  @mws = MWS.new(auth_params)
8
- @timestamp = "2012-04-25T21:42:11-04:00"
9
8
  end
10
9
 
11
10
  context "requests" do
12
11
 
13
12
  describe "list_inventory_supply" do
14
13
  it "should return items based on seller SKUs" do
15
- items = @mws.inventory.list_inventory_supply :timestamp => @timestamp,
14
+ items = @mws.inventory.list_inventory_supply :timestamp => timestamp,
16
15
  :seller_skus => %w[PF-5VZN-04XR V4-03EY-LAL1 OC-TUKC-031P]
17
16
  items.should have_key :inventory_supply_list
18
17
  items.inventory_supply_list.should be_an_instance_of Array
19
18
  end
20
19
 
21
20
  it "should return items with inventory changes since a certain time" do
22
- items = @mws.inventory.list_inventory_supply :timestamp => @timestamp,
21
+ items = @mws.inventory.list_inventory_supply :timestamp => timestamp,
23
22
  :query_start_date_time => "2012-01-15T10:04:01-05:00"
24
23
  items.should have_key :inventory_supply_list
25
24
  items.inventory_supply_list.should be_an_instance_of Array
@@ -5,14 +5,13 @@ describe MWS::API::Order do
5
5
  before :all do
6
6
  EphemeralResponse.activate
7
7
  @mws = MWS.new(auth_params)
8
- @timestamp = "2012-04-25T21:42:55-04:00"
9
8
  end
10
9
 
11
10
  context "requests" do
12
11
  describe "list_orders" do
13
12
  it "should receive a list of orders" do
14
13
  orders = @mws.orders.list_orders :last_updated_after => "2012-01-15T13:07:26-05:00" ,
15
- :timestamp => @timestamp
14
+ :timestamp => timestamp
16
15
  orders.orders.should be_an_instance_of Array
17
16
  orders.orders.first.should have_key :amazon_order_id
18
17
  end
@@ -20,7 +19,7 @@ describe MWS::API::Order do
20
19
 
21
20
  describe "list_orders_by_next_token" do
22
21
  it "should receive a list_orders_by_next_token_result" do
23
- orders = @mws.orders.list_orders_by_next_token :timestamp => @timestamp,
22
+ orders = @mws.orders.list_orders_by_next_token :timestamp => timestamp,
24
23
  :next_token => "zwR7fTkqiKp/YYuZQbKv1QafEPREmauvizt1MIhPYZZl3LSdPSOgN1byEfyVqilNBpcRD1uxgRxTg2dsYWmzKd8ytOVgN7d/KyNtf5fepe2OEd7gVZif6X81/KsTyqd1e64rGQd1TyCS68vI7Bqws+weLxD7b1CVZciW6QBe7o2FizcdzSXGSiKsUkM4/6QGllhc4XvGqg5e0zIeaOVNezxWEXvdeDL7eReo//Hc3LMRF18hF5ZYNntoCB8irbDGcVkxA+q0fZYwE7+t4NjazyEZY027dXAVTSGshRBy6ZTthhfBGj6Dwur8WCwcU8Vc25news0zC1w6gK1h3EdXw7a3u+Q12Uw9ZROnI57RGr4CrtRODNGKSRdGvNrxcHpI2aLZKrJa2MgKRa+KsojCckrDiHqb8mBEJ88g6izJN42dQcLTGQRwBej+BBOOHYP4"
25
24
  orders.orders.should be_an_instance_of Array
26
25
  orders.orders.first.should have_key :amazon_order_id
@@ -30,7 +29,7 @@ describe MWS::API::Order do
30
29
  describe "get_order" do
31
30
  it "should return one order for one order id" do
32
31
  order = @mws.orders.get_order :amazon_order_id => "102-4850183-7065809",
33
- :timestamp => @timestamp
32
+ :timestamp => timestamp
34
33
  order.should have_key :orders
35
34
  order.orders.should be_an_instance_of Array
36
35
  order.orders.first.should have_key :amazon_order_id
@@ -38,7 +37,7 @@ describe MWS::API::Order do
38
37
 
39
38
  it "should return multiple orders for multiple order ids" do
40
39
  orders = @mws.orders.get_order :amazon_order_id => ["102-4850183-7065809", "002-3400187-5292203"],
41
- :timestamp => @timestamp
40
+ :timestamp => timestamp
42
41
  orders.orders.should be_an_instance_of Array
43
42
  orders.orders.size.should == 2
44
43
  orders.orders.first.should have_key :amazon_order_id
@@ -48,7 +47,7 @@ describe MWS::API::Order do
48
47
  describe "list_order_items" do
49
48
  it "should return a list of items for an order" do
50
49
  order = @mws.orders.list_order_items :amazon_order_id => "102-4850183-7065809",
51
- :timestamp => @timestamp
50
+ :timestamp => timestamp
52
51
  order.should have_key :amazon_order_id
53
52
  order.should have_key :order_items
54
53
  order.order_items.should be_an_instance_of Array
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe MWS::API::Report do
4
+
5
+ before :all do
6
+ EphemeralResponse.activate
7
+ @mws = MWS.new(auth_params)
8
+ end
9
+
10
+ context "requests" do
11
+ describe "get_report" do
12
+ # TODO: Mock Response?
13
+ end
14
+
15
+ describe "request_report" do
16
+ it "should request a report" do
17
+ response = @mws.reports.request_report report_type: '_GET_FLAT_FILE_OPEN_LISTINGS_DATA_', timestamp: timestamp
18
+ response.should have_key(:request_report_info)
19
+ end
20
+ end
21
+
22
+ describe "get_report_request_list" do
23
+ it "should get a list of report requests" do
24
+ response = @mws.reports.get_report_request_list timestamp: timestamp
25
+ response.request_report_info.should be_an_instance_of Array
26
+ end
27
+
28
+ end
29
+ end
30
+
31
+ end
@@ -14,7 +14,7 @@ RSpec.configure do |config|
14
14
  @mws_object ||= MWS.new(auth_params)
15
15
  end
16
16
 
17
- # To test, create spec/credentials.yml or fill in below
17
+ # To test, create spec/credentials.yml
18
18
  def auth_params
19
19
  @auth_params ||=
20
20
  begin
@@ -28,6 +28,11 @@ RSpec.configure do |config|
28
28
  }
29
29
  end
30
30
  end
31
+
32
+ def timestamp
33
+ # use a recent timestamp here... how to replace this?
34
+ "2013-11-17T21:17:59-06:00"
35
+ end
31
36
  end
32
37
 
33
38
  class TestWorksError < StandardError
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: '0.1'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-13 00:00:00.000000000 Z
12
+ date: 2013-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -140,9 +140,12 @@ files:
140
140
  - bin/ruby-mws
141
141
  - lib/ruby-mws.rb
142
142
  - lib/ruby-mws/api/base.rb
143
+ - lib/ruby-mws/api/binary_parser.rb
144
+ - lib/ruby-mws/api/binary_response.rb
143
145
  - lib/ruby-mws/api/inventory.rb
144
146
  - lib/ruby-mws/api/order.rb
145
147
  - lib/ruby-mws/api/query.rb
148
+ - lib/ruby-mws/api/report.rb
146
149
  - lib/ruby-mws/api/response.rb
147
150
  - lib/ruby-mws/base.rb
148
151
  - lib/ruby-mws/connection.rb
@@ -155,6 +158,7 @@ files:
155
158
  - spec/ruby-mws/api/inventory_spec.rb
156
159
  - spec/ruby-mws/api/order_spec.rb
157
160
  - spec/ruby-mws/api/query_spec.rb
161
+ - spec/ruby-mws/api/report_spec.rb
158
162
  - spec/ruby-mws/base_spec.rb
159
163
  - spec/ruby-mws/connection_spec.rb
160
164
  - spec/spec_helper.rb
@@ -189,6 +193,7 @@ test_files:
189
193
  - spec/ruby-mws/api/inventory_spec.rb
190
194
  - spec/ruby-mws/api/order_spec.rb
191
195
  - spec/ruby-mws/api/query_spec.rb
196
+ - spec/ruby-mws/api/report_spec.rb
192
197
  - spec/ruby-mws/base_spec.rb
193
198
  - spec/ruby-mws/connection_spec.rb
194
199
  - spec/spec_helper.rb