mws-orders 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +13 -9
  3. data/lib/mws/orders/collection.rb +10 -10
  4. data/lib/mws/orders/document.rb +4 -2
  5. data/lib/mws/orders/entity.rb +13 -10
  6. data/lib/mws/orders/invoice_data.rb +7 -5
  7. data/lib/mws/orders/message.rb +17 -0
  8. data/lib/mws/orders/order.rb +40 -32
  9. data/lib/mws/orders/order_item.rb +33 -27
  10. data/lib/mws/orders/order_items.rb +7 -5
  11. data/lib/mws/orders/orders.rb +7 -5
  12. data/lib/mws/orders/parser.rb +49 -24
  13. data/lib/mws/orders/payment_execution_detail.rb +8 -4
  14. data/lib/mws/orders/payment_execution_detail_item.rb +5 -3
  15. data/lib/mws/orders/service_status.rb +8 -6
  16. data/lib/mws/orders/shipping_address.rb +9 -7
  17. data/lib/mws/orders/tokenable.rb +3 -1
  18. data/lib/mws/orders/version.rb +3 -1
  19. data/test/fixtures/orders.xml +4 -1
  20. data/test/mws/orders/test_entity.rb +44 -42
  21. data/test/mws/orders/test_message.rb +18 -0
  22. data/test/mws/orders/test_order.rb +16 -2
  23. data/test/mws/orders/test_order_item.rb +8 -2
  24. data/test/mws/orders/test_order_items.rb +4 -2
  25. data/test/mws/orders/test_orders.rb +4 -2
  26. data/test/mws/orders/test_parser.rb +3 -1
  27. data/test/mws/orders/test_payment_execution_detail.rb +6 -2
  28. data/test/mws/orders/test_payment_execution_detail_item.rb +5 -2
  29. data/test/mws/orders/test_service_status.rb +6 -2
  30. data/test/mws/orders/test_shipping_address.rb +4 -2
  31. data/test/mws/orders/test_tokenable.rb +8 -6
  32. data/test/test_helper.rb +12 -9
  33. metadata +70 -33
  34. data/lib/mws-orders.rb +0 -2
  35. data/lib/mws/orders/service_status_message.rb +0 -15
  36. data/test/integration/test_mws_orders.rb +0 -27
  37. data/test/mws/orders/test_service_status_message.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7e5fc7496851e79217521eef0d282505343a3704
4
- data.tar.gz: 8342dc83d8146fc0a64af2f002fc4754280c6610
2
+ SHA256:
3
+ metadata.gz: 5024482ae6bb34ce7a6066333ab17e2bad0c8cd98330ef2d17710c843114c1bb
4
+ data.tar.gz: 2d2235a1ccd194a58cfb162d4cd89990e3878a232c62b0c7325f30d595dd0cf4
5
5
  SHA512:
6
- metadata.gz: 5a7dc5870c74393acd3d40d24c32aa0cd5f495e2e83f7a823f5014d9acf9646bd903563f432f3b19af4e909ae81beb006c5426789215f02c20c684fd1a47c058
7
- data.tar.gz: c74b2533d707cc1ca6e63e308db703c4f827ab037d3f831108db99faf122172e99c757d2e20238f57f3f98e5941e5ff573715151fe85d630517b7d77302d2c4b
6
+ metadata.gz: a0e92ba47bfc2feb5513324f22a60abd078528c327e1be3e22a0d27940f7f45d5917e3708cbda335967d3cb2cbffe9364a4677f359af01d698c897d6c4b52883
7
+ data.tar.gz: 75677d6f12e108daf1331ba3d18b5d2c54717abd79a85999e68545a13f18773a8804577d5d063710e2fdba7a6b8a151d4b3035f795774f9c3d55bf86d43b9747
data/README.md CHANGED
@@ -11,18 +11,20 @@ To use Amazon MWS, you must have an eligible seller account.
11
11
  Create a client:
12
12
 
13
13
  ```ruby
14
- require "mws-orders"
15
- client = MWS.orders
14
+ require 'mws/orders/parser'
15
+ client = MWS.orders(marketplace: 'ATVPDKIKX0DER',
16
+ merchant_id: '123')
16
17
  ```
17
18
 
