mws-orders 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffeac9dc8722894336970c9aff3a24f421cdf781299f4b71f7a17337666e29ee
4
- data.tar.gz: f6696c0924e4f4d4e1a1ea39c01e74e8638a57e5fd12aa74d6c3eb8969087b3b
3
+ metadata.gz: 5024482ae6bb34ce7a6066333ab17e2bad0c8cd98330ef2d17710c843114c1bb
4
+ data.tar.gz: 2d2235a1ccd194a58cfb162d4cd89990e3878a232c62b0c7325f30d595dd0cf4
5
5
  SHA512:
6
- metadata.gz: 49b0857eaafcecd6f75220b6961b9a7e82b4dc3a5f53ed2f635f63979b7991781325be5e1b363f664576426b67af88d72d8c7cddd475c629803dbde4f16669b0
7
- data.tar.gz: f00ddc5e0649389dcc953c09725d5bec260261832e11848a5b0e05425fe1b0dc85ecfea895a5affa3b9a17ca80767914c028965e670f75fa7cd386ca135fb80c
6
+ metadata.gz: a0e92ba47bfc2feb5513324f22a60abd078528c327e1be3e22a0d27940f7f45d5917e3708cbda335967d3cb2cbffe9364a4677f359af01d698c897d6c4b52883
7
+ data.tar.gz: 75677d6f12e108daf1331ba3d18b5d2c54717abd79a85999e68545a13f18773a8804577d5d063710e2fdba7a6b8a151d4b3035f795774f9c3d55bf86d43b9747
data/README.md CHANGED
@@ -11,9 +11,9 @@ 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(marketplace: "ATVPDKIKX0DER",
16
- merchant_id: "123")
14
+ require 'mws/orders/parser'
15
+ client = MWS.orders(marketplace: 'ATVPDKIKX0DER',
16
+ merchant_id: '123')
17
17
  ```
18
18
 
19
19
  Set up credentials [when instantiating or with environment variables](https://github.com/hakanensari/peddler#usage).
@@ -39,7 +39,7 @@ client.list_orders_by_next_token(orders.next_token).parse
39
39
  Get one or more orders based on their order numbers:
40
40
 
41
41
  ```ruby
42
- response = client.get_order("123-1234567-1234567")
42
+ response = client.get_order('123-1234567-1234567')
43
43
  order = response.parse
44
44
  puts order # => #<MWS::Orders::Order amazon_order_id="123...
45
45
  ```
@@ -49,7 +49,7 @@ puts order # => #<MWS::Orders::Order amazon_order_id="123...
49
49
  List order items:
50
50
 
51
51
  ```ruby
52
- response = client.list_order_items("123-1234567-1234567")
52
+ response = client.list_order_items('123-1234567-1234567')
53
53
  order_items = response.parse
