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,10 @@
1
+ require 'peddler/parsers/text'
2
+
3
+ module MWS
4
+ module Feeds
5
+ module Parsers
6
+ class FeedSubmissionResult < ::Peddler::Parsers::Text
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ require 'peddler/parsers/model'
2
+ require 'mws/feeds/parsers/feed_submission'
3
+
4
+ module MWS
5
+ module Feeds
6
+ module Parsers
7
+ class FeedSubmissions < ::Peddler::Parsers::Model
8
+ value :count do
9
+ integer_at_xpath('Count')
10
+ end
11
+
12
+ def feed_submissions
13
+ xpath('FeedSubmissionInfo').map { |node| FeedSubmission.new(node) }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,38 @@
1
+ require 'peddler/request'
2
+ require 'mws/feeds/parsers/feed'
3
+
4
+ module MWS
5
+ module Feeds
6
+ module Requests
7
+ class Feed < ::Peddler::Request
8
+ def submit(content, type, options = {})
9
+ self.body = content
10
+ set_content_type
11
+ parameters(:submit_feed)
12
+ .update(feed_type: type)
13
+ .update(options)
14
+ .format_structured_lists!
15
+ .camelize_keys!
16
+
17
+ execute
18
+ end
19
+
20
+ def set_content_type
21
+ headers['Content-Type'] =
22
+ if body.start_with?('<?xml')
23
+ 'text/xml; charset=ISO-8859-1'
24
+ else
25
+ case client.default_country
26
+ when 'JP'
27
+ 'text/tab-separated-values; charset=Shift_JIS'
28
+ when 'CN'
29
+ 'text/tab-separated-values; charset=UTF-16'
30
+ else
31
+ 'text/tab-separated-values; charset=ISO-8859-1'
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ require 'peddler/request'
2
+ require 'mws/feeds/parsers/feed_submission_count'
3
+
4
+ module MWS
5
+ module Feeds
6
+ module Requests
7
+ class FeedSubmissionCount < ::Peddler::Request
8
+ def get(options = {})
9
+ parameters(:get_feed_submission_count)
10
+ .update(options)
11
+ .timestamp!
12
+ .format_structured_lists!
13
+ .camelize_keys!
14
+
15
+ execute
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ require 'peddler/request'
2
+ require 'mws/feeds/parsers/feed_submission_list'
3
+
4
+ module MWS
5
+ module Feeds
6
+ module Requests
7
+ class FeedSubmissionList < ::Peddler::Request
8
+ def get(options = {})
9
+ parameters(:get_feed_submission_list)
10
+ .update(options)
11
+ .timestamp!
12
+ .format_structured_lists!
13
+ .camelize_keys!
14
+
15
+ execute
16
+ end
17
+
18
+ def get_by_next_token
19
+ parameters(:get_feed_submission_list_by_next_token)
20
+ .update(next_token: next_token)
21
+ .camelize_keys!
22
+
23
+ execute
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ require 'peddler/request'
2
+ require 'mws/feeds/parsers/feed_submission_result'
3
+
4
+ module MWS
5
+ module Feeds
6
+ module Requests
7
+ class FeedSubmissionResult < ::Peddler::Request
8
+ def get(feed_submission_id)
9
+ parameters(:get_feed_submission_result)
10
+ .update(feed_submission_id: feed_submission_id)
11
+ .camelize_keys!
12
+
13
+ execute
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require 'peddler/request'
2
+ require 'mws/feeds/parsers/feed_submissions'
3
+
4
+ module MWS
5
+ module Feeds
6
+ module Requests
7
+ class FeedSubmissions < ::Peddler::Request
8
+ def cancel(options = {})
9
+ parameters(:cancel_feed_submissions)
10
+ .update(options)
11
+ .timestamp!
12
+ .format_structured_lists!
13
+ .camelize_keys!
14
+
15
+ execute
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module MWS
2
+ module FulfillmentInboundShipment
3
+ class Client < ::Peddler::Client
4
+ path 'FulfillmentInboundShipment/2010-10-01'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module MWS
2
+ module FulfillmentInventory
3
+ class Client < ::Peddler::Client
4
+ path 'FulfillmentInventory/2010-10-01'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module MWS
2
+ module FulfillmentOutboundShipment
3
+ class Client < ::Peddler::Client
4
+ path 'FulfillmentOutboundShipment/2010-10-01'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module MWS
2
+ module OffAmazonPayments
3
+ class Client < ::Peddler::Client
4
+ path 'OffAmazonPayments/2013-01-01/'
5
+ end
6
+ end
7
+ end
data/lib/mws/orders.rb ADDED
@@ -0,0 +1 @@
1
+ require 'mws/orders/client'
@@ -0,0 +1,88 @@
1
+ require 'mws/orders/requests/orders'
2
+ require 'mws/orders/requests/order_items'
3
+ require 'mws/orders/requests/service_status'
4
+ require 'peddler/client'
5
+
6
+ module MWS
7
+ module Orders
8
+ class Client < ::Peddler::Client
9
+ path 'Orders/2011-01-01'
10
+
11
+ # Public: Get one or more orders.
12
+ #
13
+ # amazon_order_ids - One or more String Amazon order ids.
14
+ #
15
+ # Examples
16
+ #
17
+ # client.get_order('123-1234567-1234567')
18
+ #
19
+ # Returns an enumerable list of Orders.
20
+ def_delegator :orders, :get, :get_order
21
+
22
+ # Public: List orders created or updated during a specified time frame.
23
+ #
24
+ # options - The Hash query parameters used to narrow the list. Refer to
25
+ # the MWS Orders API for available parameters.
26
+ #
27
+ # Examples
28
+ #
29
+ # client.list_orders(created_after: 1.week.ago)
30
+ #
31
+ # Returns an enumerable list of Orders.
32
+ def_delegator :orders, :list, :list_orders
33
+
34
+ # Public: List the next page of orders using the NextToken parameter.
35
+ #
36
+ # Examples
37
+ #
38
+ # client.list_orders_by_next_token
39
+ #
40
+ # Returns an enumerable list of Orders.
41
+ def_delegator :orders, :list_by_next_token, :list_orders_by_next_token
42
+
43
+ # Public: List order items for an amazon order.
44
+ #
45
+ # amazon_order_id - The String Amazon order id.
46
+ #
47
+ # Examples
48
+ #
49
+ # client.list_order_items('123-1234567-1234567')
50
+ #
51
+ # Returns an enumerable list of Order Items.
52
+ def_delegator :order_items, :list, :list_order_items
53
+
54
+ # Public: List the next page of order items using the NextToken
55
+ # parameter.
56
+ #
57
+ # Examples
58
+ #
59
+ # client.list_order_items_by_next_token
60
+ #
61
+ # Returns an enumerable list of Order Items.
62
+ def_delegator :order_items, :list_by_next_token, :list_order_items_by_next_token
63
+
64
+ # Public: Get the service status of the API.
65
+ #
66
+ # Examples
67
+ #
68
+ # client.get_service_status
69
+ #
70
+ # Returns the Service Status.
71
+ def_delegator :service_status, :get, :get_service_status
72
+
73
+ private
74
+
75
+ def orders
76
+ @orders ||= Requests::Orders.new(self)
77
+ end
78
+
79
+ def order_items
80
+ @order_items ||= Requests::OrderItems.new(self)
81
+ end
82
+
83
+ def service_status
84
+ @service_status ||= Requests::ServiceStatus.new(self)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,25 @@
1
+ require 'peddler/parsers/model'
2
+
3
+ module MWS
4
+ module Orders
5
+ module Parser
6
+ class InvoiceData < ::Peddler::Parsers::Model
7
+ value :invoice_requirement do
8
+ text_at_xpath('InvoiceRequirement')
9
+ end
10
+
11
+ value :buyer_selected_invoice_category do
12
+ text_at_xpath('BuyerSelectedInvoiceCategory')
13
+ end
14
+
15
+ value :invoice_title do
16
+ text_at_xpath('InvoiceTitle')
17
+ end
18
+
19
+ value :invoice_information do
20
+ text_at_xpath('InvoiceInformation')
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,113 @@
1
+ require 'mws/orders/parsers/shipping_address'
2
+ require 'mws/orders/parsers/payment_execution_detail'
3
+ require 'peddler/parsers/model'
4
+
5
+ module MWS
6
+ module Orders
7
+ module Parsers
8
+ class Order < ::Peddler::Parsers::Model
9
+ value :amazon_order_id do
10
+ text_at_xpath('AmazonOrderId')
11
+ end
12
+
13
+ value :seller_order_id do
14
+ text_at_xpath('SellerOrderId')
15
+ end
16
+
17
+ value :purchased_at do
18
+ time_at_xpath('PurchaseDate')
19
+ end
20
+
21
+ value :last_updated_at do
22
+ time_at_xpath('LastUpdateDate')
23
+ end
24
+
25
+ value :status do
26
+ text_at_xpath('OrderStatus')
27
+ end
28
+
29
+ value :fulfillment_channel do
30
+ text_at_xpath('FulfillmentChannel')
31
+ end
32
+
33
+ value :sales_channel do
34
+ text_at_xpath('SalesChannel')
35
+ end
36
+
37
+ value :order_channel do
38
+ text_at_xpath('OrderChannel')
39
+ end
40
+
41
+ value :ship_service_level do
42
+ text_at_xpath('ShipServiceLevel')
43
+ end
44
+
45
+ value :shipping_address do
46
+ node = at_xpath('ShippingAddress')
47
+ ShippingAddress.new(node) if node
48
+ end
49
+
50
+ value :total do
51
+ money_at_xpath('OrderTotal')
52
+ end
53
+
54
+ value :number_of_items_shipped do
55
+ integer_at_xpath('NumberOfItemsShipped')
56
+ end
57
+
58
+ value :number_of_items_unshipped do
59
+ integer_at_xpath('NumberOfItemsUnshipped')
60
+ end
61
+
62
+ value :payment_execution_detail do
63
+ node = at_xpath('PaymentExecutionDetail')
64
+ PaymentExecutionDetail.new(node) if node
65
+ end
66
+
67
+ value :payment_method do
68
+ text_at_xpath('PaymentMethod')
69
+ end
70
+
71
+ value :marketplace_id do
72
+ text_at_xpath('MarketplaceId')
73
+ end
74
+
75
+ value :buyer_name do
76
+ text_at_xpath('BuyerName')
77
+ end
78
+
79
+ value :buyer_email do
80
+ text_at_xpath('BuyerEmail')
81
+ end
82
+
83
+ value :shipment_service_level_category do
84
+ text_at_xpath('ShipmentServiceLevelCategory')
85
+ end
86
+
87
+ value :cba_displayable_shipping_label do
88
+ text_at_xpath('CbaDisplayableShippingLabel')
89
+ end
90
+
91
+ value :shipped_by_amazon_tfm do
92
+ text_at_xpath('ShippedByAmazonTFM')
93
+ end
94
+
95
+ value :tfm_shipment_status do
96
+ text_at_xpath('TFMShipmentStatus')
97
+ end
98
+
99
+ value :type do
100
+ text_at_xpath('OrderType')
101
+ end
102
+
103
+ value :earliest_shipped_at do
104
+ time_at_xpath('EarliestShipDate')
105
+ end
106
+
107
+ value :latest_shipped_at do
108
+ time_at_xpath('LatestShipDate')
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,110 @@
1
+ require 'mws/orders/parsers/invoice_data'
2
+ require 'peddler/parsers/model'
3
+
4
+ module MWS
5
+ module Orders
6
+ module Parsers
7
+ class OrderItem < ::Peddler::Parsers::Model
8
+ value :asin do
9
+ text_at_xpath('ASIN')
10
+ end
11
+
12
+ value :seller_sku do
13
+ text_at_xpath('SellerSKU')
14
+ end
15
+
16
+ value :order_item_id do
17
+ text_at_xpath('OrderItemId')
18
+ end
19
+
20
+ value :title do
21
+ text_at_xpath('Title')
22
+ end
23
+
24
+ value :quantity_ordered do
25
+ integer_at_xpath('QuantityOrdered')
26
+ end
27
+
28
+ value :quantity_shipped do
29
+ integer_at_xpath('QuantityShipped')
30
+ end
31
+
32
+ value :gift_message_text do
33
+ text_at_xpath('GiftMessageText')
34
+ end
35
+
36
+ value :gift_wrap_level do
37
+ text_at_xpath('GiftWrapLevel')
38
+ end
39
+
40
+ value :item_price do
41
+ money_at_xpath('ItemPrice')
42
+ end
43
+
44
+ value :shipping_price do
45
+ money_at_xpath('ShippingPrice')
46
+ end
47
+
48
+ value :gift_wrap_price do
49
+ money_at_xpath('GiftWrapPrice')
50
+ end
51
+
52
+ value :item_tax do
53
+ money_at_xpath('ItemTax')
54
+ end
55
+
56
+ value :shipping_tax do
57
+ money_at_xpath('ShippingTax')
58
+ end
59
+
60
+ value :gift_wrap_tax do
61
+ money_at_xpath('GiftWrapPrice')
62
+ end
63
+
64
+ value :shipping_discount do
65
+ money_at_xpath('ShippingDiscount')
66
+ end
67
+
68
+ value :promotion_discount do
69
+ money_at_xpath('PromotionDiscount')
70
+ end
71
+
72
+ value :promotion_ids do
73
+ xpath('PromotionId').map(&:text)
74
+ end
75
+
76
+ value :cod_fee do
77
+ money_at_xpath('CODFee')
78
+ end
79
+
80
+ value :cod_fee_discount do
81
+ money_at_xpath('CODFeeDiscount')
82
+ end
83
+
84
+ value :invoice_data do
85
+ xpath('InvoiceData').map { |node| InvoiceData.new(node) }
86
+ end
87
+
88
+ value :condition_id do
89
+ text_at_xpath('ConditionId')
90
+ end
91
+
92
+ value :condition_subtype_id do
93
+ text_at_xpath('ConditionSubtypeId')
94
+ end
95
+
96
+ value :condition_note do
97
+ text_at_xpath('ConditionNote')
98
+ end
99
+
100
+ value :scheduled_delivery_ends_at do
101
+ time_at_xpath('ScheduledDeliveryEndDate')
102
+ end
103
+
104
+ value :scheduled_delivery_starts_at do
105
+ time_at_xpath('ScheduledDeliveryStartDate')
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end