18
- Set up credentials [when instantiating or with environment variables](https://github.com/hakanensari/peddler#quick-start).
19
+ Set up credentials [when instantiating or with environment variables](https://github.com/hakanensari/peddler#usage).
19
20
 
20
21
  ### Orders
21
22
 
22
23
  List orders created or updated during a time frame you specify:
23
24
 
24
25
  ```ruby
25
- orders = client.list_orders(created_after: 1.month.ago)
26
+ response = client.list_orders(created_after: 1.month.ago)
27
+ orders = response.parse
26
28
  puts orders.count # => 100
27
29
  puts orders.first # => #<MWS::Orders::Order amazon_order_id="123...
28
30
  )
@@ -31,13 +33,14 @@ puts orders.first # => #<MWS::Orders::Order amazon_order_id="123...
31
33
  List the next page of orders:
32
34
 
33
35
  ```ruby
34
- client.list_orders_by_next_token(orders.next_token)
36
+ client.list_orders_by_next_token(orders.next_token).parse
35
37
  ```
36
38
 
37
39
  Get one or more orders based on their order numbers:
38
40
 
39
41
  ```ruby
40
- order = client.get_order("123-1234567-1234567")
42
+ response = client.get_order('123-1234567-1234567')
43
+ order = response.parse
41
44
  puts order # => #<MWS::Orders::Order amazon_order_id="123...
42
45
  ```
43
46
 
@@ -46,13 +49,14 @@ puts order # => #<MWS::Orders::Order amazon_order_id="123...
46
49
  List order items:
47
50
 
48
51
  ```ruby
49
- order_items = client.list_order_items("123-1234567-1234567")
52
+ response = client.list_order_items('123-1234567-1234567')
53
+ order_items = response.parse
50
54
  ```
51
55
 
52
56
  List the next page of order items:
53
57
 
54
58
  ```ruby
55
- client.list_order_items_by_next_token
59
+ client.list_order_items_by_next_token.parse
56
60
  ```
57
61
 
58
62
  Orders and order items are represented by POROs that map one on one to the attributes returned by the API.
@@ -62,5 +66,5 @@ Orders and order items are represented by POROs that map one on one to the attri
62
66
  Check the operational status of the API:
63
67
 
64
68
  ```ruby
65
- client.get_service_status
69
+ client.get_service_status.parse
66
70
  ```
@@ -1,4 +1,6 @@
1
- require "mws/orders/document"
1
+ # frozen_string_literal: true
2
+
3
+ require 'mws/orders/document'
2
4
 
3
5
  module MWS
4
6
  module Orders
@@ -10,20 +12,18 @@ module MWS
10
12
  end
11
13
 
12
14
  def empty?
13
- count == 0
15
+ count.zero?
16
+ end
17
+
18
+ def attributes
19
+ map(&:attributes)
14
20
  end
15
21
 
16
22
  def inspect
17
- "#<#{self.class} #{
18
- if count > 3
19
- "[#{take(3).map(&:inspect).join(', ')}...]"
20
- else
21
- "[#{map(&:inspect).join(', ')}]"
22
- end
23
- }>"
23
+ "#<#{self.class.name} #{to_a}>"
24
24
  end
25
25
 
26
- alias_method :to_s, :inspect
26
+ alias to_s inspect
27
27
  end
28
28
  end
29
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MWS
2
4
  module Orders
3
5
  class Document
@@ -15,9 +17,9 @@ module MWS
15
17
 
16
18
  def add_namespace(path)
17
19
  path
18
- .split("/")
20
+ .split('/')
19
21
  .map { |attr| "xmlns:#{attr}" }
20
- .join("/")
22
+ .join('/')
21
23
  end
22
24
  end
23
25
  end
@@ -1,8 +1,10 @@
1
- require "cgi"
2
- require "time"
3
- require "money"
4
- require "structure"
5
- require "mws/orders/document"
1
+ # frozen_string_literal: true
2
+
3
+ require 'cgi'
4
+ require 'time'
5
+ require 'money'
6
+ require 'structure'
7
+ require 'mws/orders/document'
6
8
 
7
9
  module MWS
8
10
  module Orders
@@ -11,19 +13,20 @@ module MWS
11
13
 
12
14
  def float_at_xpath(path)
13
15
  text = text_at_xpath(path)
14
- text.to_f if text
16
+ text&.to_f
15
17
  end
16
18
 
17
19
  def integer_at_xpath(path)
18
20
  text = text_at_xpath(path)
19
- text.to_i if text
21
+ text&.to_i
20
22
  end
21
23
 
22
24
  def money_at_xpath(path)
23
- return unless amount = float_at_xpath("#{path}/Amount")
25
+ amount = float_at_xpath("#{path}/Amount")
26
+ return unless amount
24
27
 
25
28
  currency_code = text_at_xpath("#{path}/CurrencyCode")
26
- amount = amount * 100 unless currency_code == "JPY"
29
+ amount *= 100 unless currency_code == 'JPY'
27
30
 
28
31
  Money.new(amount, currency_code)
29
32
  end
@@ -35,7 +38,7 @@ module MWS
35
38
 
36
39
  def text_at_xpath(path)
37
40
  node = xpath(path).first
38
- node.text.strip if node
41
+ node&.text&.strip
39
42
  end
40
43
  end
41
44
  end
@@ -1,22 +1,24 @@
1
- require "mws/orders/entity"
1
+ # frozen_string_literal: true
2
+
3
+ require 'mws/orders/entity'
2
4
 
3
5
  module MWS
4
6
  module Orders
5
7
  class InvoiceData < Entity
6
8
  attribute(:invoice_requirement) do
7
- text_at_xpath("InvoiceRequirement")
9
+ text_at_xpath('InvoiceRequirement')
8
10
  end
9
11
 
10
12
  attribute(:buyer_selected_invoice_category) do
11
- text_at_xpath("BuyerSelectedInvoiceCategory")
13
+ text_at_xpath('BuyerSelectedInvoiceCategory')
12
14
  end
13
15
 
14
16
  attribute(:invoice_title) do
15
- text_at_xpath("InvoiceTitle")
17
+ text_at_xpath('InvoiceTitle')
16
18
  end
17
19
 
18
20
  attribute(:invoice_information) do
19
- text_at_xpath("InvoiceInformation")
21
+ text_at_xpath('InvoiceInformation')
20
22
  end
21
23
  end
22
24
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mws/orders/entity'
4
+
5
+ module MWS
6
+ module Orders
7
+ class Message < Entity
8
+ attribute(:locale) do
9
+ text_at_xpath('Locale')
10
+ end
11
+
12
+ attribute(:text) do
13
+ text_at_xpath('Text')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,112 +1,120 @@
1
- require "mws/orders/entity"
2
- require "mws/orders/shipping_address"
3
- require "mws/orders/payment_execution_detail"
1
+ # frozen_string_literal: true
2
+
3
+ require 'mws/orders/entity'
4
+ require 'mws/orders/shipping_address'
5
+ require 'mws/orders/payment_execution_detail'
4
6
 
5
7
  module MWS
6
8
  module Orders
7
9
  class Order < Entity
8
10
  attribute(:amazon_order_id) do
9
- text_at_xpath("AmazonOrderId")
11
+ text_at_xpath('AmazonOrderId')
10
12
  end
11
13
 
12
14
  attribute(:seller_order_id) do
13
- text_at_xpath("SellerOrderId")
15
+ text_at_xpath('SellerOrderId')
14
16
  end
15
17
 
16
18
  attribute(:purchased_at) do
17
- time_at_xpath("PurchaseDate")
19
+ time_at_xpath('PurchaseDate')
18
20
  end
19
21
 
20
22
  attribute(:last_updated_at) do
21
- time_at_xpath("LastUpdateDate")
23
+ time_at_xpath('LastUpdateDate')
22
24
  end
23
25
 
24
26
  attribute(:status) do
25
- text_at_xpath("OrderStatus")
27
+ text_at_xpath('OrderStatus')
26
28
  end
27
29
 
28
30
  attribute(:fulfillment_channel) do
29
- text_at_xpath("FulfillmentChannel")
31
+ text_at_xpath('FulfillmentChannel')
30
32
  end
31
33
 
32
34
  attribute(:sales_channel) do
33
- text_at_xpath("SalesChannel")
35
+ text_at_xpath('SalesChannel')
34
36
  end
35
37
 
36
38
  attribute(:order_channel) do
37
- text_at_xpath("OrderChannel")
39
+ text_at_xpath('OrderChannel')
38
40
  end
39
41
 
40
42
  attribute(:ship_service_level) do
41
- text_at_xpath("ShipServiceLevel")
43
+ text_at_xpath('ShipServiceLevel')
42
44
  end
43
45
 
44
46
  attribute(:shipping_address) do
45
- if node = xpath("ShippingAddress").first
46
- ShippingAddress.new(node)
47
- end
47
+ node = xpath('ShippingAddress').first
48
+ ShippingAddress.new(node) if node
48
49
  end
49
50
 
50
51
  attribute(:total) do
51
- money_at_xpath("OrderTotal")
52
+ money_at_xpath('OrderTotal')
52
53
  end
53
54
 
54
55
  attribute(:number_of_items_shipped) do
55
- integer_at_xpath("NumberOfItemsShipped")
56
+ integer_at_xpath('NumberOfItemsShipped')
56
57
  end
57
58
 
58
59
  attribute(:number_of_items_unshipped) do
59
- integer_at_xpath("NumberOfItemsUnshipped")
60
+ integer_at_xpath('NumberOfItemsUnshipped')
60
61
  end
61
62
 
62
63
  attribute(:payment_execution_detail) do
63
- if node = xpath("PaymentExecutionDetail").first
64
- PaymentExecutionDetail.new(node)
65
- end
64
+ node = xpath('PaymentExecutionDetail').first
65
+ PaymentExecutionDetail.new(node) if node
66
66
  end
67
67
 
68
68
  attribute(:payment_method) do
69
- text_at_xpath("PaymentMethod")
69
+ text_at_xpath('PaymentMethod')
70
70
  end
71
71
 
72
72
  attribute(:marketplace_id) do
73
- text_at_xpath("MarketplaceId")
73
+ text_at_xpath('MarketplaceId')
74
74
  end
75
75
 
76
76
  attribute(:buyer_name) do
77
- text_at_xpath("BuyerName")
77
+ text_at_xpath('BuyerName')
78
78
  end
79
79
 
80
80
  attribute(:buyer_email) do
81
- text_at_xpath("BuyerEmail")
81
+ text_at_xpath('BuyerEmail')
82
82
  end
83
83
 
84
84
  attribute(:shipment_service_level_category) do
85
- text_at_xpath("ShipmentServiceLevelCategory")
85
+ text_at_xpath('ShipmentServiceLevelCategory')
86
86
  end
87
87
 
88
88
  attribute(:cba_displayable_shipping_label) do
89
- text_at_xpath("CbaDisplayableShippingLabel")
89
+ text_at_xpath('CbaDisplayableShippingLabel')
90
90
  end
91
91
 
92
92
  attribute(:shipped_by_amazon_tfm) do
93
- text_at_xpath("ShippedByAmazonTFM")
93
+ text_at_xpath('ShippedByAmazonTFM')
94
94
  end
95
95
 
96
96
  attribute(:tfm_shipment_status) do
97
- text_at_xpath("TFMShipmentStatus")
97
+ text_at_xpath('TFMShipmentStatus')
98
98
  end
99
99
 
100
100
  attribute(:type) do
101
- text_at_xpath("OrderType")
101
+ text_at_xpath('OrderType')
102
102
  end
103
103
 
104
104
  attribute(:earliest_shipped_at) do
105
- time_at_xpath("EarliestShipDate")
105
+ time_at_xpath('EarliestShipDate')
106
106
  end
107
107
 
108
108
  attribute(:latest_shipped_at) do
109
- time_at_xpath("LatestShipDate")
109
+ time_at_xpath('LatestShipDate')
110
+ end
111
+
112
+ attribute(:latest_delivered_at) do
113
+ time_at_xpath('LatestDeliveryDate')
114
+ end
115
+
116
+ def to_s
117
+ amazon_order_id
110
118
  end
111
119
  end
112
120
  end
@@ -1,107 +1,113 @@
1
- require "mws/orders/entity"
2
- require "mws/orders/invoice_data"
1
+ # frozen_string_literal: true
2
+
3
+ require 'mws/orders/entity'
4
+ require 'mws/orders/invoice_data'
3
5
 
4
6
  module MWS
5
7
  module Orders
6
8
  class OrderItem < Entity
7
9
  attribute(:asin) do
8
- text_at_xpath("ASIN")
10
+ text_at_xpath('ASIN')
9
11
  end
10
12
 
11
13
  attribute(:seller_sku) do
12
- text_at_xpath("SellerSKU")
14
+ text_at_xpath('SellerSKU')
13
15
  end
14
16
 
15
17
  attribute(:order_item_id) do
16
- text_at_xpath("OrderItemId")
18
+ text_at_xpath('OrderItemId')
17
19
  end
18
20
 
19
21
  attribute(:title) do
20
- text_at_xpath("Title")
22
+ text_at_xpath('Title')
21
23
  end
22
24
 
23
25
  attribute(:quantity_ordered) do
24
- integer_at_xpath("QuantityOrdered")
26
+ integer_at_xpath('QuantityOrdered')
25
27
  end
26
28
 
27
29
  attribute(:quantity_shipped) do
28
- integer_at_xpath("QuantityShipped")
30
+ integer_at_xpath('QuantityShipped')
29
31
  end
30
32
 
31
33
  attribute(:gift_message_text) do
32
- text_at_xpath("GiftMessageText")
34
+ text_at_xpath('GiftMessageText')
33
35
  end
34
36
 
35
37
  attribute(:gift_wrap_level) do
36
- text_at_xpath("GiftWrapLevel")
38
+ text_at_xpath('GiftWrapLevel')
37
39
  end
38
40
 
39
41
  attribute(:item_price) do
40
- money_at_xpath("ItemPrice")
42
+ money_at_xpath('ItemPrice')
41
43
  end
42
44
 
43
45
  attribute(:shipping_price) do
44
- money_at_xpath("ShippingPrice")
46
+ money_at_xpath('ShippingPrice')
45
47
  end
46
48
 
47
49
  attribute(:gift_wrap_price) do
48
- money_at_xpath("GiftWrapPrice")
50
+ money_at_xpath('GiftWrapPrice')
49
51
  end
50
52
 
51
53
  attribute(:item_tax) do
52
- money_at_xpath("ItemTax")
54
+ money_at_xpath('ItemTax')
53
55
  end
54
56
 
55
57
  attribute(:shipping_tax) do
56
- money_at_xpath("ShippingTax")
58
+ money_at_xpath('ShippingTax')
57
59
  end
58
60
 
59
61
  attribute(:gift_wrap_tax) do
60
- money_at_xpath("GiftWrapPrice")
62
+ money_at_xpath('GiftWrapPrice')
61
63
  end
62
64
 
63
65
  attribute(:shipping_discount) do
64
- money_at_xpath("ShippingDiscount")
66
+ money_at_xpath('ShippingDiscount')
65
67
  end
66
68
 
67
69
  attribute(:promotion_discount) do
68
- money_at_xpath("PromotionDiscount")
70
+ money_at_xpath('PromotionDiscount')
69
71
  end
70
72
 
71
73
  attribute(:promotion_ids) do
72
- xpath("PromotionId").map(&:text)
74
+ xpath('PromotionId').map(&:text)
73
75
  end
74
76
 
75
77
  attribute(:cod_fee) do
76
- money_at_xpath("CODFee")
78
+ money_at_xpath('CODFee')
77
79
  end
78
80
 
79
81
  attribute(:cod_fee_discount) do
80
- money_at_xpath("CODFeeDiscount")
82
+ money_at_xpath('CODFeeDiscount')
81
83
  end
82
84
 
83
85
  attribute(:invoice_data) do
84
- xpath("InvoiceData").map { |node| InvoiceData.new(node) }
86
+ xpath('InvoiceData').map { |node| InvoiceData.new(node) }
85
87
  end
86
88
 
87
89
  attribute(:condition_id) do
88
- text_at_xpath("ConditionId")
90
+ text_at_xpath('ConditionId')
89
91
  end
90
92
 
91
93
  attribute(:condition_subtype_id) do
92
- text_at_xpath("ConditionSubtypeId")
94
+ text_at_xpath('ConditionSubtypeId')
93
95
  end
94
96
 
95
97
  attribute(:condition_note) do
96
- text_at_xpath("ConditionNote")
98
+ text_at_xpath('ConditionNote')
97
99
  end
98
100
 
99
101
  attribute(:scheduled_delivery_ends_at) do
100
- time_at_xpath("ScheduledDeliveryEndDate")
102
+ time_at_xpath('ScheduledDeliveryEndDate')
101
103
  end
102
104
 
103
105
  attribute(:scheduled_delivery_starts_at) do
104
- time_at_xpath("ScheduledDeliveryStartDate")
106
+ time_at_xpath('ScheduledDeliveryStartDate')
107
+ end
108
+
109
+ def to_s
110
+ order_item_id
105
111
  end
106
112
  end
107
113
  end