54
54
  ```
55
55
 
@@ -15,12 +15,12 @@ module MWS
15
15
  count.zero?
16
16
  end
17
17
 
18
+ def attributes
19
+ map(&:attributes)
20
+ end
21
+
18
22
  def inspect
19
- "#<#{self.class} #{if count > 3
20
- "[#{take(3).map(&:inspect).join(', ')}...]"
21
- else
22
- "[#{map(&:inspect).join(', ')}]"
23
- end}>"
23
+ "#<#{self.class.name} #{to_a}>"
24
24
  end
25
25
 
26
26
  alias to_s inspect
@@ -4,7 +4,7 @@ require 'mws/orders/entity'
4
4
 
5
5
  module MWS
6
6
  module Orders
7
- class ServiceStatusMessage < Entity
7
+ class Message < Entity
8
8
  attribute(:locale) do
9
9
  text_at_xpath('Locale')
10
10
  end
@@ -112,6 +112,10 @@ module MWS
112
112
  attribute(:latest_delivered_at) do
113
113
  time_at_xpath('LatestDeliveryDate')
114
114
  end
115
+
116
+ def to_s
117
+ amazon_order_id
118
+ end
115
119
  end
116
120
  end
117
121
  end
@@ -105,6 +105,10 @@ module MWS
105
105
  attribute(:scheduled_delivery_starts_at) do
106
106
  time_at_xpath('ScheduledDeliveryStartDate')
107
107
  end
108
+
109
+ def to_s
110
+ order_item_id
111
+ end
108
112
  end
109
113
  end
110
114
  end
@@ -4,6 +4,7 @@ require 'nokogiri'
4
4
  require 'mws/orders/orders'
5
5
  require 'mws/orders/order_items'
6
6
  require 'mws/orders/service_status'
7
+ require 'peddler'
7
8
 
8
9
  module MWS
9
10
  module Orders
@@ -15,19 +16,12 @@ module MWS
15
16
  end
16
17
 
17
18
  def parse
18
- node = find_result_node
19
-
20
- case node.name
21
- when /GetServiceStatus/
22
- ServiceStatus.new(node)
23
- when /GetOrder/
24
- Orders.new(node).first
25
- when /ListOrders/
26
- Orders.new(node)
27
- when /ListOrderItems/
28
- OrderItems.new(node)
29
- else
30
- raise NotImplementedError
19
+ case result_node.name
20
+ when /GetOrder/ then order
21
+ when /GetServiceStatus/ then service_status
22
+ when /ListOrders/ then orders
23
+ when /ListOrderItems/ then order_items
24
+ else raise NotImplementedError
31
25
  end
32
26
  end
33
27
 
@@ -35,10 +29,38 @@ module MWS
35
29
  @response.headers
36
30
  end
37
31
 
32
+ def status_code
33
+ @response.status
34
+ end
35
+
36
+ def body
37
+ @response.body
38
+ end
39
+
38
40
  private
39
41
 
42
+ def order
43
+ orders.first
44
+ end
45
+
46
+ def orders
47
+ Orders.new(result_node)
48
+ end
49
+
50
+ def order_items
51
+ OrderItems.new(result_node)
52
+ end
53
+
54
+ def service_status
55
+ ServiceStatus.new(result_node)
56
+ end
57
+
58
+ def result_node
59
+ @result_node ||= find_result_node
60
+ end
61
+
40
62
  def find_result_node
41
- xml = Nokogiri(@response.body)
63
+ xml = Nokogiri(body)
42
64
  root = xml.children.first
43
65
 
44
66
  root.children.find { |node| node.name.include?('Result') }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'mws/orders/entity'
4
- require 'mws/orders/service_status_message'
4
+ require 'mws/orders/message'
5
5
 
6
6
  module MWS
7
7
  module Orders
@@ -19,7 +19,7 @@ module MWS
19
19
  end
20
20
 
21
21
  attribute(:messages) do
22
- xpath('Messages/Message').map { |node| ServiceStatusMessage.new(node) }
22
+ xpath('Messages/Message').map { |node| Message.new(node) }
23
23
  end
24
24
  end
25
25
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module MWS
4
4
  module Orders
5
- VERSION = '0.3.1'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -30,10 +30,10 @@ class TestEntity < MiniTest::Test
30
30
  XML
31
31
  entity = build_entity(xml)
32
32
  money = entity.money_at_xpath('Price')
33
- assert_equal '$10.00', money.format
33
+ assert_equal 1000, money.fractional
34
34
  end
35
35
 
36
- def test_parses_japanese_yen
36
+ def test_parses_yen
37
37
  xml = <<-XML
38
38
  <Price xmlns="example">
39
39
  <CurrencyCode>JPY</CurrencyCode>
@@ -42,8 +42,7 @@ class TestEntity < MiniTest::Test
42
42
  XML
43
43
  entity = build_entity(xml)
44
44
  money = entity.money_at_xpath('Price')
45
-
46
- assert_equal '¥1,000', money.format
45
+ assert_equal 1000, money.fractional
47
46
  end
48
47
 
49
48
  def test_parses_text
@@ -2,10 +2,10 @@
2
2
 
3
3
  require 'test_helper'
4
4
 
5
- class TestServiceStatusMessage < MiniTest::Test
5
+ class TestMessage < MiniTest::Test
6
6
  def setup
7
- node = load_xml_fixture('service_status').xpath('//xmlns:Message').first
8
- @message = ServiceStatusMessage.new(node)
7
+ node = load_fixture('service_status').xpath('//xmlns:Message').first
8
+ @message = Message.new(node)
9
9
  end
10
10
 
11
11
  def test_locale
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
 
5
5
  class TestOrder < MiniTest::Test
6
6
  def setup
7
- node = load_xml_fixture('orders').at_xpath('//xmlns:Order')
7
+ node = load_fixture('orders').at_xpath('//xmlns:Order')
8
8
  @order = Order.new(node)
9
9
  end
10
10
 
@@ -92,4 +92,8 @@ class TestOrder < MiniTest::Test
92
92
  def test_latest_delivered_at
93
93
  assert_kind_of Time, @order.latest_delivered_at
94
94
  end
95
+
96
+ def test_to_s
97
+ assert_equal @order.amazon_order_id, @order.to_s
98
+ end
95
99
  end
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
 
5
5
  class TestOrderItemTest < MiniTest::Test
6
6
  def setup
7
- node = load_xml_fixture('order_items').at_xpath('//xmlns:OrderItem')
7
+ node = load_fixture('order_items').at_xpath('//xmlns:OrderItem')
8
8
  @order_item = OrderItem.new(node)
9
9
  end
10
10
 
@@ -67,4 +67,8 @@ class TestOrderItemTest < MiniTest::Test
67
67
  def test_gift_wrap_level
68
68
  assert_kind_of String, @order_item.gift_wrap_level
69
69
  end
70
+
71
+ def test_to_s
72
+ assert_equal @order_item.order_item_id, @order_item.to_s
73
+ end
70
74
  end
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
 
5
5
  class TestOrderItems < MiniTest::Test
6
6
  def setup
7
- node = load_xml_fixture('order_items').xpath('//xmlns:ListOrderItemsResult')
7
+ node = load_fixture('order_items').xpath('//xmlns:ListOrderItemsResult')
8
8
  @order_items = OrderItems.new(node)
9
9
  end
10
10
 
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
 
5
5
  class TestOrders < MiniTest::Test
6
6
  def setup
7
- node = load_xml_fixture('orders').xpath('//xmlns:ListOrdersResult')
7
+ node = load_fixture('orders').xpath('//xmlns:ListOrdersResult')
8
8
  @orders = Orders.new(node)
9
9
  end
10
10
 
@@ -5,8 +5,8 @@ require 'test_helper'
5
5
  class TestPaymentExecutionDetail < MiniTest::Test
6
6
  def setup
7
7
  node =
8
- load_xml_fixture('orders').xpath('//xmlns:PaymentExecutionDetail')
9
- .first
8
+ load_fixture('orders').xpath('//xmlns:PaymentExecutionDetail')
9
+ .first
10
10
  @ped = PaymentExecutionDetail.new(node)
11
11
  end
12
12
 
@@ -5,8 +5,7 @@ require 'test_helper'
5
5
  class TestPaymentExecutionDetailItem < MiniTest::Test
6
6
  def setup
7
7
  node =
8
- load_xml_fixture('orders').xpath('//xmlns:PaymentExecutionDetailItem')
9
- .first
8
+ load_fixture('orders').xpath('//xmlns:PaymentExecutionDetailItem').first
10
9
  @pedi = PaymentExecutionDetailItem.new(node)
11
10
  end
12
11
 
@@ -5,8 +5,8 @@ require 'test_helper'
5
5
  class TestServiceStatus < MiniTest::Test
6
6
  def setup
7
7
  node =
8
- load_xml_fixture('service_status').xpath('//xmlns:GetServiceStatusResult')
9
- .first
8
+ load_fixture('service_status').xpath('//xmlns:GetServiceStatusResult')
9
+ .first
10
10
  @status = ServiceStatus.new(node)
11
11
  end
12
12
 
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
 
5
5
  class TestShippingAddress < MiniTest::Test
6
6
  def setup
7
- node = load_xml_fixture('orders').xpath('//xmlns:ShippingAddress').first
7
+ node = load_fixture('orders').xpath('//xmlns:ShippingAddress').first
8
8
  @address = ShippingAddress.new(node)
9
9
  end
10
10
 
@@ -1,12 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'minitest/autorun'
4
- require 'mws-orders'
5
-
6
- begin
7
- require 'pry'
8
- rescue LoadError
9
- end
4
+ require 'mws/orders/parser'
10
5
 
11
6
  I18n.enforce_available_locales = false
12
7
 
@@ -14,7 +9,7 @@ module MiniTest
14
9
  class Test
15
10
  include MWS::Orders
16
11
 
17
- def load_xml_fixture(type)
12
+ def load_fixture(type)
18
13
  file = File.expand_path("../fixtures/#{type}.xml", __FILE__)
19
14
  body = File.read(file)
20
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mws-orders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hakan Ensari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2019-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: money
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.5'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.5'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: peddler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,28 +58,70 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.0'
61
+ version: '2.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.0'
69
- description: A rich Ruby interface to the Amazon MWS Orders API
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
70
112
  email:
71
- - hakanensari@gmail.com
113
+ - me@hakanensari.com
72
114
  executables: []
73
115
  extensions: []
74
116
  extra_rdoc_files: []
75
117
  files:
76
118
  - LICENSE
77
119
  - README.md
78
- - lib/mws-orders.rb
79
120
  - lib/mws/orders/collection.rb
80
121
  - lib/mws/orders/document.rb
81
122
  - lib/mws/orders/entity.rb
82
123
  - lib/mws/orders/invoice_data.rb
124
+ - lib/mws/orders/message.rb
83
125
  - lib/mws/orders/order.rb
84
126
  - lib/mws/orders/order_item.rb
85
127
  - lib/mws/orders/order_items.rb
@@ -88,7 +130,6 @@ files:
88
130
  - lib/mws/orders/payment_execution_detail.rb
89
131
  - lib/mws/orders/payment_execution_detail_item.rb
90
132
  - lib/mws/orders/service_status.rb
91
- - lib/mws/orders/service_status_message.rb
92
133
  - lib/mws/orders/shipping_address.rb
93
134
  - lib/mws/orders/tokenable.rb
94
135
  - lib/mws/orders/version.rb
@@ -96,6 +137,7 @@ files:
96
137
  - test/fixtures/orders.xml
97
138
  - test/fixtures/service_status.xml
98
139
  - test/mws/orders/test_entity.rb
140
+ - test/mws/orders/test_message.rb
99
141
  - test/mws/orders/test_order.rb
100
142
  - test/mws/orders/test_order_item.rb
101
143
  - test/mws/orders/test_order_items.rb
@@ -104,7 +146,6 @@ files:
104
146
  - test/mws/orders/test_payment_execution_detail.rb
105
147
  - test/mws/orders/test_payment_execution_detail_item.rb
106
148
  - test/mws/orders/test_service_status.rb
107
- - test/mws/orders/test_service_status_message.rb
108
149
  - test/mws/orders/test_shipping_address.rb
109
150
  - test/mws/orders/test_tokenable.rb
110
151
  - test/test_helper.rb
@@ -120,25 +161,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
161
  requirements:
121
162
  - - ">="
122
163
  - !ruby/object:Gem::Version
123
- version: '2.3'
164
+ version: '2.4'
124
165
  required_rubygems_version: !ruby/object:Gem::Requirement
125
166
  requirements:
126
167
  - - ">="
127
168
  - !ruby/object:Gem::Version
128
169
  version: '0'
129
170
  requirements: []
130
- rubyforge_project:
131
- rubygems_version: 2.7.6
171
+ rubygems_version: 3.0.3
132
172
  signing_key:
133
173
  specification_version: 4
134
- summary: Wraps the Amazon MWS Orders API
174
+ summary: A Ruby wrapper for the Amazon MWS Orders API
135
175
  test_files:
136
176
  - test/mws/orders/test_orders.rb
137
- - test/mws/orders/test_service_status_message.rb
138
177
  - test/mws/orders/test_order.rb
139
178
  - test/mws/orders/test_service_status.rb
140
179
  - test/mws/orders/test_shipping_address.rb
141
180
  - test/mws/orders/test_tokenable.rb
181
+ - test/mws/orders/test_message.rb
142
182
  - test/mws/orders/test_payment_execution_detail_item.rb
143
183
  - test/mws/orders/test_order_items.rb
144
184
  - test/mws/orders/test_entity.rb
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'peddler'
4
- require 'mws/orders/parser'