peddler 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +237 -8
  3. data/lib/mws/feeds.rb +1 -0
  4. data/lib/mws/feeds/client.rb +97 -0
  5. data/lib/mws/feeds/parsers/feed.rb +14 -0
  6. data/lib/mws/feeds/parsers/feed_submission.rb +25 -0
  7. data/lib/mws/feeds/parsers/feed_submission_count.rb +13 -0
  8. data/lib/mws/feeds/parsers/feed_submission_list.rb +20 -0
  9. data/lib/mws/feeds/parsers/feed_submission_result.rb +10 -0
  10. data/lib/mws/feeds/parsers/feed_submissions.rb +18 -0
  11. data/lib/mws/feeds/requests/feed.rb +38 -0
  12. data/lib/mws/feeds/requests/feed_submission_count.rb +20 -0
  13. data/lib/mws/feeds/requests/feed_submission_list.rb +28 -0
  14. data/lib/mws/feeds/requests/feed_submission_result.rb +18 -0
  15. data/lib/mws/feeds/requests/feed_submissions.rb +20 -0
  16. data/lib/mws/fulfillment_inbound_shipment/client.rb +7 -0
  17. data/lib/mws/fulfillment_inventory/client.rb +7 -0
  18. data/lib/mws/fulfillment_outbound_shipment/client.rb +7 -0
  19. data/lib/mws/off_amazon_payments/client.rb +7 -0
  20. data/lib/mws/orders.rb +1 -0
  21. data/lib/mws/orders/client.rb +88 -0
  22. data/lib/mws/orders/parsers/invoice_data.rb +25 -0
  23. data/lib/mws/orders/parsers/order.rb +113 -0
  24. data/lib/mws/orders/parsers/order_item.rb +110 -0
  25. data/lib/mws/orders/parsers/order_items.rb +20 -0
  26. data/lib/mws/orders/parsers/orders.rb +20 -0
  27. data/lib/mws/orders/parsers/payment_execution_detail.rb +20 -0
  28. data/lib/mws/orders/parsers/payment_execution_detail_item.rb +17 -0
  29. data/lib/mws/orders/parsers/service_status.rb +36 -0
  30. data/lib/mws/orders/parsers/service_status_message.rb +17 -0
  31. data/lib/mws/orders/parsers/shipping_address.rb +37 -0
  32. data/lib/mws/orders/requests/order_items.rb +26 -0
  33. data/lib/mws/orders/requests/orders.rb +39 -0
  34. data/lib/mws/orders/requests/service_status.rb +15 -0
  35. data/lib/mws/products/client.rb +7 -0
  36. data/lib/mws/recommendations/client.rb +7 -0
  37. data/lib/mws/reports/client.rb +6 -0
  38. data/lib/mws/sellers/client.rb +7 -0
  39. data/lib/mws/subscriptions/client.rb +7 -0
  40. data/lib/peddler.rb +11 -1
  41. data/lib/peddler/client.rb +62 -0
  42. data/lib/peddler/parsers/base.rb +15 -0
  43. data/lib/peddler/parsers/collection.rb +23 -0
  44. data/lib/peddler/parsers/model.rb +43 -0
  45. data/lib/peddler/parsers/text.rb +13 -0
  46. data/lib/peddler/parsers/xml.rb +25 -0
  47. data/lib/peddler/request.rb +50 -0
  48. data/lib/peddler/request/parameters.rb +56 -0
  49. data/lib/peddler/request/structured_list.rb +43 -0
  50. data/lib/peddler/response_wrapper.rb +32 -0
  51. data/lib/peddler/version.rb +1 -1
  52. data/test/fixtures/feeds/feed_submission.xml +14 -0
  53. data/test/fixtures/feeds/feed_submission_count.xml +9 -0
  54. data/test/fixtures/feeds/feed_submission_list.xml +17 -0
  55. data/test/fixtures/feeds/feed_submissions.xml +15 -0
  56. data/test/fixtures/mws.yml +8 -0
  57. data/test/fixtures/mws.yml.example +4 -0
  58. data/test/fixtures/orders/order_items.xml +83 -0
  59. data/test/fixtures/orders/orders.xml +109 -0
  60. data/test/fixtures/orders/service_status.xml +19 -0
  61. data/test/helper.rb +5 -0
  62. data/test/integration/feeds/test_feed_submission_count.rb +13 -0
  63. data/test/integration/feeds/test_feed_submission_list.rb +15 -0
  64. data/test/integration/feeds/test_feed_submission_result.rb +15 -0
  65. data/test/integration/orders/test_order_items.rb +19 -0
  66. data/test/integration/orders/test_orders.rb +20 -0
  67. data/test/integration/orders/test_service_status.rb +12 -0
  68. data/test/integration_helper.rb +16 -0
  69. data/test/mws/feeds/parsers/test_feed.rb +13 -0
  70. data/test/mws/feeds/parsers/test_feed_submission.rb +25 -0
  71. data/test/mws/feeds/parsers/test_feed_submission_count.rb +13 -0
  72. data/test/mws/feeds/parsers/test_feed_submission_list.rb +14 -0
  73. data/test/mws/feeds/parsers/test_feed_submission_result.rb +13 -0
  74. data/test/mws/feeds/parsers/test_feed_submissions.rb +17 -0
  75. data/test/mws/feeds/requests/test_feed.rb +63 -0
  76. data/test/mws/feeds/requests/test_feed_submission_count.rb +23 -0
  77. data/test/mws/feeds/requests/test_feed_submission_list.rb +40 -0
  78. data/test/mws/feeds/requests/test_feed_submissions.rb +29 -0
  79. data/test/mws/orders/parsers/test_order.rb +86 -0
  80. data/test/mws/orders/parsers/test_order_item.rb +69 -0
  81. data/test/mws/orders/parsers/test_order_items.rb +14 -0
  82. data/test/mws/orders/parsers/test_orders.rb +14 -0
  83. data/test/mws/orders/parsers/test_payment_execution_detail.rb +14 -0
  84. data/test/mws/orders/parsers/test_payment_execution_detail_item.rb +17 -0
  85. data/test/mws/orders/parsers/test_service_status.rb +39 -0
  86. data/test/mws/orders/parsers/test_service_status_message.rb +17 -0
  87. data/test/mws/orders/parsers/test_shipping_address.rb +36 -0
  88. data/test/mws/orders/requests/test_order_items.rb +39 -0
  89. data/test/mws/orders/requests/test_orders.rb +49 -0
  90. data/test/mws/orders/requests/test_service_status.rb +25 -0
  91. data/test/parser_helper.rb +11 -0
  92. data/test/peddler/parsers/test_collection.rb +8 -0
  93. data/test/peddler/parsers/test_model.rb +34 -0
  94. data/test/peddler/request/test_parameters.rb +35 -0
  95. data/test/peddler/request/test_structured_list.rb +18 -0
  96. data/test/peddler/test_client.rb +42 -0
  97. data/test/request_helper.rb +20 -0
  98. metadata +213 -10
  99. data/lib/peddler/apis.rb +0 -45
  100. data/lib/peddler/service.rb +0 -83
  101. data/test/service_test.rb +0 -42
  102. 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
@@ -0,0 +1,7 @@
1
+ module MWS
2
+ module Products
3
+ class Client < ::Peddler::Client
4
+ path 'Products/2011-10-01'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module MWS
2
+ module Recommendations
3
+ class Client < ::Peddler::Client
4
+ path 'Recommendations/2013-04-01'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module MWS
2
+ module Reports
3
+ class Client < ::Peddler::Client
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module MWS
2
+ module Sellers
3
+ class Client < ::Peddler::Client
4
+ path 'Sellers/2011-07-01'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module MWS
2
+ module Subscriptions
3
+ class Client < ::Peddler::Client
4
+ path 'Subscriptions/2013-07-01'
5
+ end
6
+ end
7
+ end
data/lib/peddler.rb CHANGED
@@ -1 +1,11 @@
1
- require 'peddler/apis'
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,15 @@
1
+ module Peddler
2
+ module Parsers
3
+ class Base
4
+ def self.handle?(type)
5
+ raise NotImplementedError
6
+ end
7
+
8
+ attr :document
9
+
10
+ def initialize(document)
11
+ @document = document
12
+ end
13
+ end
14
+ end
15
+ 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