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,17 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class Orders < Collection
5
- extend Forwardable
6
-
7
- def_delegator :order_nodes, :each
8
-
9
- private
10
-
11
- def order_nodes
12
- xpath('Order').map { |node| Order.new(node) }
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class PaymentExecutionDetail < Collection
5
- def each(&blk)
6
- payment_execution_detail_item_nodes.each { |node| yield PaymentExecutionDetailItem.new(node) }
7
- end
8
-
9
- private
10
-
11
- def payment_execution_detail_item_nodes
12
- xpath('PaymentExecutionDetailItem')
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class PaymentExecutionDetailItem < Model
5
- value :payment do
6
- money_at_xpath('Payment')
7
- end
8
-
9
- value :payment_method do
10
- text_at_xpath('PaymentMethod')
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,32 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class ServiceStatus < Model
5
- value :status do
6
- text_at_xpath('Status')
7
- end
8
-
9
- value :timestamp do
10
- time_at_xpath('Timestamp')
11
- end
12
-
13
- value :message_id do
14
- text_at_xpath('MessageId')
15
- end
16
-
17
- value :messages do
18
- xpath('Messages/Message').map { |node| ServiceStatusMessage.new(node) }
19
- end
20
-
21
- def ok?
22
- status == 'GREEN'
23
- end
24
-
25
- def inspect
26
- status
27
- end
28
- alias :to_s :inspect
29
- end
30
- end
31
- end
32
- end
@@ -1,15 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class ServiceStatusMessage < Model
5
- value :locale do
6
- text_at_xpath('Locale')
7
- end
8
-
9
- value :text do
10
- text_at_xpath('Text')
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,35 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Parser
4
- class ShippingAddress < Model
5
- value :name do
6
- text_at_xpath('Name')
7
- end
8
-
9
- value :address_lines do
10
- 1.upto(3).map { |i| text_at_xpath("AddressLine#{i}") }.compact
11
- end
12
-
13
- value :city do
14
- text_at_xpath('City')
15
- end
16
-
17
- value :state_or_region do
18
- text_at_xpath('StateOrRegion')
19
- end
20
-
21
- value :postal_code do
22
- text_at_xpath('PostalCode')
23
- end
24
-
25
- value :country_code do
26
- text_at_xpath('CountryCode')
27
- end
28
-
29
- value :phone do
30
- text_at_xpath('Phone')
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,55 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Request
4
- class Base
5
- attr :client
6
- attr_accessor :last_response
7
-
8
- def initialize(client)
9
- @client = client
10
- end
11
-
12
- def next_token
13
- node = document.at_xpath('//xmlns:NextToken')
14
- node.text if node
15
- end
16
-
17
- private
18
-
19
- def execute
20
- fetch
21
- parse
22
- end
23
-
24
- def fetch
25
- @last_response = client.post(query: parameters)
26
- end
27
-
28
- def parameters(action = nil)
29
- @parameters = Helper::Parameters.new(action) if action
30
- @parameters
31
- end
32
-
33
- def parse
34
- parser.new(node)
35
- end
36
-
37
- def parser
38
- Parser.const_get(name)
39
- end
40
-
41
- def node
42
- document.xpath("//xmlns:#{name}")
43
- end
44
-
45
- def document
46
- Nokogiri::XML(last_response.body)
47
- end
48
-
49
- def name
50
- self.class.name.split('::').last
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,23 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Request
4
- class OrderItems < Base
5
- def list(amazon_order_id)
6
- parameters(:list_order_items)
7
- .update(amazon_order_id: amazon_order_id)
8
- .camelize_keys!
9
-
10
- execute
11
- end
12
-
13
- def list_by_next_token
14
- parameters(:list_order_items_by_next_token)
15
- .update(next_token: next_token)
16
- .camelize_keys!
17
-
18
- execute
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,36 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Request
4
- class Orders < Base
5
- def get(*amazon_order_ids)
6
- parameters(:get_order)
7
- .update(amazon_order_id: amazon_order_ids)
8
- .format_structured_lists!
9
- .camelize_keys!
10
-
11
- execute
12
- end
13
-
14
- def list(options)
15
- options[:marketplace_id] ||= client.home_marketplace_id
16
-
17
- parameters(:list_orders)
18
- .update(options)
19
- .timestamp!
20
- .format_structured_lists!
21
- .camelize_keys!
22
-
23
- execute
24
- end
25
-
26
- def list_by_next_token
27
- parameters(:list_orders_by_next_token)
28
- .update(next_token: next_token)
29
- .camelize_keys!
30
-
31
- execute
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,18 +0,0 @@
1
- module MWS
2
- module Orders
3
- module Request
4
- class ServiceStatus < Base
5
- def get
6
- parameters(:get_service_status)
7
- execute
8
- end
9
-
10
- private
11
-
12
- def node
13
- document.xpath("//xmlns:GetServiceStatusResult")
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,12 +0,0 @@
1
- - country: US
2
- aws_access_key_id: AKIAJOD3NLXHOMANRNQQ
3
- aws_secret_access_key: 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
4
- seller_id: A2JYSO6W6KEP83
5
- - country: GB
6
- aws_access_key_id: AKIAJJDQ2MJTMPXKJE4A
7
- aws_secret_access_key: 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
8
- seller_id: A2D9DZ30GEWP6N
9
- - country: JP
10
- aws_access_key_id: AKIAJ5RDDSRROM6GXQ5Q
11
- aws_secret_access_key: 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
12
- seller_id: A7BU5WGNVGQ1I
@@ -1,34 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- class ParametersHelperTest < MiniTest::Test
4
- def setup
5
- @parameters = Helper::Parameters.new(:do_it)
6
- end
7
-
8
- def test_has_an_action_key
9
- assert_equal 'DoIt', @parameters.fetch('Action')
10
- end
11
-
12
- def test_formats_timestamps
13
- ts = Minitest::Mock.new
14
- ts.expect(:iso8601, 'formatted')
15
- @parameters.store('a timestamp', ts)
16
- assert_equal 'formatted', @parameters.timestamp!.fetch('a timestamp')
17
- end
18
-
19
- def test_formats_structured_lists
20
- @parameters.store(:order_status, 'foo')
21
- assert_equal 'foo', @parameters.format_structured_lists!.fetch('OrderStatus.Status.1')
22
- end
23
-
24
- def test_camelizes_keys
25
- @parameters.store(:underscored_key, 'baz')
26
- refute @parameters.camelize_keys!.has_key?(:underscored_key)
27
- assert @parameters.has_key?('UnderscoredKey')
28
- end
29
-
30
- def test_updates_delegated_hash
31
- assert_kind_of Helper::Parameters, @parameters.update(key: 'value')
32
- assert_equal 'value', @parameters.fetch(:key)
33
- end
34
- end
@@ -1,17 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- class StructuredListHelperTest < MiniTest::Test
4
- def setup
5
- @structured_list = Helper::StructuredList.new(:order_status)
6
- end
7
-
8
- def test_builds_a_structured_list_for_a_single_value
9
- exp = { 'OrderStatus.Status.1' => 'foo' }
10
- assert_equal(exp, @structured_list.build('foo'))
11
- end
12
-
13
- def test_builds_a_structured_list_for_an_array_of_values
14
- exp = { 'OrderStatus.Status.1' => 'foo', 'OrderStatus.Status.2' => 'bar' }
15
- assert_equal(exp, @structured_list.build(%w(foo bar)))
16
- end
17
- end
@@ -1,16 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class OrderItemsTest < IntegrationTest
4
- def sample_amazon_order_id(client)
5
- order = client.list_orders(created_after: Date.today - 365).to_a.sample
6
- order.amazon_order_id
7
- end
8
-
9
- def list_order_items
10
- @clients.each do |client|
11
- amazon_order_id = sample_amazon_order_id(client)
12
- order_items = client.list_order_items(amazon_order_id)
13
- refute_empty order_items
14
- end
15
- end
16
- end
@@ -1,17 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class OrdersTest < IntegrationTest
4
- def test_lists_and_gets_orders
5
- @clients.each do |client|
6
- amazon_order_ids = []
7
- orders = client.list_orders(created_after: Date.today - 365)
8
- amazon_order_ids << orders.to_a.sample.amazon_order_id
9
-
10
- orders = client.list_orders_by_next_token
11
- amazon_order_ids << orders.to_a.sample.amazon_order_id
12
-
13
- orders = client.get_order(*amazon_order_ids)
14
- assert orders
15
- end
16
- end
17
- end
@@ -1,9 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class ServiceStatusTest < IntegrationTest
4
- def test_gets_service_status
5
- @clients.each do |client|
6
- assert client.get_service_status
7
- end
8
- end
9
- end
@@ -1,12 +0,0 @@
1
- require_relative '../test_helper'
2
- require 'yaml'
3
-
4
- class IntegrationTest < MiniTest::Test
5
- def accounts
6
- YAML.load_file(File.expand_path('../../fixtures/mws.yml', __FILE__))
7
- end
8
-
9
- def setup
10
- @clients = accounts.map { |mws| Client.new(*mws.values) }
11
- end
12
- end
@@ -1,7 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class CollectionParserTest < ParserTest
4
- def test_is_enumerable
5
- assert_respond_to Parser::Collection.new(nil), :map
6
- end
7
- end
@@ -1,27 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class ModelParserTest < ParserTest
4
- def test_parses_money
5
- xml = <<-EOF
6
- <Price xmlns="example">
7
- <CurrencyCode>USD</CurrencyCode>
8
- <Amount>10.00</Amount>
9
- </Price>
10
- EOF
11
- model = Parser::Model.new(Nokogiri(xml))
12
- money = model.money_at_xpath('Price')
13
- assert_equal '$10.00', money.format
14
- end
15
-
16
- def test_parses_japanese_yen
17
- xml = <<-EOF
18
- <Price xmlns="example">
19
- <CurrencyCode>JPY</CurrencyCode>
20
- <Amount>1000.00</Amount>
21
- </Price>
22
- EOF
23
- model = Parser::Model.new(Nokogiri(xml))
24
- money = model.money_at_xpath('Price')
25
- assert_equal '¥1,000', money.format
26
- end
27
- end