mws-orders 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1573eac66d2fcb6f0d19426a9f49b9e943d6662c
4
- data.tar.gz: 32b0a15281d875074c93b2ec382e033c9761d821
3
+ metadata.gz: a19c5ef1c9834c6008a1618a7e2b9740dbc264d6
4
+ data.tar.gz: d7a3b54bdeb81dd00380076535e869747e46b71f
5
5
  SHA512:
6
- metadata.gz: 9cbf5db8dcb0f758ecea5b83210738f704544f06734140aae757c154ac41c82869bfed16ba294f5d10313771e0dfee49435e6675d50970f49ec23ff7268c6cd6
7
- data.tar.gz: b5d8b528756fb96208831eaf3a939d27ba913c0b83a359af97afbda93eafdb07f1e82983ebf739397a49b8dde18c440c771f3eff07754f8c96d79ae3dcad23bb
6
+ metadata.gz: 36ea87627bac392e57c5e6abd92ecc2e6beee64d3b38458a9a8e6ddb4b5f278de30d160569099c6fc3ee50a51d81d20d61d6e2ea44c89a9d77e001984384cf04
7
+ data.tar.gz: ab91b32c50a02f8f964c1f4bb94753a26801b1d6ed8a0b648a63fae4b4bb731efefbdcf347cb4deddfc7a957670917e034604a810033ae4f0c777db0774b0abb
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2013 Paper Cavalier
3
+ Copyright (c) 2013-2014 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,50 +1,50 @@
1
1
  # MWS Orders
2
2
 
3
- **MWS Orders** is a fully-featured Ruby interface to the [Amazon Marketplace
4
- Web Service (MWS) Orders API][1].
3
+ **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.
4
+
5
+ To use Amazon MWS, you must have an eligible seller account.
5
6
 
6
7
  ## Usage
7
8
 
8
- Instantiate a client:
9
+ Create a client:
9
10
 
10
11
  ```ruby
11
- client = MWS::Orders::Client.new('GB', 'aws_key', 'aws_secret', 'seller_id')
12
+ require "mws-orders"
13
+ client = MWS.orders
12
14
  ```
13
15
 
