mws-orders 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +16 -25
  4. data/lib/mws-orders.rb +2 -29
  5. data/lib/mws/orders/collection.rb +29 -0
  6. data/lib/mws/orders/document.rb +28 -0
  7. data/lib/mws/orders/entity.rb +39 -0
  8. data/lib/mws/orders/invoice_data.rb +23 -0
  9. data/lib/mws/orders/order.rb +113 -0
  10. data/lib/mws/orders/order_item.rb +108 -0
  11. data/lib/mws/orders/order_items.rb +15 -0
  12. data/lib/mws/orders/orders.rb +15 -0
  13. data/lib/mws/orders/parser.rb +52 -0
  14. data/lib/mws/orders/payment_execution_detail.rb +12 -0
  15. data/lib/mws/orders/payment_execution_detail_item.rb +15 -0
  16. data/lib/mws/orders/service_status.rb +24 -0
  17. data/lib/mws/orders/service_status_message.rb +15 -0
  18. data/lib/mws/orders/shipping_address.rb +35 -0
  19. data/lib/mws/orders/tokenable.rb +10 -0
  20. data/lib/mws/orders/version.rb +1 -1
  21. data/test/integration/test_integration.rb +26 -0
  22. data/test/mws/orders/test_entity.rb +88 -0
  23. data/test/{parsers/order_test.rb → mws/orders/test_order.rb} +11 -6
  24. data/test/{parsers/order_item_test.rb → mws/orders/test_order_item.rb} +4 -4
  25. data/test/mws/orders/test_order_items.rb +19 -0
  26. data/test/mws/orders/test_orders.rb +19 -0
  27. data/test/mws/orders/test_parser.rb +7 -0
  28. data/test/mws/orders/test_payment_execution_detail.rb +15 -0
  29. data/test/mws/orders/test_payment_execution_detail_item.rb +16 -0
  30. data/test/mws/orders/test_service_status.rb +24 -0
  31. data/test/mws/orders/test_service_status_message.rb +16 -0
  32. data/test/{parsers/shipping_address_test.rb → mws/orders/test_shipping_address.rb} +4 -4
  33. data/test/test_helper.rb +15 -6
  34. metadata +67 -134
  35. data/lib/mws/orders/client.rb +0 -88
  36. data/lib/mws/orders/helpers/parameters.rb +0 -53
  37. data/lib/mws/orders/helpers/structured_list.rb +0 -40
  38. data/lib/mws/orders/parsers/base.rb +0 -27
  39. data/lib/mws/orders/parsers/collection.rb +0 -22
  40. data/lib/mws/orders/parsers/invoice_data.rb +0 -23
  41. data/lib/mws/orders/parsers/model.rb +0 -38
  42. data/lib/mws/orders/parsers/order.rb +0 -108
  43. data/lib/mws/orders/parsers/order_item.rb +0 -107
  44. data/lib/mws/orders/parsers/order_items.rb +0 -17
  45. data/lib/mws/orders/parsers/orders.rb +0 -17
  46. data/lib/mws/orders/parsers/payment_execution_detail.rb +0 -17
  47. data/lib/mws/orders/parsers/payment_execution_detail_item.rb +0 -15
  48. data/lib/mws/orders/parsers/service_status.rb +0 -32
  49. data/lib/mws/orders/parsers/service_status_message.rb +0 -15
  50. data/lib/mws/orders/parsers/shipping_address.rb +0 -35
  51. data/lib/mws/orders/requests/base.rb +0 -55
  52. data/lib/mws/orders/requests/order_items.rb +0 -23
  53. data/lib/mws/orders/requests/orders.rb +0 -36
  54. data/lib/mws/orders/requests/service_status.rb +0 -18
  55. data/test/fixtures/mws.yml +0 -12
  56. data/test/helpers/parameters_test.rb +0 -34
  57. data/test/helpers/structured_list_test.rb +0 -17
  58. data/test/integration/order_items_test.rb +0 -16
  59. data/test/integration/orders_test.rb +0 -17
  60. data/test/integration/service_status_test.rb +0 -9
  61. data/test/integration/test_helper.rb +0 -12
  62. data/test/parsers/collection_test.rb +0 -7
  63. data/test/parsers/model_test.rb +0 -27
  64. data/test/parsers/order_items_test.rb +0 -13
  65. data/test/parsers/orders_test.rb +0 -13
  66. data/test/parsers/payment_execution_detail_item_test.rb +0 -16
  67. data/test/parsers/payment_execution_detail_test.rb +0 -13
  68. data/test/parsers/service_status_message_test.rb +0 -16
  69. data/test/parsers/service_status_test.rb +0 -38
  70. data/test/parsers/test_helper.rb +0 -10
  71. data/test/requests/order_items_test.rb +0 -36
  72. data/test/requests/orders_test.rb +0 -46
  73. data/test/requests/service_status_test.rb +0 -22
  74. data/test/requests/test_helper.rb +0 -18
