gentle 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/gentle/documents/request/rma_document.rb +84 -0
- data/lib/gentle/documents/response/shipment_order_result.rb +4 -0
- data/lib/gentle/request.rb +2 -1
- data/lib/gentle/version.rb +1 -1
- data/spec/spec_helper.rb +71 -0
- data/spec/unit/documents/request/rma_document_spec.rb +59 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac1168e00550479a4f358c13eedfb72000994ad3
|
4
|
+
data.tar.gz: 9bf880dbdc5a3d542b5ec0ed0b589b03dded03c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cba459dd7c952479b79e822864c5952cb8a2454b3617ac3e7c61f3cfe2f52741e871cfe56198876c7736b30244d7523cf339faa88cf12ed5892c5d2a58c5089
|
7
|
+
data.tar.gz: eba1ea53a4c8438ea4ebff136c3bf35e599c9f6778beb044aa9e8b36be4c3907f9dba513bfcc9d6ee0dfcf9e2689fc32b918315b4c34852f77d0cc1c38960893
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
module Gentle
|
3
|
+
module Documents
|
4
|
+
module Request
|
5
|
+
class RMADocument
|
6
|
+
include Gentle::Documents::Document
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
NAMESPACE = "http://schemas.quietlogistics.com/V2/RMADocument.xsd"
|
10
|
+
|
11
|
+
DATEFORMAT = "%Y%m%d_%H%M%S"
|
12
|
+
|
13
|
+
class MissingOrderError < StandardError; end
|
14
|
+
class MissingClientError < StandardError; end
|
15
|
+
|
16
|
+
attr_reader :rma, :config, :name
|
17
|
+
|
18
|
+
def initialize(options = {})
|
19
|
+
@config = options.fetch(:config).symbolize_keys
|
20
|
+
@rma = options.fetch(:rma)
|
21
|
+
@order = @rma.order
|
22
|
+
@name = "RMA_#{@rma.number}_#{date_stamp}.xml"
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_xml
|
26
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
27
|
+
xml.RMADocument('xmlns' => 'http://schemas.quietlogistics.com/V2/RMADocument.xsd') do
|
28
|
+
xml.RMA('ClientID' => @config[:client_id],
|
29
|
+
'BusinessUnit' => @config[:business_unit],
|
30
|
+
'RMANumber' => @rma.number,
|
31
|
+
'Warehouse' => warehouse,
|
32
|
+
'TrackingNumber' => @rma.tracking_number) do
|
33
|
+
|
34
|
+
@rma.returned_items.each do |returned_item|
|
35
|
+
xml.Line('LineNo' => returned_item.line_item_id,
|
36
|
+
'OrderNumber' => @order.number,
|
37
|
+
'ItemNumber' => returned_item.sku,
|
38
|
+
'Quantity' => returned_item.quantity,
|
39
|
+
'SaleUOM' => 'EA', #Each
|
40
|
+
'ReturnReason' => @rma.reason.name,
|
41
|
+
'CustomerComment' => ''
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
builder.to_xml
|
48
|
+
end
|
49
|
+
|
50
|
+
def message
|
51
|
+
"Sent RMA #{@number} to QL"
|
52
|
+
end
|
53
|
+
|
54
|
+
def date_stamp
|
55
|
+
Time.now.strftime('%Y%m%d_%H%M%3N')
|
56
|
+
end
|
57
|
+
|
58
|
+
def business_unit
|
59
|
+
@config[:business_unit]
|
60
|
+
end
|
61
|
+
|
62
|
+
def type
|
63
|
+
'RMADocument'
|
64
|
+
end
|
65
|
+
|
66
|
+
def document_number
|
67
|
+
@rma.number
|
68
|
+
end
|
69
|
+
|
70
|
+
def warehouse
|
71
|
+
'Default'
|
72
|
+
end
|
73
|
+
|
74
|
+
def date
|
75
|
+
@rma.created_at
|
76
|
+
end
|
77
|
+
|
78
|
+
def filename
|
79
|
+
"#{business_unit}_#{type}_#{document_number}_#{date.strftime(DATEFORMAT)}.xml"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/gentle/request.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'gentle/documents/request/shipment_order'
|
2
|
+
require 'gentle/documents/request/rma_document'
|
2
3
|
|
3
4
|
module Gentle
|
4
5
|
module Request
|
5
|
-
VALID_REQUEST_TYPES = %w(ShipmentOrder)
|
6
|
+
VALID_REQUEST_TYPES = %w(ShipmentOrder, RMADocument)
|
6
7
|
|
7
8
|
def self.valid_type?(type)
|
8
9
|
VALID_REQUEST_TYPES.include?(type)
|
data/lib/gentle/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -256,6 +256,77 @@ class OrderDouble
|
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
259
|
+
class ReasonDouble
|
260
|
+
attr_accessor :name
|
261
|
+
DEFAULT_OPTIONS = {
|
262
|
+
name: 'Fitting'
|
263
|
+
}
|
264
|
+
def initialize(options = {})
|
265
|
+
@name = options[:name]
|
266
|
+
end
|
267
|
+
def self.example(options = {})
|
268
|
+
self.new(DEFAULT_OPTIONS.merge(options))
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
class InventoryUnitDouble
|
273
|
+
attr_accessor :variant, :line_item, :line_item_id
|
274
|
+
|
275
|
+
DEFAULT_OPTIONS = {
|
276
|
+
line_item_id: 1,
|
277
|
+
line_item: LineItemDouble.example,
|
278
|
+
variant: VariantDouble.example
|
279
|
+
}
|
280
|
+
def initialize(options = {})
|
281
|
+
@line_item_id = options[:line_item_id]
|
282
|
+
@line_item = options[:line_item]
|
283
|
+
@variant = options[:variant]
|
284
|
+
end
|
285
|
+
def self.example(options = {})
|
286
|
+
self.new(DEFAULT_OPTIONS.merge(options))
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
class ReturnItemDouble
|
291
|
+
attr_accessor :inventory_unit
|
292
|
+
|
293
|
+
DEFAULT_OPTIONS = {
|
294
|
+
inventory_unit: InventoryUnitDouble.example,
|
295
|
+
}
|
296
|
+
def initialize(options = {})
|
297
|
+
@inventory_unit = options[:inventory_unit]
|
298
|
+
end
|
299
|
+
def self.example(options = {})
|
300
|
+
self.new(DEFAULT_OPTIONS.merge(options))
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
class RMADouble
|
305
|
+
attr_accessor :return_items, :order, :config, :reason, :number, :tracking_number, :created_at
|
306
|
+
|
307
|
+
DEFAULT_OPTIONS = {
|
308
|
+
number: 'RMA1234567',
|
309
|
+
tracking_number: 'UPS1234',
|
310
|
+
return_items: [ReturnItemDouble.example],
|
311
|
+
reason: ReasonDouble.example,
|
312
|
+
config: { client_id: 123, business_unit: 'BU123'},
|
313
|
+
created_at: Time.new(2013, 04, 07, 13, 45, 00)
|
314
|
+
|
315
|
+
}
|
316
|
+
def initialize(options = {})
|
317
|
+
@number = options[:number]
|
318
|
+
@tracking_number = options[:tracking_number]
|
319
|
+
@return_items = options[:return_items]
|
320
|
+
@reason = options[:reason]
|
321
|
+
@config = options[:config]
|
322
|
+
@order = options[:order]
|
323
|
+
@created_at = options[:created_at]
|
324
|
+
end
|
325
|
+
def self.example(options = {})
|
326
|
+
self.new(DEFAULT_OPTIONS.merge(options))
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
259
330
|
class ShipmentDouble
|
260
331
|
DEFAULT_OPTIONS = {
|
261
332
|
shipping_method: ShippingMethodDouble.example,
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gentle/documents/request/shipment_order'
|
3
|
+
|
4
|
+
module Gentle
|
5
|
+
module Documents
|
6
|
+
module Request
|
7
|
+
describe "RMADocument" do
|
8
|
+
include Gentle::Documents::DocumentInterfaceTestcases
|
9
|
+
|
10
|
+
before do
|
11
|
+
@order = OrderDouble.example
|
12
|
+
@rma = RMADouble.example
|
13
|
+
@config = RMADouble::DEFAULT_OPTIONS[:config]
|
14
|
+
|
15
|
+
@rma.order = @order
|
16
|
+
@object = @RMADocument = RMADocument.new(config: @config, rma: @rma)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should raise an error if an RMA wasn't passed in" do
|
20
|
+
assert_raises KeyError do
|
21
|
+
RMADocument.new(client: @client)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be able to generate an XML document" do
|
26
|
+
document = Nokogiri::XML::Document.parse(@RMADocument.to_xml)
|
27
|
+
|
28
|
+
expected_namespaces = {'xmlns' => 'http://schemas.quietlogistics.com/V2/RMADocument.xsd'}
|
29
|
+
assert_equal expected_namespaces, document.collect_namespaces()
|
30
|
+
|
31
|
+
assert_equal 1, document.css('RMA').length
|
32
|
+
assert_equal @config[:client_id], document.css("RMA").attr('ClientID').value.to_i
|
33
|
+
assert_equal @config[:business_unit], document.css("RMA").attr('BusinessUnit').value
|
34
|
+
assert_equal @rma.number, document.css("RMA").attr('RMANumber').value
|
35
|
+
assert_equal @rma.tracking_number, document.css("RMA").attr('TrackingNumber').value
|
36
|
+
|
37
|
+
|
38
|
+
line_items = document.css('Line')
|
39
|
+
assert_equal 1, line_items.length
|
40
|
+
assert_line_item(@order.line_items.first, line_items.first)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def assert_line_item(expected_line_item, line_item)
|
47
|
+
assert_equal "1", line_item['LineNo']
|
48
|
+
assert_equal @order.number, line_item['OrderNumber']
|
49
|
+
assert_equal expected_line_item.sku.to_s, line_item['ItemNumber']
|
50
|
+
assert_equal expected_line_item.quantity.to_s, line_item['Quantity']
|
51
|
+
assert_equal "EA", line_item['SaleUOM']
|
52
|
+
assert_equal @rma.reason.name, line_item['ReturnReason']
|
53
|
+
assert_equal "", line_item['CustomerComment']
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gentle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DynamoMTL
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/gentle/client.rb
|
127
127
|
- lib/gentle/documents/document.rb
|
128
128
|
- lib/gentle/documents/request/hash_converter.rb
|
129
|
+
- lib/gentle/documents/request/rma_document.rb
|
129
130
|
- lib/gentle/documents/request/shipment_order.rb
|
130
131
|
- lib/gentle/documents/response/shipment_order_result.rb
|
131
132
|
- lib/gentle/error_message.rb
|
@@ -146,6 +147,7 @@ files:
|
|
146
147
|
- spec/unit/client_spec.rb
|
147
148
|
- spec/unit/documents/document_spec.rb
|
148
149
|
- spec/unit/documents/request/hash_converter_spec.rb
|
150
|
+
- spec/unit/documents/request/rma_document_spec.rb
|
149
151
|
- spec/unit/documents/request/shipment_order_spec.rb
|
150
152
|
- spec/unit/documents/response/shipment_order_result_spec.rb
|
151
153
|
- spec/unit/error_message_spec.rb
|
@@ -188,9 +190,11 @@ test_files:
|
|
188
190
|
- spec/unit/client_spec.rb
|
189
191
|
- spec/unit/documents/document_spec.rb
|
190
192
|
- spec/unit/documents/request/hash_converter_spec.rb
|
193
|
+
- spec/unit/documents/request/rma_document_spec.rb
|
191
194
|
- spec/unit/documents/request/shipment_order_spec.rb
|
192
195
|
- spec/unit/documents/response/shipment_order_result_spec.rb
|
193
196
|
- spec/unit/error_message_spec.rb
|
194
197
|
- spec/unit/message_spec.rb
|
195
198
|
- spec/unit/phase_1_set_spec.rb
|
196
199
|
- spec/unit/queue_spec.rb
|
200
|
+
has_rdoc:
|