mws-orders 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +3 -3
  4. data/lib/mws/orders/address.rb +38 -0
  5. data/lib/mws/orders/buyer_customized_info.rb +14 -0
  6. data/lib/mws/orders/buyer_tax_info.rb +23 -0
  7. data/lib/mws/orders/collection.rb +1 -0
  8. data/lib/mws/orders/document.rb +6 -4
  9. data/lib/mws/orders/entity.rb +26 -15
  10. data/lib/mws/orders/invoice_data.rb +5 -4
  11. data/lib/mws/orders/message.rb +3 -2
  12. data/lib/mws/orders/order.rb +82 -33
  13. data/lib/mws/orders/order_item.rb +67 -30
  14. data/lib/mws/orders/order_items.rb +1 -0
  15. data/lib/mws/orders/orders.rb +1 -0
  16. data/lib/mws/orders/parser.rb +6 -14
  17. data/lib/mws/orders/payment_execution_detail_item.rb +3 -2
  18. data/lib/mws/orders/points_granted.rb +18 -0
  19. data/lib/mws/orders/product_info.rb +14 -0
  20. data/lib/mws/orders/service_status.rb +4 -3
  21. data/lib/mws/orders/tax_classification.rb +18 -0
  22. data/lib/mws/orders/tax_collection.rb +18 -0
  23. data/lib/mws/orders/tokenable.rb +2 -2
  24. data/lib/mws/orders/version.rb +1 -1
  25. metadata +11 -38
  26. data/lib/mws/orders/payment_execution_detail.rb +0 -16
  27. data/lib/mws/orders/shipping_address.rb +0 -37
  28. data/test/fixtures/order_items.xml +0 -83
  29. data/test/fixtures/orders.xml +0 -112
  30. data/test/fixtures/service_status.xml +0 -19
  31. data/test/mws/orders/test_entity.rb +0 -96
  32. data/test/mws/orders/test_message.rb +0 -18
  33. data/test/mws/orders/test_order.rb +0 -99
  34. data/test/mws/orders/test_order_item.rb +0 -74
  35. data/test/mws/orders/test_order_items.rb +0 -21
  36. data/test/mws/orders/test_orders.rb +0 -21
  37. data/test/mws/orders/test_parser.rb +0 -9
  38. data/test/mws/orders/test_payment_execution_detail.rb +0 -19
  39. data/test/mws/orders/test_payment_execution_detail_item.rb +0 -19
  40. data/test/mws/orders/test_service_status.rb +0 -28
  41. data/test/mws/orders/test_shipping_address.rb +0 -37
  42. data/test/mws/orders/test_tokenable.rb +0 -33
  43. data/test/test_helper.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5024482ae6bb34ce7a6066333ab17e2bad0c8cd98330ef2d17710c843114c1bb
4
- data.tar.gz: 2d2235a1ccd194a58cfb162d4cd89990e3878a232c62b0c7325f30d595dd0cf4
3
+ metadata.gz: b05f9a8f9c6d1b3eda7df105bd088572fbe93324682f9902f81a16aa7060b55f
4
+ data.tar.gz: 812d86fb8d5e6e4bdf8f5ad1b928394290f26a282b5f2eed67c8054da1d1cef7
5
5
  SHA512:
6
- metadata.gz: a0e92ba47bfc2feb5513324f22a60abd078528c327e1be3e22a0d27940f7f45d5917e3708cbda335967d3cb2cbffe9364a4677f359af01d698c897d6c4b52883
7
- data.tar.gz: 75677d6f12e108daf1331ba3d18b5d2c54717abd79a85999e68545a13f18773a8804577d5d063710e2fdba7a6b8a151d4b3035f795774f9c3d55bf86d43b9747
6
+ metadata.gz: 0bcd1463e7bcdf91b937926079202a9ebc93ec783da4a459fcef869c65381b8ad935d654462a3397c7ed5145f55c306f6dff4cc7345096e77f96b6c438bc19d5
7
+ data.tar.gz: a8df5632bc2d3132680cdc9e9c45cb91d355400fae60a6479f8b248332ce9afc80623eb51f0262fec54075ffcc77694e43415770fc58b568654beeaa6607e2ea
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2013-2014 Hakan Ensari
3
+ Copyright (c) Hakan Ensari
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MWS Orders
2
2
 