@@ -1,53 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Helper
4
- class Parameters < SimpleDelegator
5
- def initialize(action)
6
- super({ 'Action' => camelize(action) })
7
- end
8
-
9
- def timestamp!
10
- each do |key, value|
11
- store(key, value.iso8601) if value.respond_to?(:iso8601)
12
- end
13
-
14
- self
15
- end
16
-
17
- def format_structured_lists!
18
- lists = {}
19
-
20
- each do |key, value|
21
- if StructuredList.handle?(key)
22
- lists.update(StructuredList.new(key).build(delete(key)))
23
- end
24
- end
25
-
26
- update(lists)
27
- end
28
-
29
- def camelize_keys!
30
- keys.each do |key|
31
- if key.is_a?(Symbol)
32
- new_key = camelize(key)
33
- store(new_key, delete(key))
34
- end
35
- end
36
-
37
- self
38
- end
39
-
40
- def update(hsh)
41
- __getobj__.update(hsh)
42
- self
43
- end
44
-
45
- private
46
-
47
- def camelize(sym)
48
- sym.to_s.split('_').map(&:capitalize).join
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,40 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Helper
4
- class StructuredList
5
- KEYS = {
6
- order_status: %w(OrderStatus Status),
7
- marketplace_id: %w(MarketplaceId Id),
8
- fulfillment_channel: %w(FulfillmentChannel Channel),
9
- payment_method: %w(PaymentMethod),
10
- tfm_shipment_status: %w(TFMShipmentStatus Status),
11
- amazon_order_id: %w(AmazonOrderId Id)
12
- }
13
-
14
- attr :keys
15
-
16
- def self.handle?(key)
17
- KEYS.has_key?(key)
18
- end
19
-
20
- def initialize(key)
21
- @keys = KEYS.fetch(key)
22
- end
23
-
24
- def build(values)
25
- Array(values)
26
- .each_with_index
27
- .reduce(Hash.new) { |hsh, (v, i)|
28
- hsh.merge(composite_key(i + 1) => v)
29
- }
30
- end
31
-
32
- private
33
-
34
- def composite_key(index)
35
- (keys.dup << index).join('.')
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,27 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class Base
5
- attr :document
6
-
7
- def initialize(document)
8
- @document = document
9
- end
10
-
11
- private
12
-
13
- def at_xpath(path)
14
- document.at_xpath(with_namespace(path))
15
- end
16
-
17
- def xpath(path)
18
- document.xpath(with_namespace(path))
19
- end
20
-
21
- def with_namespace(path)
22
- path.split('/').map { |attr| "xmlns:#{attr}" }.join('/')
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,22 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class Collection < Base
5
- include Enumerable
6
-
7
- def each
8
- raise NotImplementedError
9
- end
10
-
11
- def empty?
12
- count == 0
13
- end
14
-
15
- def inspect
16
- "#<#{self.class}>"
17
- end
18
- alias :to_s :inspect
19
- end
20
- end
21
- end
22
- end
@@ -1,23 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class InvoiceData < Model
5
- value :invoice_requirement do
6
- text_at_xpath('InvoiceRequirement')
7
- end
8
-
9
- value :buyer_selected_invoice_category do
10
- text_at_xpath('BuyerSelectedInvoiceCategory')
11
- end
12
-
13
- value :invoice_title do
14
- text_at_xpath('InvoiceTitle')
15
- end
16
-
17
- value :invoice_information do
18
- text_at_xpath('InvoiceInformation')
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,38 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class Model < Base
5
- include Structure
6
-
7
- def float_at_xpath(path)
8
- str = text_at_xpath(path)
9
- str.to_f if str
10
- end
11
-
12
- def integer_at_xpath(path)
13
- str = text_at_xpath(path)
14
- str.to_i if str
15
- end
16
-
17
- def money_at_xpath(path)
18
- return unless amount = float_at_xpath("#{path}/Amount")
19
-
20
- currency_code = text_at_xpath("#{path}/CurrencyCode")
21
- amount = amount * 100 unless currency_code == 'JPY'
22
-
23
- Money.new(amount, currency_code)
24
- end
25
-
26
- def text_at_xpath(path)
27
- node = at_xpath(path)
28
- node.text if node
29
- end
30
-
31
- def time_at_xpath(path)
32
- str = text_at_xpath(path)
33
- Time.parse(CGI.unescape(str)) if str
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,108 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class Order < Model
5
- value :amazon_order_id do
6
- text_at_xpath('AmazonOrderId')
7
- end
8
-
9
- value :seller_order_id do
10
- text_at_xpath('SellerOrderId')
11
- end
12
-
13
- value :purchased_at do
14
- time_at_xpath('PurchaseDate')
15
- end
16
-
17
- value :last_updated_at do
18
- time_at_xpath('LastUpdateDate')
19
- end
20
-
21
- value :status do
22
- text_at_xpath('OrderStatus')
23
- end
24
-
25
- value :fulfillment_channel do
26
- text_at_xpath('FulfillmentChannel')
27
- end
28
-
29
- value :sales_channel do
30
- text_at_xpath('SalesChannel')
31
- end
32
-
33
- value :order_channel do
34
- text_at_xpath('OrderChannel')
35
- end
36
-
37
- value :ship_service_level do
38
- text_at_xpath('ShipServiceLevel')
39
- end
40
-
41
- value :shipping_address do
42
- ShippingAddress.new(at_xpath('ShippingAddress'))
43
- end
44
-
45
- value :total do
46
- money_at_xpath('OrderTotal')
47
- end
48
-
49
- value :number_of_items_shipped do
50
- integer_at_xpath('NumberOfItemsShipped')
51
- end
52
-
53
- value :number_of_items_unshipped do
54
- integer_at_xpath('NumberOfItemsUnshipped')
55
- end
56
-
57
- value :payment_execution_detail do
58
- node = at_xpath('PaymentExecutionDetail')
59
- PaymentExecutionDetail.new(node) if node
60
- end
61
-
62
- value :payment_method do
63
- text_at_xpath('PaymentMethod')
64
- end
65
-
66
- value :marketplace_id do
67
- text_at_xpath('MarketplaceId')
68
- end
69
-
70
- value :buyer_name do
71
- text_at_xpath('BuyerName')
72
- end
73
-
74
- value :buyer_email do
75
- text_at_xpath('BuyerEmail')
76
- end
77
-
78
- value :shipment_service_level_category do
79
- text_at_xpath('ShipmentServiceLevelCategory')
80
- end
81
-
82
- value :cba_displayable_shipping_label do
83
- text_at_xpath('CbaDisplayableShippingLabel')
84
- end
85
-
86
- value :shipped_by_amazon_tfm do
87
- text_at_xpath('ShippedByAmazonTFM')
88
- end
89
-
90
- value :tfm_shipment_status do
91
- text_at_xpath('TFMShipmentStatus')
92
- end
93
-
94
- value :type do
95
- text_at_xpath('OrderType')
96
- end
97
-
98
- value :earliest_shipped_at do
99
- time_at_xpath('EarliestShipDate')
100
- end
101
-
102
- value :latest_shipped_at do
103
- time_at_xpath('LatestShipDate')
104
- end
105
- end
106
- end
107
- end
108
- end
@@ -1,107 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class OrderItem < Model
5
- value :asin do
6
- text_at_xpath('ASIN')
7
- end
8
-
9
- value :seller_sku do
10
- text_at_xpath('SellerSKU')
11
- end
12
-
13
- value :order_item_id do
14
- text_at_xpath('OrderItemId')
15
- end
16
-
17
- value :title do
18
- text_at_xpath('Title')
19
- end
20
-
21
- value :quantity_ordered do
22
- integer_at_xpath('QuantityOrdered')
23
- end
24
-
25
- value :quantity_shipped do
26
- integer_at_xpath('QuantityShipped')
27
- end
28
-
29
- value :gift_message_text do
30
- text_at_xpath('GiftMessageText')
31
- end
32
-
33
- value :gift_wrap_level do
34
- text_at_xpath('GiftWrapLevel')
35
- end
36
-
37
- value :item_price do
38
- money_at_xpath('ItemPrice')
39
- end
40
-
41
- value :shipping_price do
42
- money_at_xpath('ShippingPrice')
43
- end
44
-
45
- value :gift_wrap_price do
46
- money_at_xpath('GiftWrapPrice')
47
- end
48
-
49
- value :item_tax do
50
- money_at_xpath('ItemTax')
51
- end
52
-
53
- value :shipping_tax do
54
- money_at_xpath('ShippingTax')
55
- end
56
-
57
- value :gift_wrap_tax do
58
- money_at_xpath('GiftWrapPrice')
59
- end
60
-
61
- value :shipping_discount do
62
- money_at_xpath('ShippingDiscount')
63
- end
64
-
65
- value :promotion_discount do
66
- money_at_xpath('PromotionDiscount')
67
- end
68
-
69
- value :promotion_ids do
70
- xpath('PromotionId').map(&:text)
71
- end
72
-
73
- value :cod_fee do
74
- money_at_xpath('CODFee')
75
- end
76
-
77
- value :cod_fee_discount do
78
- money_at_xpath('CODFeeDiscount')
79
- end
80
-
81
- value :invoice_data do
82
- xpath('InvoiceData').map { |node| InvoiceData.new(node) }
83
- end
84
-
85
- value :condition_id do
86
- text_at_xpath('ConditionId')
87
- end
88
-
89
- value :condition_subtype_id do
90
- text_at_xpath('ConditionSubtypeId')
91
- end
92
-
93
- value :condition_note do
94
- text_at_xpath('ConditionNote')
95
- end
96
-
97
- value :scheduled_delivery_ends_at do
98
- time_at_xpath('ScheduledDeliveryEndDate')
99
- end
100
-
101
- value :scheduled_delivery_starts_at do
102
- time_at_xpath('ScheduledDeliveryStartDate')
103
- end
104
- end
105
- end
106
- end
107
- end
@@ -1,17 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class OrderItems < Collection
5
- def each(&blk)
6
- order_item_nodes.each { |node| yield OrderItem.new(node) }
7
- end
8
-
9
- private
10
-
11
- def order_item_nodes
12
- xpath('OrderItem')
13
- end
14
- end
15
- end
16
- end
17
- end