peddler 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +237 -8
- data/lib/mws/feeds.rb +1 -0
- data/lib/mws/feeds/client.rb +97 -0
- data/lib/mws/feeds/parsers/feed.rb +14 -0
- data/lib/mws/feeds/parsers/feed_submission.rb +25 -0
- data/lib/mws/feeds/parsers/feed_submission_count.rb +13 -0
- data/lib/mws/feeds/parsers/feed_submission_list.rb +20 -0
- data/lib/mws/feeds/parsers/feed_submission_result.rb +10 -0
- data/lib/mws/feeds/parsers/feed_submissions.rb +18 -0
- data/lib/mws/feeds/requests/feed.rb +38 -0
- data/lib/mws/feeds/requests/feed_submission_count.rb +20 -0
- data/lib/mws/feeds/requests/feed_submission_list.rb +28 -0
- data/lib/mws/feeds/requests/feed_submission_result.rb +18 -0
- data/lib/mws/feeds/requests/feed_submissions.rb +20 -0
- data/lib/mws/fulfillment_inbound_shipment/client.rb +7 -0
- data/lib/mws/fulfillment_inventory/client.rb +7 -0
- data/lib/mws/fulfillment_outbound_shipment/client.rb +7 -0
- data/lib/mws/off_amazon_payments/client.rb +7 -0
- data/lib/mws/orders.rb +1 -0
- data/lib/mws/orders/client.rb +88 -0
- data/lib/mws/orders/parsers/invoice_data.rb +25 -0
- data/lib/mws/orders/parsers/order.rb +113 -0
- data/lib/mws/orders/parsers/order_item.rb +110 -0
- data/lib/mws/orders/parsers/order_items.rb +20 -0
- data/lib/mws/orders/parsers/orders.rb +20 -0
- data/lib/mws/orders/parsers/payment_execution_detail.rb +20 -0
- data/lib/mws/orders/parsers/payment_execution_detail_item.rb +17 -0
- data/lib/mws/orders/parsers/service_status.rb +36 -0
- data/lib/mws/orders/parsers/service_status_message.rb +17 -0
- data/lib/mws/orders/parsers/shipping_address.rb +37 -0
- data/lib/mws/orders/requests/order_items.rb +26 -0
- data/lib/mws/orders/requests/orders.rb +39 -0
- data/lib/mws/orders/requests/service_status.rb +15 -0
- data/lib/mws/products/client.rb +7 -0
- data/lib/mws/recommendations/client.rb +7 -0
- data/lib/mws/reports/client.rb +6 -0
- data/lib/mws/sellers/client.rb +7 -0
- data/lib/mws/subscriptions/client.rb +7 -0
- data/lib/peddler.rb +11 -1
- data/lib/peddler/client.rb +62 -0
- data/lib/peddler/parsers/base.rb +15 -0
- data/lib/peddler/parsers/collection.rb +23 -0
- data/lib/peddler/parsers/model.rb +43 -0
- data/lib/peddler/parsers/text.rb +13 -0
- data/lib/peddler/parsers/xml.rb +25 -0
- data/lib/peddler/request.rb +50 -0
- data/lib/peddler/request/parameters.rb +56 -0
- data/lib/peddler/request/structured_list.rb +43 -0
- data/lib/peddler/response_wrapper.rb +32 -0
- data/lib/peddler/version.rb +1 -1
- data/test/fixtures/feeds/feed_submission.xml +14 -0
- data/test/fixtures/feeds/feed_submission_count.xml +9 -0
- data/test/fixtures/feeds/feed_submission_list.xml +17 -0
- data/test/fixtures/feeds/feed_submissions.xml +15 -0
- data/test/fixtures/mws.yml +8 -0
- data/test/fixtures/mws.yml.example +4 -0
- data/test/fixtures/orders/order_items.xml +83 -0
- data/test/fixtures/orders/orders.xml +109 -0
- data/test/fixtures/orders/service_status.xml +19 -0
- data/test/helper.rb +5 -0
- data/test/integration/feeds/test_feed_submission_count.rb +13 -0
- data/test/integration/feeds/test_feed_submission_list.rb +15 -0
- data/test/integration/feeds/test_feed_submission_result.rb +15 -0
- data/test/integration/orders/test_order_items.rb +19 -0
- data/test/integration/orders/test_orders.rb +20 -0
- data/test/integration/orders/test_service_status.rb +12 -0
- data/test/integration_helper.rb +16 -0
- data/test/mws/feeds/parsers/test_feed.rb +13 -0
- data/test/mws/feeds/parsers/test_feed_submission.rb +25 -0
- data/test/mws/feeds/parsers/test_feed_submission_count.rb +13 -0
- data/test/mws/feeds/parsers/test_feed_submission_list.rb +14 -0
- data/test/mws/feeds/parsers/test_feed_submission_result.rb +13 -0
- data/test/mws/feeds/parsers/test_feed_submissions.rb +17 -0
- data/test/mws/feeds/requests/test_feed.rb +63 -0
- data/test/mws/feeds/requests/test_feed_submission_count.rb +23 -0
- data/test/mws/feeds/requests/test_feed_submission_list.rb +40 -0
- data/test/mws/feeds/requests/test_feed_submissions.rb +29 -0
- data/test/mws/orders/parsers/test_order.rb +86 -0
- data/test/mws/orders/parsers/test_order_item.rb +69 -0
- data/test/mws/orders/parsers/test_order_items.rb +14 -0
- data/test/mws/orders/parsers/test_orders.rb +14 -0
- data/test/mws/orders/parsers/test_payment_execution_detail.rb +14 -0
- data/test/mws/orders/parsers/test_payment_execution_detail_item.rb +17 -0
- data/test/mws/orders/parsers/test_service_status.rb +39 -0
- data/test/mws/orders/parsers/test_service_status_message.rb +17 -0
- data/test/mws/orders/parsers/test_shipping_address.rb +36 -0
- data/test/mws/orders/requests/test_order_items.rb +39 -0
- data/test/mws/orders/requests/test_orders.rb +49 -0
- data/test/mws/orders/requests/test_service_status.rb +25 -0
- data/test/parser_helper.rb +11 -0
- data/test/peddler/parsers/test_collection.rb +8 -0
- data/test/peddler/parsers/test_model.rb +34 -0
- data/test/peddler/request/test_parameters.rb +35 -0
- data/test/peddler/request/test_structured_list.rb +18 -0
- data/test/peddler/test_client.rb +42 -0
- data/test/request_helper.rb +20 -0
- metadata +213 -10
- data/lib/peddler/apis.rb +0 -45
- data/lib/peddler/service.rb +0 -83
- data/test/service_test.rb +0 -42
- data/test/test_helper.rb +0 -3
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'mws/orders/parsers/order_item'
|
2
|
+
require 'peddler/parsers/collection'
|
3
|
+
|
4
|
+
module MWS
|
5
|
+
module Orders
|
6
|
+
module Parsers
|
7
|
+
class OrderItems < ::Peddler::Parsers::Collection
|
8
|
+
def each(&blk)
|
9
|
+
order_item_nodes.each { |node| yield OrderItem.new(node) }
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def order_item_nodes
|
15
|
+
xpath('OrderItems/OrderItem')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'mws/orders/parsers/order'
|
2
|
+
require 'peddler/parsers/collection'
|
3
|
+
|
4
|
+
module MWS
|
5
|
+
module Orders
|
6
|
+
module Parsers
|
7
|
+
class Orders < ::Peddler::Parsers::Collection
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegator :order_nodes, :each
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def order_nodes
|
15
|
+
xpath('Orders/Order').map { |node| Order.new(node) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'mws/orders/parsers/payment_execution_detail_item'
|
2
|
+
require 'peddler/parsers/collection'
|
3
|
+
|
4
|
+
module MWS
|
5
|
+
module Orders
|
6
|
+
module Parsers
|
7
|
+
class PaymentExecutionDetail < ::Peddler::Parsers::Collection
|
8
|
+
def each(&blk)
|
9
|
+
payment_execution_detail_item_nodes.each { |node| yield PaymentExecutionDetailItem.new(node) }
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def payment_execution_detail_item_nodes
|
15
|
+
xpath('PaymentExecutionDetailItem')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'peddler/parsers/model'
|
2
|
+
|
3
|
+
module MWS
|
4
|
+
module Orders
|
5
|
+
module Parsers
|
6
|
+
class PaymentExecutionDetailItem < ::Peddler::Parsers::Model
|
7
|
+
value :payment do
|
8
|
+
money_at_xpath('Payment')
|
9
|
+
end
|
10
|
+
|
11
|
+
value :payment_method do
|
12
|
+
text_at_xpath('PaymentMethod')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'mws/orders/parsers/service_status_message'
|
2
|
+
require 'peddler/parsers/model'
|
3
|
+
|
4
|
+
module MWS
|
5
|
+
module Orders
|
6
|
+
module Parsers
|
7
|
+
class ServiceStatus < ::Peddler::Parsers::Model
|
8
|
+
value :status do
|
9
|
+
text_at_xpath('Status')
|
10
|
+
end
|
11
|
+
|
12
|
+
value :timestamp do
|
13
|
+
time_at_xpath('Timestamp')
|
14
|
+
end
|
15
|
+
|
16
|
+
value :message_id do
|
17
|
+
text_at_xpath('MessageId')
|
18
|
+
end
|
19
|
+
|
20
|
+
value :messages do
|
21
|
+
xpath('Messages/Message').map { |node| ServiceStatusMessage.new(node) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def ok?
|
25
|
+
status == 'GREEN'
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
status
|
30
|
+
end
|
31
|
+
|
32
|
+
alias :to_s :inspect
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'peddler/parsers/model'
|
2
|
+
|
3
|
+
module MWS
|
4
|
+
module Orders
|
5
|
+
module Parsers
|
6
|
+
class ServiceStatusMessage < ::Peddler::Parsers::Model
|
7
|
+
value :locale do
|
8
|
+
text_at_xpath('Locale')
|
9
|
+
end
|
10
|
+
|
11
|
+
value :text do
|
12
|
+
text_at_xpath('Text')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'peddler/parsers/model'
|
2
|
+
|
3
|
+
module MWS
|
4
|
+
module Orders
|
5
|
+
module Parsers
|
6
|
+
class ShippingAddress < ::Peddler::Parsers::Model
|
7
|
+
value :name do
|
8
|
+
text_at_xpath('Name')
|
9
|
+
end
|
10
|
+
|
11
|
+
value :address_lines do
|
12
|
+
1.upto(3).map { |i| text_at_xpath("AddressLine#{i}") }.compact
|
13
|
+
end
|
14
|
+
|
15
|
+
value :city do
|
16
|
+
text_at_xpath('City')
|
17
|
+
end
|
18
|
+
|
19
|
+
value :state_or_region do
|
20
|
+
text_at_xpath('StateOrRegion')
|
21
|
+
end
|
22
|
+
|
23
|
+
value :postal_code do
|
24
|
+
text_at_xpath('PostalCode')
|
25
|
+
end
|
26
|
+
|
27
|
+
value :country_code do
|
28
|
+
text_at_xpath('CountryCode')
|
29
|
+
end
|
30
|
+
|
31
|
+
value :phone do
|
32
|
+
text_at_xpath('Phone')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'peddler/request'
|
2
|
+
require 'mws/orders/parsers/order_items'
|
3
|
+
|
4
|
+
module MWS
|
5
|
+
module Orders
|
6
|
+
module Requests
|
7
|
+
class OrderItems < ::Peddler::Request
|
8
|
+
def list(amazon_order_id)
|
9
|
+
parameters(:list_order_items)
|
10
|
+
.update(amazon_order_id: amazon_order_id)
|
11
|
+
.camelize_keys!
|
12
|
+
|
13
|
+
execute
|
14
|
+
end
|
15
|
+
|
16
|
+
def list_by_next_token
|
17
|
+
parameters(:list_order_items_by_next_token)
|
18
|
+
.update(next_token: next_token)
|
19
|
+
.camelize_keys!
|
20
|
+
|
21
|
+
execute
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'peddler/request'
|
2
|
+
require 'mws/orders/parsers/orders'
|
3
|
+
|
4
|
+
module MWS
|
5
|
+
module Orders
|
6
|
+
module Requests
|
7
|
+
class Orders < ::Peddler::Request
|
8
|
+
def get(*amazon_order_ids)
|
9
|
+
parameters(:get_order)
|
10
|
+
.update(amazon_order_id: amazon_order_ids)
|
11
|
+
.format_structured_lists!
|
12
|
+
.camelize_keys!
|
13
|
+
|
14
|
+
execute
|
15
|
+
end
|
16
|
+
|
17
|
+
def list(options)
|
18
|
+
options[:marketplace_id] ||= client.marketplace_id
|
19
|
+
|
20
|
+
parameters(:list_orders)
|
21
|
+
.update(options)
|
22
|
+
.timestamp!
|
23
|
+
.format_structured_lists!
|
24
|
+
.camelize_keys!
|
25
|
+
|
26
|
+
execute
|
27
|
+
end
|
28
|
+
|
29
|
+
def list_by_next_token
|
30
|
+
parameters(:list_orders_by_next_token)
|
31
|
+
.update(next_token: next_token)
|
32
|
+
.camelize_keys!
|
33
|
+
|
34
|
+
execute
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'peddler/request'
|
2
|
+
require 'mws/orders/parsers/service_status'
|
3
|
+
|
4
|
+
module MWS
|
5
|
+
module Orders
|
6
|
+
module Requests
|
7
|
+
class ServiceStatus < ::Peddler::Request
|
8
|
+
def get
|
9
|
+
parameters(:get_service_status)
|
10
|
+
execute
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/peddler.rb
CHANGED
@@ -1 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'mws/feeds'
|
2
|
+
require 'mws/fulfillment_inbound_shipment'
|
3
|
+
require 'mws/fulfillment_inventory'
|
4
|
+
require 'mws/fulfillment_outbound_shipment'
|
5
|
+
require 'mws/off_amazon_payments'
|
6
|
+
require 'mws/orders'
|
7
|
+
require 'mws/products'
|
8
|
+
require 'mws/recommendations'
|
9
|
+
require 'mws/reports'
|
10
|
+
require 'mws/sellers'
|
11
|
+
require 'mws/subscriptions'
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'jeff'
|
3
|
+
|
4
|
+
module Peddler
|
5
|
+
class Client
|
6
|
+
extend Forwardable
|
7
|
+
include Jeff
|
8
|
+
|
9
|
+
attr_accessor :default_country, :merchant_id
|
10
|
+
|
11
|
+
def initialize(default_country = nil, aws_access_key_id = nil, aws_secret_access_key = nil, merchant_id = nil)
|
12
|
+
@default_country = default_country
|
13
|
+
@aws_access_key_id = aws_access_key_id || ENV['AWS_ACCESS_KEY_ID']
|
14
|
+
@aws_secret_access_key = aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY']
|
15
|
+
@merchant_id = merchant_id || ENV['MERCHANT_ID']
|
16
|
+
end
|
17
|
+
|
18
|
+
HOSTS = {
|
19
|
+
'CA' => 'mws.amazonservices.ca',
|
20
|
+
'CN' => 'mws.amazonservices.com.cn',
|
21
|
+
'DE' => 'mws-eu.amazonservices.com',
|
22
|
+
'ES' => 'mws-eu.amazonservices.com',
|
23
|
+
'FR' => 'mws-eu.amazonservices.com',
|
24
|
+
'GB' => 'mws-eu.amazonservices.com',
|
25
|
+
'IN' => 'mws.amazonservices.in',
|
26
|
+
'IT' => 'mws-eu.amazonservices.com',
|
27
|
+
'JP' => 'mws.amazonservices.jp',
|
28
|
+
'US' => 'mws.amazonservices.com'
|
29
|
+
}
|
30
|
+
|
31
|
+
MARKETPLACE_IDS = {
|
32
|
+
'CA' => 'A2EUQ1WTGCTBG2',
|
33
|
+
'CN' => 'AAHKV2X7AFYLW',
|
34
|
+
'DE' => 'A1PA6795UKMFR9',
|
35
|
+
'ES' => 'A1RKKUPIHCS9HS',
|
36
|
+
'FR' => 'A13V1IB3VIYZZH',
|
37
|
+
'GB' => 'A1F83G8C2ARO7P',
|
38
|
+
'IN' => 'A21TJRUUN4KGV',
|
39
|
+
'IT' => 'APJ6JRA9NG5V4',
|
40
|
+
'JP' => 'A1VC38T7YXB528',
|
41
|
+
'US' => 'ATVPDKIKX0DER'
|
42
|
+
}
|
43
|
+
|
44
|
+
def self.path(path = nil)
|
45
|
+
path ? @path = path : @path
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.inherited(base)
|
49
|
+
base.params(params)
|
50
|
+
end
|
51
|
+
|
52
|
+
params('SellerId' => -> { merchant_id })
|
53
|
+
|
54
|
+
def endpoint
|
55
|
+
"https://#{HOSTS.fetch(default_country)}/#{self.class.path}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def marketplace_id(country = default_country)
|
59
|
+
MARKETPLACE_IDS.fetch(country)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'peddler/parsers/xml'
|
2
|
+
|
3
|
+
module Peddler
|
4
|
+
module Parsers
|
5
|
+
class Collection < XML
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
def each
|
9
|
+
raise NotImplementedError
|
10
|
+
end
|
11
|
+
|
12
|
+
def empty?
|
13
|
+
count == 0
|
14
|
+
end
|
15
|
+
|
16
|
+
def inspect
|
17
|
+
"#<#{self.class} (#{count})>"
|
18
|
+
end
|
19
|
+
|
20
|
+
alias :to_s :inspect
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'time'
|
3
|
+
require 'money'
|
4
|
+
require 'structure'
|
5
|
+
|
6
|
+
require 'peddler/parsers/xml'
|
7
|
+
|
8
|
+
module Peddler
|
9
|
+
module Parsers
|
10
|
+
class Model < XML
|
11
|
+
include Structure
|
12
|
+
|
13
|
+
def float_at_xpath(path)
|
14
|
+
str = text_at_xpath(path)
|
15
|
+
str.to_f if str
|
16
|
+
end
|
17
|
+
|
18
|
+
def integer_at_xpath(path)
|
19
|
+
str = text_at_xpath(path)
|
20
|
+
str.to_i if str
|
21
|
+
end
|
22
|
+
|
23
|
+
def money_at_xpath(path)
|
24
|
+
return unless amount = float_at_xpath("#{path}/Amount")
|
25
|
+
|
26
|
+
currency_code = text_at_xpath("#{path}/CurrencyCode")
|
27
|
+
amount = amount * 100 unless currency_code == 'JPY'
|
28
|
+
|
29
|
+
Money.new(amount, currency_code)
|
30
|
+
end
|
31
|
+
|
32
|
+
def text_at_xpath(path)
|
33
|
+
node = at_xpath(path)
|
34
|
+
node.text if node
|
35
|
+
end
|
36
|
+
|
37
|
+
def time_at_xpath(path)
|
38
|
+
str = text_at_xpath(path)
|
39
|
+
Time.parse(CGI.unescape(str)) if str
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|