3
- [![Build Status](https://travis-ci.org/hakanensari/mws-orders.svg)](https://travis-ci.org/hakanensari/mws-orders)
3
+ [![CircleCI](https://circleci.com/gh/hakanensari/mws-orders.svg?style=svg)](https://circleci.com/gh/hakanensari/mws-orders)
4
4
 
5
5
  **MWS Orders** is a full-featured Ruby interface to the [Amazon Marketplace Web Service (MWS) Orders API](http://docs.developer.amazonservices.com/en_UK/orders/index.html). With the MWS Orders API, you can list orders created or updated during a time frame you specify or retrieve information about specific orders.
6
6
 
@@ -26,7 +26,7 @@ List orders created or updated during a time frame you specify:
26
26
  response = client.list_orders(created_after: 1.month.ago)
27
27
  orders = response.parse
28
28
  puts orders.count # => 100
29
- puts orders.first # => #<MWS::Orders::Order amazon_order_id="123...
29
+ orders.first.inspect # => #<MWS::Orders::Order 902-3159896-1390916>
30
30
  )
31
31
  ```
32
32
 
@@ -41,7 +41,7 @@ Get one or more orders based on their order numbers:
41
41
  ```ruby
42
42
  response = client.get_order('123-1234567-1234567')
43
43
  order = response.parse
44
- puts order # => #<MWS::Orders::Order amazon_order_id="123...
44
+ order.inspect # => #<MWS::Orders::Order 902-3159896-1390916>
45
45
  ```
46
46
 
47
47
  ### Order Items
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mws/orders/entity'
4
+
5
+ module MWS
6
+ module Orders
7
+ # https://docs.developer.amazonservices.com/en_US/orders-2013-09-01/Orders_Datatypes.html#Address
8
+ class Address < Entity
9
+ attribute(:name) do
10
+ string('Name')
11
+ end
12
+
13
+ attribute(:lines) do
14
+ 1.upto(3).map { |i| string("AddressLine#{i}") }.compact
15
+ end
16
+
17
+ attribute(:city) do
18
+ string('City')
19
+ end
20
+
21
+ attribute(:state_or_region) do
22
+ string('StateOrRegion')
23
+ end
24
+
25
+ attribute(:postal_code) do
26
+ string('PostalCode')
27
+ end
28
+
29
+ attribute(:country_code) do
30
+ string('CountryCode')
31
+ end
32
+
33
+ attribute(:phone) do
34
+ string('Phone')
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mws/orders/entity'
4
+
5
+ module MWS
6
+ module Orders
7
+ # https://docs.developer.amazonservices.com/en_US/orders-2013-09-01/Orders_Datatypes.html#BuyerCustomizedInfo
8
+ class BuyerCustomizedInfo < Entity
9
+ attribute :customized_url do
10
+ string('CustomizedURL')
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mws/orders/entity'
4
+ require 'mws/orders/tax_classification'
5
+
6
+ module MWS
7
+ module Orders
8
+ # https://docs.developer.amazonservices.com/en_US/orders-2013-09-01/Orders_Datatypes.html#BuyerTaxInfo
9
+ class BuyerTaxInfo < Entity
10
+ attribute :company_legal_name do
11
+ string('CompanyLegalName')
12
+ end
13
+
14
+ attribute(:taxing_region) do
15
+ string('TaxingRegion')
16
+ end
17
+
18
+ attribute(:tax_classifications) do
19
+ entities('TaxClassifications/TaxClassification', TaxClassification)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -4,6 +4,7 @@ require 'mws/orders/document'
4
4
 
5
5
  module MWS
6
6
  module Orders
7
+ # Returns a list of parsed objects
7
8
  class Collection < Document
8
9
  include Enumerable
9
10
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  module MWS
4
4
  module Orders
5
+ # Wraps a Nokogiri node
5
6
  class Document
6
7
  attr_reader :node
7
8
 
@@ -13,13 +14,14 @@ module MWS
13
14
  node.xpath(add_namespace(path))
14
15
  end
15
16
 
17
+ def at_xpath(path)
18
+ node.at_xpath(add_namespace(path))
19
+ end
20
+
16
21
  private
17
22
 
18
23
  def add_namespace(path)
19
- path
20
- .split('/')
21
- .map { |attr| "xmlns:#{attr}" }
22
- .join('/')
24
+ path.split('/').map { |attr| "xmlns:#{attr}" }.join('/')
23
25
  end
24
26
  end
25
27
  end
@@ -8,37 +8,48 @@ require 'mws/orders/document'
8
8
 
9
9
  module MWS
10
10
  module Orders
11
+ # A parsed object
11
12
  class Entity < Document
12
13
  include Structure
13
14
 
14
- def float_at_xpath(path)
15
- text = text_at_xpath(path)
16
- text&.to_f
15
+ def boolean(path)
16
+ string(path) == 'true'
17
17
  end
18
18
 
19
- def integer_at_xpath(path)
20
- text = text_at_xpath(path)
21
- text&.to_i
19
+ def entities(path, klass)
20
+ xpath(path).map { |node| klass.new(node) }
22
21
  end
23
22
 
24
- def money_at_xpath(path)
25
- amount = float_at_xpath("#{path}/Amount")
23
+ def entity(path, klass)
24
+ node = at_xpath(path)
25
+ klass.new(node) if node
26
+ end
27
+
28
+ def float(path)
29
+ string(path)&.to_f
30
+ end
31
+
32
+ def integer(path)
33
+ string(path)&.to_i
34
+ end
35
+
36
+ def money(path)
37
+ amount = float("#{path}/Amount")
26
38
  return unless amount
27
39
 
28
- currency_code = text_at_xpath("#{path}/CurrencyCode")
40
+ currency_code = string("#{path}/CurrencyCode")
29
41
  amount *= 100 unless currency_code == 'JPY'
30
42
 
31
43
  Money.new(amount, currency_code)
32
44
  end
33
45
 
34
- def time_at_xpath(path)
35
- text = text_at_xpath(path)
36
- Time.parse(CGI.unescape(text)) if text
46
+ def string(path)
47
+ at_xpath(path)&.text&.strip
37
48
  end
38
49
 
39
- def text_at_xpath(path)
40
- node = xpath(path).first
41
- node&.text&.strip
50
+ def time(path)
51
+ text = string(path)
52
+ Time.parse(CGI.unescape(text)) if text
42
53
  end
43
54
  end
44
55
  end
@@ -4,21 +4,22 @@ require 'mws/orders/entity'
4
4
 
5
5
  module MWS
6
6
  module Orders
7
+ # https://docs.developer.amazonservices.com/en_US/orders-2013-09-01/Orders_Datatypes.html#InvoiceData
7
8
  class InvoiceData < Entity
8
9
  attribute(:invoice_requirement) do
9
- text_at_xpath('InvoiceRequirement')
10
+ string('InvoiceRequirement')
10
11
  end
11
12
 
12
13
  attribute(:buyer_selected_invoice_category) do
13
- text_at_xpath('BuyerSelectedInvoiceCategory')
14
+ string('BuyerSelectedInvoiceCategory')
14
15
  end
15
16
 
16
17
  attribute(:invoice_title) do
17
- text_at_xpath('InvoiceTitle')
18
+ string('InvoiceTitle')
18
19
  end
19
20
 
20
21
  attribute(:invoice_information) do
21
- text_at_xpath('InvoiceInformation')
22
+ string('InvoiceInformation')
22
23
  end
23
24
  end
24
25
  end
@@ -4,13 +4,14 @@ require 'mws/orders/entity'
4
4
 
5
5
  module MWS
6
6
  module Orders
7
+ # https://docs.developer.amazonservices.com/en_US/orders-2013-09-01/MWS_GetServiceStatus.html
7
8
  class Message < Entity
8
9
  attribute(:locale) do
9
- text_at_xpath('Locale')
10
+ string('Locale')
10
11
  end
11
12
 
12
13
  attribute(:text) do
13
- text_at_xpath('Text')
14
+ string('Text')
14
15
  end
15
16
  end
16
17
  end
@@ -1,116 +1,165 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'mws/orders/entity'
4
- require 'mws/orders/shipping_address'
5
- require 'mws/orders/payment_execution_detail'
4
+ require 'mws/orders/address'
5
+ require 'mws/orders/buyer_tax_info'
6
+ require 'mws/orders/payment_execution_detail_item'
6
7
 
7
8
  module MWS
8
9
  module Orders
10
+ # https://docs.developer.amazonservices.com/en_US/orders-2013-09-01/Orders_Datatypes.html#Order
9
11
  class Order < Entity
10
12
  attribute(:amazon_order_id) do
11
- text_at_xpath('AmazonOrderId')
13
+ string('AmazonOrderId')
12
14
  end
13
15
 
14
16
  attribute(:seller_order_id) do
15
- text_at_xpath('SellerOrderId')
17
+ string('SellerOrderId')
16
18
  end
17
19
 
18
20
  attribute(:purchased_at) do
19
- time_at_xpath('PurchaseDate')
21
+ time('PurchaseDate')
20
22
  end
21
23
 
22
24
  attribute(:last_updated_at) do
23
- time_at_xpath('LastUpdateDate')
25
+ time('LastUpdateDate')
24
26
  end
25
27
 
26
28
  attribute(:status) do
27
- text_at_xpath('OrderStatus')
29
+ string('OrderStatus')
28
30
  end
29
31
 
30
32
  attribute(:fulfillment_channel) do
31
- text_at_xpath('FulfillmentChannel')
33
+ string('FulfillmentChannel')
32
34
  end
33
35
 
34
36
  attribute(:sales_channel) do
35
- text_at_xpath('SalesChannel')
37
+ string('SalesChannel')
36
38
  end
37
39
 
38
40
  attribute(:order_channel) do
39
- text_at_xpath('OrderChannel')
41
+ string('OrderChannel')
40
42
  end
41
43
 
42
44
  attribute(:ship_service_level) do
43
- text_at_xpath('ShipServiceLevel')
45
+ string('ShipServiceLevel')
44
46
  end
45
47
 
46
48
  attribute(:shipping_address) do
47
- node = xpath('ShippingAddress').first
48
- ShippingAddress.new(node) if node
49
+ entity('ShippingAddress', Address)
49
50
  end
50
51
 
51
52
  attribute(:total) do
52
- money_at_xpath('OrderTotal')
53
+ money('OrderTotal')
53
54
  end
54
55
 
55
56
  attribute(:number_of_items_shipped) do
56
- integer_at_xpath('NumberOfItemsShipped')
57
+ integer('NumberOfItemsShipped')
57
58
  end
58
59
 
59
60
  attribute(:number_of_items_unshipped) do
60
- integer_at_xpath('NumberOfItemsUnshipped')
61
+ integer('NumberOfItemsUnshipped')
61
62
  end
62
63
 
63
64
  attribute(:payment_execution_detail) do
64
- node = xpath('PaymentExecutionDetail').first
65
- PaymentExecutionDetail.new(node) if node
65
+ xpath('PaymentExecutionDetail/PaymentExecutionDetailItem')
66
+ .map { |node| PaymentExecutionDetailItem.new(node) }
66
67
  end
67
68
 
68
69
  attribute(:payment_method) do
69
- text_at_xpath('PaymentMethod')
70
+ string('PaymentMethod')
71
+ end
72
+
73
+ attribute(:payment_method_details) do
74
+ xpath('PaymentMethodDetails/PaymentMethodDetail').map(&:text)
75
+ end
76
+
77
+ attribute(:replacement_order?) do
78
+ boolean('IsReplacementOrder')
79
+ end
80
+
81
+ attribute(:replaced_order_id) do
82
+ string('ReplacedOrderId')
70
83
  end
71
84
 
72
85
  attribute(:marketplace_id) do
73
- text_at_xpath('MarketplaceId')
86
+ string('MarketplaceId')
87
+ end
88
+
89
+ attribute(:buyer_email) do
90
+ string('BuyerEmail')
74
91
  end
75
92
 
76
93
  attribute(:buyer_name) do
77
- text_at_xpath('BuyerName')
94
+ string('BuyerName')
78
95
  end
79
96
 
80
- attribute(:buyer_email) do
81
- text_at_xpath('BuyerEmail')
97
+ attribute(:buyer_county) do
98
+ string('BuyerCounty')
82
99
  end
83
100
 
84
- attribute(:shipment_service_level_category) do
85
- text_at_xpath('ShipmentServiceLevelCategory')
101
+ attribute(:buyer_tax_info) do
102
+ entity('BuyerTaxInfo', BuyerTaxInfo)
86
103
  end
87
104
 
88
- attribute(:cba_displayable_shipping_label) do
89
- text_at_xpath('CbaDisplayableShippingLabel')
105
+ attribute(:shipment_service_level_category) do
106
+ string('ShipmentServiceLevelCategory')
90
107
  end
91
108
 
92
109
  attribute(:shipped_by_amazon_tfm) do
93
- text_at_xpath('ShippedByAmazonTFM')
110
+ string('ShippedByAmazonTFM')
94
111
  end
95
112
 
96
113
  attribute(:tfm_shipment_status) do
97
- text_at_xpath('TFMShipmentStatus')
114
+ string('TFMShipmentStatus')
115
+ end
116
+
117
+ attribute(:easy_ship_shipment_status) do
118
+ string('EasyShipShipmentStatus')
98
119
  end
99
120
 
100
121
  attribute(:type) do
101
- text_at_xpath('OrderType')
122
+ string('OrderType')
102
123
  end
103
124
 
104
125
  attribute(:earliest_shipped_at) do
105
- time_at_xpath('EarliestShipDate')
126
+ time('EarliestShipDate')
106
127
  end
107
128
 
108
129
  attribute(:latest_shipped_at) do
109
- time_at_xpath('LatestShipDate')
130
+ time('LatestShipDate')
131
+ end
132
+
133
+ attribute(:earliest_delivered_at) do
134
+ time('LatestDeliveryDate')
110
135
  end
111
136
 
112
137
  attribute(:latest_delivered_at) do
113
- time_at_xpath('LatestDeliveryDate')
138
+ time('LatestDeliveryDate')
139
+ end
140
+
141
+ attribute(:business_order?) do
142
+ boolean('IsBusinessOrder')
143
+ end
144
+
145
+ attribute(:purchase_order_number) do
146
+ string('PurchaseOrderNumber')
147
+ end
148
+
149
+ attribute(:prime?) do
150
+ boolean('IsPrime')
151
+ end
152
+
153
+ attribute(:premium?) do
154
+ boolean('IsPremiumOrder')
155
+ end
156
+
157
+ attribute(:promise_response_due_at) do
158
+ time('PromiseResponseDueDate')
159
+ end
160
+
161
+ attribute(:estimated_ship_date_set?) do
162
+ boolean('IsEstimatedShipDateSet')
114
163
  end
115
164
 
116
165
  def to_s