14
- [API methods are available on the client][2].
16
+ Set up credentials [when instantiating or with environment variables](https://github.com/hakanensari/peddler#quick-start).
15
17
 
16
18
  ### Orders
17
19
 
18
20
  List orders created or updated during a time frame you specify:
19
21
 
20
22
  ```ruby
21
- # See the API for all available parameters.
22
- client.list_orders(
23
- created_after: 1.week.ago,
24
- order_status: %w(Pending Unshipped)
23
+ orders = client.list_orders(created_after: 1.month.ago)
24
+ puts orders.count # => 100
25
+ puts orders.first # => #<MWS::Orders::Order amazon_order_id="123...
25
26
  )
26
27
  ```
27
28
 
28
29
  List the next page of orders:
29
30
 
30
31
  ```ruby
31
- client.list_orders_by_next_token
32
+ client.list_orders_by_next_token(orders.next_token)
32
33
  ```
33
34
 
34
35
  Get one or more orders based on their order numbers:
35
36
 
36
37
  ```ruby
37
- client.get_order('123-1234567-1234567')
38
+ order = client.get_order("123-1234567-1234567")
39
+ puts order # => #<MWS::Orders::Order amazon_order_id="123...
38
40
  ```
39
41
 
40
- All above queries will return an enumerable list of orders.
41
-
42
42
  ### Order Items
43
43
 
44
- List order items based on an order number you specify:
44
+ List order items:
45
45
 
46
46
  ```ruby
47
- client.list_order_items('123-1234567-1234567')
47
+ order_items = client.list_order_items("123-1234567-1234567")
48
48
  ```
49
49
 
50
50
  List the next page of order items:
@@ -53,7 +53,7 @@ List the next page of order items:
53
53
  client.list_order_items_by_next_token
54
54
  ```
55
55
 
56
- All above queries will return an enumerable list of order items.
56
+ Orders and order items are represented by POROs that map one on one to the attributes returned by the API.
57
57
 
58
58
  ### Service Status
59
59
 
@@ -62,12 +62,3 @@ Check the operational status of the API:
62
62
  ```ruby
63
63
  client.get_service_status
64
64
  ```
65
-
66
- ### Naming Conventions
67
-
68
- Request and response attribute names follow Amazon's naming conventions with a
69
- few exceptions, where some Railsism has insidiuously crept in&mdash;e.g.
70
- `shipped_at` instead of `ShipDate`.
71
-
72
- [1]: http://docs.developer.amazonservices.com/en_UK/orders/index.html
73
- [2]: https://github.com/papercavalier/mws-orders/blob/master/lib/mws/orders/client.rb
data/lib/mws-orders.rb CHANGED
@@ -1,29 +1,2 @@
1
- require 'cgi'
2
- require 'delegate'
3
- require 'forwardable'
4
- require 'time'
5
-
6
- require 'money'
7
- require 'nokogiri'
8
- require 'peddler'
9
- require 'structure'
10
-
11
- require 'mws/orders/client'
12
- require 'mws/orders/helpers/structured_list'
13
- require 'mws/orders/helpers/parameters'
14
- require 'mws/orders/requests/base'
15
- require 'mws/orders/requests/orders'
16
- require 'mws/orders/requests/order_items'
17
- require 'mws/orders/requests/service_status'
18
- require 'mws/orders/parsers/base'
19
- require 'mws/orders/parsers/model'
20
- require 'mws/orders/parsers/collection'
21
- require 'mws/orders/parsers/orders'
22
- require 'mws/orders/parsers/order'
23
- require 'mws/orders/parsers/shipping_address'
24
- require 'mws/orders/parsers/payment_execution_detail'
25
- require 'mws/orders/parsers/payment_execution_detail_item'
26
- require 'mws/orders/parsers/order_items'
27
- require 'mws/orders/parsers/order_item'
28
- require 'mws/orders/parsers/service_status'
29
- require 'mws/orders/parsers/service_status_message'
1
+ require "peddler"
2
+ require "mws/orders/parser"
@@ -0,0 +1,29 @@
1
+ require "mws/orders/document"
2
+
3
+ module MWS
4
+ module Orders
5
+ class Collection < Document
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} #{
18
+ if count > 3
19
+ "[#{take(3).map(&:inspect).join(', ')}...]"
20
+ else
21
+ "[#{map(&:inspect).join(', ')}]"
22
+ end
23
+ }>"
24
+ end
25
+
26
+ alias_method :to_s, :inspect
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require "structure"
2
+
3
+ module MWS
4
+ module Orders
5
+ class Document
6
+ include Structure
7
+
8
+ attr_reader :node
9
+
10
+ def initialize(node)
11
+ @node = node
12
+ end
13
+
14
+ def xpath(path)
15
+ node.xpath(add_namespace(path))
16
+ end
17
+
18
+ private
19
+
20
+ def add_namespace(path)
21
+ path
22
+ .split("/")
23
+ .map { |attr| "xmlns:#{attr}" }
24
+ .join("/")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,39 @@
1
+ require "cgi"
2
+ require "time"
3
+ require "money"
4
+ require "mws/orders/document"
5
+
6
+ module MWS
7
+ module Orders
8
+ class Entity < Document
9
+ def float_at_xpath(path)
10
+ text = text_at_xpath(path)
11
+ text.to_f if text
12
+ end
13
+
14
+ def integer_at_xpath(path)
15
+ text = text_at_xpath(path)
16
+ text.to_i if text
17
+ end
18
+
19
+ def money_at_xpath(path)
20
+ return unless amount = float_at_xpath("#{path}/Amount")
21
+
22
+ currency_code = text_at_xpath("#{path}/CurrencyCode")
23
+ amount = amount * 100 unless currency_code == "JPY"
24
+
25
+ Money.new(amount, currency_code)
26
+ end
27
+
28
+ def time_at_xpath(path)
29
+ text = text_at_xpath(path)
30
+ Time.parse(CGI.unescape(text)) if text
31
+ end
32
+
33
+ def text_at_xpath(path)
34
+ node = xpath(path).first
35
+ node.text.strip if node
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ require "mws/orders/entity"
2
+
3
+ module MWS
4
+ module Orders
5
+ class InvoiceData < Entity
6
+ attribute(:invoice_requirement) do
7
+ text_at_xpath("InvoiceRequirement")
8
+ end
9
+
10
+ attribute(:buyer_selected_invoice_category) do
11
+ text_at_xpath("BuyerSelectedInvoiceCategory")
12
+ end
13
+
14
+ attribute(:invoice_title) do
15
+ text_at_xpath("InvoiceTitle")
16
+ end
17
+
18
+ attribute(:invoice_information) do
19
+ text_at_xpath("InvoiceInformation")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,113 @@
1
+ require "mws/orders/entity"
2
+ require "mws/orders/shipping_address"
3
+ require "mws/orders/payment_execution_detail"
4
+
5
+ module MWS
6
+ module Orders
7
+ class Order < Entity
8
+ attribute(:amazon_order_id) do
9
+ text_at_xpath("AmazonOrderId")
10
+ end
11
+
12
+ attribute(:seller_order_id) do
13
+ text_at_xpath("SellerOrderId")
14
+ end
15
+
16
+ attribute(:purchased_at) do
17
+ time_at_xpath("PurchaseDate")
18
+ end
19
+
20
+ attribute(:last_updated_at) do
21
+ time_at_xpath("LastUpdateDate")
22
+ end
23
+
24
+ attribute(:status) do
25
+ text_at_xpath("OrderStatus")
26
+ end
27
+
28
+ attribute(:fulfillment_channel) do
29
+ text_at_xpath("FulfillmentChannel")
30
+ end
31
+
32
+ attribute(:sales_channel) do
33
+ text_at_xpath("SalesChannel")
34
+ end
35
+
36
+ attribute(:order_channel) do
37
+ text_at_xpath("OrderChannel")
38
+ end
39
+
40
+ attribute(:ship_service_level) do
41
+ text_at_xpath("ShipServiceLevel")
42
+ end
43
+
44
+ attribute(:shipping_address) do
45
+ if node = xpath("ShippingAddress").first
46
+ ShippingAddress.new(node)
47
+ end
48
+ end
49
+
50
+ attribute(:total) do
51
+ money_at_xpath("OrderTotal")
52
+ end
53
+
54
+ attribute(:number_of_items_shipped) do
55
+ integer_at_xpath("NumberOfItemsShipped")
56
+ end
57
+
58
+ attribute(:number_of_items_unshipped) do
59
+ integer_at_xpath("NumberOfItemsUnshipped")
60
+ end
61
+
62
+ attribute(:payment_execution_detail) do
63
+ if node = xpath("PaymentExecutionDetail").first
64
+ PaymentExecutionDetail.new(node)
65
+ end
66
+ end
67
+
68
+ attribute(:payment_method) do
69
+ text_at_xpath("PaymentMethod")
70
+ end
71
+
72
+ attribute(:marketplace_id) do
73
+ text_at_xpath("MarketplaceId")
74
+ end
75
+
76
+ attribute(:buyer_name) do
77
+ text_at_xpath("BuyerName")
78
+ end
79
+
80
+ attribute(:buyer_email) do
81
+ text_at_xpath("BuyerEmail")
82
+ end
83
+
84
+ attribute(:shipment_service_level_category) do
85
+ text_at_xpath("ShipmentServiceLevelCategory")
86
+ end
87
+
88
+ attribute(:cba_displayable_shipping_label) do
89
+ text_at_xpath("CbaDisplayableShippingLabel")
90
+ end
91
+
92
+ attribute(:shipped_by_amazon_tfm) do
93
+ text_at_xpath("ShippedByAmazonTFM")
94
+ end
95
+
96
+ attribute(:tfm_shipment_status) do
97
+ text_at_xpath("TFMShipmentStatus")
98
+ end
99
+
100
+ attribute(:type) do
101
+ text_at_xpath("OrderType")
102
+ end
103
+
104
+ attribute(:earliest_shipped_at) do
105
+ time_at_xpath("EarliestShipDate")
106
+ end
107
+
108
+ attribute(:latest_shipped_at) do
109
+ time_at_xpath("LatestShipDate")
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,108 @@
1
+ require "mws/orders/entity"
2
+ require "mws/orders/invoice_data"
3
+
4
+ module MWS
5
+ module Orders
6
+ class OrderItem < Entity
7
+ attribute(:asin) do
8
+ text_at_xpath("ASIN")
9
+ end
10
+
11
+ attribute(:seller_sku) do
12
+ text_at_xpath("SellerSKU")
13
+ end
14
+
15
+ attribute(:order_item_id) do
16
+ text_at_xpath("OrderItemId")
17
+ end
18
+
19
+ attribute(:title) do
20
+ text_at_xpath("Title")
21
+ end
22
+
23
+ attribute(:quantity_ordered) do
24
+ integer_at_xpath("QuantityOrdered")
25
+ end
26
+
27
+ attribute(:quantity_shipped) do
28
+ integer_at_xpath("QuantityShipped")
29
+ end
30
+
31
+ attribute(:gift_message_text) do
32
+ text_at_xpath("GiftMessageText")
33
+ end
34
+
35
+ attribute(:gift_wrap_level) do
36
+ text_at_xpath("GiftWrapLevel")
37
+ end
38
+
39
+ attribute(:item_price) do
40
+ money_at_xpath("ItemPrice")
41
+ end
42
+
43
+ attribute(:shipping_price) do
44
+ money_at_xpath("ShippingPrice")
45
+ end
46
+
47
+ attribute(:gift_wrap_price) do
48
+ money_at_xpath("GiftWrapPrice")
49
+ end
50
+
51
+ attribute(:item_tax) do
52
+ money_at_xpath("ItemTax")
53
+ end
54
+
55
+ attribute(:shipping_tax) do
56
+ money_at_xpath("ShippingTax")
57
+ end
58
+
59
+ attribute(:gift_wrap_tax) do
60
+ money_at_xpath("GiftWrapPrice")
61
+ end
62
+
63
+ attribute(:shipping_discount) do
64
+ money_at_xpath("ShippingDiscount")
65
+ end
66
+
67
+ attribute(:promotion_discount) do
68
+ money_at_xpath("PromotionDiscount")
69
+ end
70
+
71
+ attribute(:promotion_ids) do
72
+ xpath("PromotionId").map(&:text)
73
+ end
74
+
75
+ attribute(:cod_fee) do
76
+ money_at_xpath("CODFee")
77
+ end
78
+
79
+ attribute(:cod_fee_discount) do
80
+ money_at_xpath("CODFeeDiscount")
81
+ end
82
+
83
+ attribute(:invoice_data) do
84
+ xpath("InvoiceData").map { |node| InvoiceData.new(node) }
85
+ end
86
+
87
+ attribute(:condition_id) do
88
+ text_at_xpath("ConditionId")
89
+ end
90
+
91
+ attribute(:condition_subtype_id) do
92
+ text_at_xpath("ConditionSubtypeId")
93
+ end
94
+
95
+ attribute(:condition_note) do
96
+ text_at_xpath("ConditionNote")
97
+ end
98
+
99
+ attribute(:scheduled_delivery_ends_at) do
100
+ time_at_xpath("ScheduledDeliveryEndDate")
101
+ end
102
+
103
+ attribute(:scheduled_delivery_starts_at) do
104
+ time_at_xpath("ScheduledDeliveryStartDate")
105
+ end
106
+ end
107
+ end
108
+ end