mws_rb 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.ruby-gemset +1 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +43 -0
- data/Gemfile +3 -0
- data/Guardfile +12 -0
- data/LICENSE +20 -0
- data/README.markdown +73 -0
- data/Rakefile +1 -0
- data/lib/mws.rb +51 -0
- data/lib/mws/api/base.rb +55 -0
- data/lib/mws/api/feeds.rb +30 -0
- data/lib/mws/api/feeds/envelope.rb +84 -0
- data/lib/mws/api/feeds/xsd/AdditionalProductInformation.xsd +23 -0
- data/lib/mws/api/feeds/xsd/Amazon.xsd +94 -0
- data/lib/mws/api/feeds/xsd/Arts.xsd +144 -0
- data/lib/mws/api/feeds/xsd/AutoAccessory.xsd +1714 -0
- data/lib/mws/api/feeds/xsd/Baby.xsd +206 -0
- data/lib/mws/api/feeds/xsd/Beauty.xsd +170 -0
- data/lib/mws/api/feeds/xsd/Books.xsd +135 -0
- data/lib/mws/api/feeds/xsd/CE.xsd +2878 -0
- data/lib/mws/api/feeds/xsd/CameraPhoto.xsd +2612 -0
- data/lib/mws/api/feeds/xsd/ClothingAccessories.xsd +128 -0
- data/lib/mws/api/feeds/xsd/Computers.xsd +2347 -0
- data/lib/mws/api/feeds/xsd/EUCompliance.xsd +24 -0
- data/lib/mws/api/feeds/xsd/EntertainmentCollectibles.xsd +99 -0
- data/lib/mws/api/feeds/xsd/FBA.xsd +28 -0
- data/lib/mws/api/feeds/xsd/FoodAndBeverages.xsd +1000 -0
- data/lib/mws/api/feeds/xsd/FoodServiceAndJanSan.xsd +216 -0
- data/lib/mws/api/feeds/xsd/FulfillmentCenter.xsd +57 -0
- data/lib/mws/api/feeds/xsd/GiftCards.xsd +97 -0
- data/lib/mws/api/feeds/xsd/Gourmet.xsd +85 -0
- data/lib/mws/api/feeds/xsd/Health.xsd +335 -0
- data/lib/mws/api/feeds/xsd/Home.xsd +1362 -0
- data/lib/mws/api/feeds/xsd/HomeImprovement.xsd +1065 -0
- data/lib/mws/api/feeds/xsd/Industrial.xsd +315 -0
- data/lib/mws/api/feeds/xsd/Inventory.xsd +49 -0
- data/lib/mws/api/feeds/xsd/Jewelry.xsd +916 -0
- data/lib/mws/api/feeds/xsd/LabSupplies.xsd +178 -0
- data/lib/mws/api/feeds/xsd/LargeAppliances.xsd +646 -0
- data/lib/mws/api/feeds/xsd/Lighting.xsd +243 -0
- data/lib/mws/api/feeds/xsd/Listings.xsd +32 -0
- data/lib/mws/api/feeds/xsd/Luggage.xsd +93 -0
- data/lib/mws/api/feeds/xsd/MechanicalFasteners.xsd +172 -0
- data/lib/mws/api/feeds/xsd/Miscellaneous.xsd +157 -0
- data/lib/mws/api/feeds/xsd/Motorcycles.xsd +348 -0
- data/lib/mws/api/feeds/xsd/Music.xsd +251 -0
- data/lib/mws/api/feeds/xsd/MusicalInstruments.xsd +853 -0
- data/lib/mws/api/feeds/xsd/Office.xsd +586 -0
- data/lib/mws/api/feeds/xsd/OrderAcknowledgement.xsd +55 -0
- data/lib/mws/api/feeds/xsd/OrderAdjustment.xsd +175 -0
- data/lib/mws/api/feeds/xsd/OrderFulfillment.xsd +57 -0
- data/lib/mws/api/feeds/xsd/Override.xsd +48 -0
- data/lib/mws/api/feeds/xsd/PetSupplies.xsd +197 -0
- data/lib/mws/api/feeds/xsd/PowerTransmission.xsd +87 -0
- data/lib/mws/api/feeds/xsd/Price.xsd +59 -0
- data/lib/mws/api/feeds/xsd/ProcessingReport.xsd +87 -0
- data/lib/mws/api/feeds/xsd/Product.xsd +399 -0
- data/lib/mws/api/feeds/xsd/ProductClothing.xsd +285 -0
- data/lib/mws/api/feeds/xsd/ProductImage.xsd +39 -0
- data/lib/mws/api/feeds/xsd/RawMaterials.xsd +125 -0
- data/lib/mws/api/feeds/xsd/Relationship.xsd +47 -0
- data/lib/mws/api/feeds/xsd/SWVG.xsd +345 -0
- data/lib/mws/api/feeds/xsd/SettlementReport.xsd +158 -0
- data/lib/mws/api/feeds/xsd/Shoes.xsd +213 -0
- data/lib/mws/api/feeds/xsd/Sports.xsd +772 -0
- data/lib/mws/api/feeds/xsd/SportsMemorabilia.xsd +55 -0
- data/lib/mws/api/feeds/xsd/TiresAndWheels.xsd +159 -0
- data/lib/mws/api/feeds/xsd/Tools.xsd +82 -0
- data/lib/mws/api/feeds/xsd/Toys.xsd +272 -0
- data/lib/mws/api/feeds/xsd/ToysBaby.xsd +335 -0
- data/lib/mws/api/feeds/xsd/Video.xsd +406 -0
- data/lib/mws/api/feeds/xsd/WineAndAlcohol.xsd +181 -0
- data/lib/mws/api/feeds/xsd/Wireless.xsd +128 -0
- data/lib/mws/api/feeds/xsd/amzn-base.xsd +4350 -0
- data/lib/mws/api/feeds/xsd/amzn-envelope.xsd +98 -0
- data/lib/mws/api/feeds/xsd/amzn-header.xsd +45 -0
- data/lib/mws/api/fulfillment_inbound_shipment.rb +16 -0
- data/lib/mws/api/fulfillment_inventory.rb +14 -0
- data/lib/mws/api/fulfillment_outbound_shipment.rb +24 -0
- data/lib/mws/api/orders.rb +16 -0
- data/lib/mws/api/products.rb +19 -0
- data/lib/mws/api/recommendations.rb +14 -0
- data/lib/mws/api/reports.rb +17 -0
- data/lib/mws/api/sellers.rb +18 -0
- data/lib/mws/api/subscriptions.rb +15 -0
- data/lib/mws/connection.rb +56 -0
- data/lib/mws/query.rb +104 -0
- data/lib/mws/version.rb +4 -0
- data/mws_rb.gemspec +32 -0
- data/spec/fixtures/vcr_cassettes/feeds/submit_feed/invalid_request.yml +194 -0
- data/spec/fixtures/vcr_cassettes/feeds/submit_feed/text_request.yml +188 -0
- data/spec/fixtures/vcr_cassettes/feeds/submit_feed/xml_request.yml +224 -0
- data/spec/mws-rb/api/base_spec.rb +48 -0
- data/spec/mws-rb/api/feeds/envelope/general_spec.rb +31 -0
- data/spec/mws-rb/api/feeds/envelope/xml_building_spec.rb +101 -0
- data/spec/mws-rb/api/feeds_spec.rb +88 -0
- data/spec/mws-rb/api/fulfillment_inbound_shipment_spec.rb +24 -0
- data/spec/mws-rb/api/fulfillment_inventory_spec.rb +24 -0
- data/spec/mws-rb/api/fulfillment_outbound_shipment_spec.rb +24 -0
- data/spec/mws-rb/api/orders_spec.rb +24 -0
- data/spec/mws-rb/api/products_spec.rb +24 -0
- data/spec/mws-rb/api/recommendations_spec.rb +24 -0
- data/spec/mws-rb/api/reports_spec.rb +24 -0
- data/spec/mws-rb/api/sellers_spec.rb +28 -0
- data/spec/mws-rb/api/subscriptions_spec.rb +24 -0
- data/spec/mws-rb/connection_spec.rb +77 -0
- data/spec/mws-rb/mws_spec.rb +12 -0
- data/spec/mws-rb/query_spec.rb +150 -0
- data/spec/spec_helper.rb +17 -0
- metadata +310 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 6984f02c386959b4ed60082b2b1f733b069ce0f3
|
|
4
|
+
data.tar.gz: aa2c13fc770dcb14c5e0d3a0e4f0ee3a4bc304f8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c02ac371ce06c65d342090c382adfe33497b039dcb8bfd1caa048a795974df716a324717fe745662cad9b8306f0ddeba2f8d570a3d81a062cbe092ce378c5b0a
|
|
7
|
+
data.tar.gz: 59f664c80f238b037435013eae1350b1a04ed078a4526b2a097667a55b87d49aa17747d80ab298e84251300872235d78524652f8c09f6a18dcdb1d6f2f3a5285
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mws-rb
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Changelog
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
Version 0.0.2 (February 2, 2015)
|
|
5
|
+
-----------------------------
|
|
6
|
+
|
|
7
|
+
* Completed Orders API
|
|
8
|
+
* Completed Products API
|
|
9
|
+
* Completed Sellers API
|
|
10
|
+
* Completed Recommendations API
|
|
11
|
+
* Completed FulfillmentInventory API
|
|
12
|
+
* Completed FulfillmentInboundShipment API
|
|
13
|
+
* Completed FulfillmentOutboundShipment API
|
|
14
|
+
* Completed Feeds API
|
|
15
|
+
* Completed Subscriptions API
|
|
16
|
+
|
|
17
|
+
Version 0.0.3 (February 21, 2015)
|
|
18
|
+
-----------------------------
|
|
19
|
+
|
|
20
|
+
* Fix Orders API spec
|
|
21
|
+
* Add default timeout for requests
|
|
22
|
+
|
|
23
|
+
Version 0.0.4 (April 7, 2015)
|
|
24
|
+
-----------------------------
|
|
25
|
+
|
|
26
|
+
* Add support of MWS Auth Token
|
|
27
|
+
* Add global reference to the location of XSD files
|
|
28
|
+
|
|
29
|
+
Version 0.0.5 (May 29, 2015)
|
|
30
|
+
-----------------------------
|
|
31
|
+
|
|
32
|
+
* Fix signature generation
|
|
33
|
+
* Add support text based feeds
|
|
34
|
+
|
|
35
|
+
Version 0.0.6 (Next release)
|
|
36
|
+
-----------------------------
|
|
37
|
+
|
|
38
|
+
* Add missing specs
|
|
39
|
+
* Update rspec expectations
|
|
40
|
+
* Update dependencies
|
|
41
|
+
* Fix query action SKU|ASIN capitalization
|
|
42
|
+
* Default connection params to ENV variables
|
|
43
|
+
* Enforce ruby guidelines using Rubocop
|
data/Gemfile
ADDED
data/Guardfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# A sample Guardfile
|
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
|
3
|
+
|
|
4
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
|
5
|
+
watch(%r{^lib/(.+)\.rb$}) { 'spec' }
|
|
6
|
+
watch(%r{^spec/(.+)\.rb$}) { 'spec' }
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
guard :rubocop do
|
|
10
|
+
watch(/.+\.rb$/)
|
|
11
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
|
12
|
+
end
|
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2013 Jhimy Fernandes Villar
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# mws_rb
|
|
2
|
+
|
|
3
|
+
This gem is a complete wrapper for Amazon.com's Marketplace Web Service (MWS) API extracted from http://veeqo.com
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Using with a Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'mws_rb', require: 'mws'
|
|
10
|
+
bundle install
|
|
11
|
+
|
|
12
|
+
Using in a simple ruby file:
|
|
13
|
+
|
|
14
|
+
gem install mws_rb
|
|
15
|
+
require 'mws'
|
|
16
|
+
|
|
17
|
+
## Initialization
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
mws_api = MWS.new(
|
|
21
|
+
host: "mws-eu.amazonservices.com",
|
|
22
|
+
aws_access_key_id: "Your access key id",
|
|
23
|
+
aws_secret_access_key: "Your secret access key",
|
|
24
|
+
seller_id: "Your seller/merchant id"
|
|
25
|
+
)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Using
|
|
29
|
+
|
|
30
|
+
To access the apis you can use:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
mws_api._api_name_._action_to_calll(params={})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Let's say we want to retrieve a list of orders using MWS orders api:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
mws_api.orders.list_orders(
|
|
40
|
+
"MarketplaceId.Id.1" => "marketplace id",
|
|
41
|
+
created_after: Time.new(2013, 1, 1)
|
|
42
|
+
)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Here is a list of all available APIS:
|
|
46
|
+
|
|
47
|
+
- mws_api.feeds
|
|
48
|
+
- mws_api.orders
|
|
49
|
+
- mws_api.reports
|
|
50
|
+
- mws_api.products
|
|
51
|
+
- mws_api.sellers
|
|
52
|
+
- mws_api.recommendations
|
|
53
|
+
- mws_api.fulfillment_inventory
|
|
54
|
+
- mws_api.fulfillment_inbound_shipment
|
|
55
|
+
- mws_api.fulfillment_outbound_shipment
|
|
56
|
+
|
|
57
|
+
## API docs/actions/params
|
|
58
|
+
|
|
59
|
+
You can check on the MWS documentation section all actions and params needed:
|
|
60
|
+
|
|
61
|
+
- http://docs.developer.amazonservices.com/en_US/feeds/index.html
|
|
62
|
+
- http://docs.developer.amazonservices.com/en_US/reports/index.html
|
|
63
|
+
- http://docs.developer.amazonservices.com/en_US/fba_inbound/index.html
|
|
64
|
+
- http://docs.developer.amazonservices.com/en_US/fba_inventory/index.html
|
|
65
|
+
- http://docs.developer.amazonservices.com/en_US/fba_outbound/index.html
|
|
66
|
+
- http://docs.developer.amazonservices.com/en_US/orders/index.html
|
|
67
|
+
- http://docs.developer.amazonservices.com/en_US/products/index.html
|
|
68
|
+
- http://docs.developer.amazonservices.com/en_US/recommendations/index.html
|
|
69
|
+
- http://docs.developer.amazonservices.com/en_US/sellers/index.html
|
|
70
|
+
|
|
71
|
+
## LICENSE
|
|
72
|
+
|
|
73
|
+
Copyright (c) Jhimy Fernandes Villar
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/mws.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# rubocop:disable all
|
|
2
|
+
require 'httparty'
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'openssl'
|
|
5
|
+
require 'active_support/core_ext'
|
|
6
|
+
require 'builder'
|
|
7
|
+
require 'nokogiri'
|
|
8
|
+
|
|
9
|
+
require_relative 'mws/query'
|
|
10
|
+
require_relative 'mws/connection'
|
|
11
|
+
require_relative 'mws/api/base'
|
|
12
|
+
require_relative 'mws/api/orders'
|
|
13
|
+
require_relative 'mws/api/reports'
|
|
14
|
+
require_relative 'mws/api/products'
|
|
15
|
+
require_relative 'mws/api/sellers'
|
|
16
|
+
require_relative 'mws/api/subscriptions'
|
|
17
|
+
require_relative 'mws/api/recommendations'
|
|
18
|
+
require_relative 'mws/api/fulfillment_inventory'
|
|
19
|
+
require_relative 'mws/api/fulfillment_inbound_shipment'
|
|
20
|
+
require_relative 'mws/api/fulfillment_outbound_shipment'
|
|
21
|
+
require_relative 'mws/api/feeds'
|
|
22
|
+
require_relative 'mws/api/feeds/envelope'
|
|
23
|
+
|
|
24
|
+
module MWS
|
|
25
|
+
@@aws_access_key_id = nil
|
|
26
|
+
@@aws_secret_access_key = nil
|
|
27
|
+
|
|
28
|
+
def self.aws_access_key_id=(key_id)
|
|
29
|
+
@@aws_access_key_id = key_id
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.aws_access_key_id
|
|
33
|
+
@@aws_access_key_id
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.aws_secret_access_key=(secret_key)
|
|
37
|
+
@@aws_secret_access_key = secret_key
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.aws_secret_access_key
|
|
41
|
+
@@aws_secret_access_key
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.new(options = {})
|
|
45
|
+
@connection = MWS::Connection.new(options)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.config
|
|
49
|
+
yield self
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/mws/api/base.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module MWS
|
|
2
|
+
module API
|
|
3
|
+
# Base Class
|
|
4
|
+
class Base
|
|
5
|
+
attr_reader :connection, :uri, :version, :verb
|
|
6
|
+
|
|
7
|
+
# TODO: Temporary solution, move to configuration
|
|
8
|
+
DEFAULT_TIMEOUT = 2000
|
|
9
|
+
|
|
10
|
+
def initialize(connection)
|
|
11
|
+
@verb ||= :get
|
|
12
|
+
@connection = connection
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def call(action, params = {})
|
|
16
|
+
@verb ||= params.delete(:verb)
|
|
17
|
+
query = build_query_from_params(action, params)
|
|
18
|
+
|
|
19
|
+
case @verb.to_s.upcase
|
|
20
|
+
when 'GET'
|
|
21
|
+
HTTParty.get(query.request_uri, http_request_options)
|
|
22
|
+
when 'POST'
|
|
23
|
+
HTTParty.post(query.request_uri, (params[:request_params] || {}).merge(http_request_options))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def build_query_from_params(action, params)
|
|
28
|
+
Query.new(verb: @verb,
|
|
29
|
+
uri: @uri,
|
|
30
|
+
host: @connection.host,
|
|
31
|
+
aws_access_key_id: @connection.aws_access_key_id,
|
|
32
|
+
aws_secret_access_key: @connection.aws_secret_access_key,
|
|
33
|
+
seller_id: @connection.seller_id,
|
|
34
|
+
mws_auth_token: @connection.mws_auth_token,
|
|
35
|
+
action: action.to_s.camelize,
|
|
36
|
+
version: @version,
|
|
37
|
+
params: params.except(:request_params))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def method_missing(name, *args)
|
|
41
|
+
if self.class::ACTIONS.include?(name)
|
|
42
|
+
call(name, *args)
|
|
43
|
+
else
|
|
44
|
+
super
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def http_request_options
|
|
49
|
+
{
|
|
50
|
+
timeout: DEFAULT_TIMEOUT
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module MWS
|
|
2
|
+
module API
|
|
3
|
+
# Feeds
|
|
4
|
+
class Feeds < Base
|
|
5
|
+
XSD_PATH = File.join(File.dirname(__FILE__), 'feeds', 'xsd')
|
|
6
|
+
|
|
7
|
+
ACTIONS = [:get_feed_submission_list, :get_feed_submission_list_by_next_token,
|
|
8
|
+
:get_feed_submission_count, :cancel_feed_submissions, :get_feed_submission_result]
|
|
9
|
+
|
|
10
|
+
def initialize(connection)
|
|
11
|
+
@uri = '/'
|
|
12
|
+
@version = '2009-01-01'
|
|
13
|
+
@verb = :post
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def submit_feed(params = {})
|
|
18
|
+
xml_envelope = Envelope.new(params.merge!(merchant_id: connection.seller_id))
|
|
19
|
+
params = params.except(:merchant_id, :message_type, :message, :messages, :skip_schema_validation)
|
|
20
|
+
call(:submit_feed, params.merge!(
|
|
21
|
+
request_params: {
|
|
22
|
+
format: :xml,
|
|
23
|
+
headers: { 'Content-MD5' => xml_envelope.md5 },
|
|
24
|
+
body: xml_envelope.to_s
|
|
25
|
+
}
|
|
26
|
+
))
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
module MWS
|
|
2
|
+
module API
|
|
3
|
+
class Feeds
|
|
4
|
+
# Envelope
|
|
5
|
+
class Envelope
|
|
6
|
+
def initialize(params = {})
|
|
7
|
+
if params[:type].to_s == 'text'
|
|
8
|
+
@type = :text
|
|
9
|
+
@envelope = params[:message]
|
|
10
|
+
else
|
|
11
|
+
@type = :xml
|
|
12
|
+
@envelope = build_envelope(params)
|
|
13
|
+
end
|
|
14
|
+
validate! unless params[:skip_schema_validation] || @type == :text
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def valid?
|
|
18
|
+
errors.count == 0
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def validate!
|
|
22
|
+
fail "Invalid XML:\n" + errors.join("\n") unless valid?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def md5
|
|
26
|
+
Digest::MD5.base64digest(self)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def to_str
|
|
30
|
+
to_s
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_s
|
|
34
|
+
if @type == :text
|
|
35
|
+
result = @envelope
|
|
36
|
+
else
|
|
37
|
+
result = @envelope.target!
|
|
38
|
+
result.gsub!('<Items type="array">', '')
|
|
39
|
+
result.gsub!('</Items>', '')
|
|
40
|
+
result.gsub!('<Inventories type="array">', '')
|
|
41
|
+
result.gsub!('</Inventories>', '')
|
|
42
|
+
end
|
|
43
|
+
result
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def xsd
|
|
47
|
+
Nokogiri::XML::Schema(File.open(File.join(MWS::API::Feeds::XSD_PATH, 'amzn-envelope.xsd')))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def errors
|
|
51
|
+
@errors ||= xsd.validate(Nokogiri::XML(self))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
# rubocop:disable all
|
|
57
|
+
def build_envelope(params = {})
|
|
58
|
+
xml = Builder::XmlMarkup.new
|
|
59
|
+
xml.AmazonEnvelope do
|
|
60
|
+
xml.Header do
|
|
61
|
+
xml.DocumentVersion '1.01'
|
|
62
|
+
xml.MerchantIdentifier params[:merchant_id]
|
|
63
|
+
end
|
|
64
|
+
xml.MessageType params[:message_type].to_s.camelize
|
|
65
|
+
xml.PurgeAndReplace params[:purge_and_replace] || false
|
|
66
|
+
messages_array(params).each { |message| xml << message_xml(message) }
|
|
67
|
+
end; xml
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def messages_array(params)
|
|
71
|
+
get_array(params[:message]) + get_array(params[:messages])
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def get_array(parameter)
|
|
75
|
+
[parameter].flatten.compact
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def message_xml(message)
|
|
79
|
+
message.to_xml(skip_instruct: true, root: 'Message')
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!-- Revision="$Revision: #1 $" -->
|
|
3
|
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
|
|
4
|
+
<!--
|
|
5
|
+
$Date: 2012/09/11/ $
|
|
6
|
+
AMAZON.COM CONFIDENTIAL. This document and the information contained in it are
|
|
7
|
+
confidential and proprietary information of Amazon.com and may not be reproduced,
|
|
8
|
+
distributed or used, in whole or in part, for any purpose other than as necessary
|
|
9
|
+
to list products for sale on the www.amazon.com web site pursuant to an agreement
|
|
10
|
+
with Amazon.com.
|
|
11
|
+
-->
|
|
12
|
+
<xsd:include schemaLocation="amzn-base.xsd"/>
|
|
13
|
+
<xsd:element name="AdditionalProductInformation">
|
|
14
|
+
<xsd:complexType>
|
|
15
|
+
<xsd:sequence>
|
|
16
|
+
<xsd:element name="MaterialFabric" type="HundredString" minOccurs="0" maxOccurs="3"/>
|
|
17
|
+
<xsd:element name="ImportDesignation" type="HundredString" minOccurs="0"/>
|
|
18
|
+
<xsd:element name="CountryAsLabeled" type="CountryOfOriginType" minOccurs="0"/>
|
|
19
|
+
<xsd:element name="FurDescription" type="HundredString" minOccurs="0"/>
|
|
20
|
+
</xsd:sequence>
|
|
21
|
+
</xsd:complexType>
|
|
22
|
+
</xsd:element>
|
|
23
|
+
</xsd:schema>
|