cxml-ruby 0.4.0 → 0.7.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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -0
  3. data/.rubocop.yml +4 -0
  4. data/CHANGELOG.md +18 -0
  5. data/cxml-ruby.gemspec +1 -0
  6. data/lib/cxml-ruby.rb +1 -1
  7. data/lib/cxml/address.rb +4 -1
  8. data/lib/cxml/comment.rb +9 -0
  9. data/lib/cxml/contact.rb +4 -1
  10. data/lib/cxml/country_code.rb +9 -0
  11. data/lib/cxml/credential.rb +1 -1
  12. data/lib/cxml/deposit_amount.rb +9 -0
  13. data/lib/cxml/document.rb +11 -6
  14. data/lib/cxml/document_node.rb +5 -5
  15. data/lib/cxml/invoice_detail_item.rb +11 -11
  16. data/lib/cxml/invoice_detail_item_reference.rb +3 -1
  17. data/lib/cxml/invoice_detail_request_header.rb +5 -5
  18. data/lib/cxml/invoice_detail_summary.rb +6 -4
  19. data/lib/cxml/item_detail.rb +5 -1
  20. data/lib/cxml/order_request_header.rb +11 -10
  21. data/lib/cxml/parser.rb +29 -2
  22. data/lib/cxml/phone.rb +13 -0
  23. data/lib/cxml/postal_address.rb +1 -1
  24. data/lib/cxml/telephone_number.rb +11 -0
  25. data/lib/cxml/version.rb +1 -1
  26. data/spec/document_spec.rb +33 -1
  27. data/spec/fixtures/1.2.014-cXML.dtd +4184 -0
  28. data/spec/fixtures/1.2.020-InvoiceDetail.dtd +4590 -0
  29. data/spec/fixtures/1.2.020-cXML.dtd +4917 -0
  30. data/spec/fixtures/1.2.037-InvoiceDetail.dtd +7287 -0
  31. data/spec/fixtures/invoice_taxes_at_line_multiple_taxes.xml +1 -3
  32. data/spec/fixtures/item_in.xml +2 -1
  33. data/spec/fixtures/{order_request.cxml → order_request.xml} +0 -0
  34. data/spec/fixtures/punch_out_order_message_doc.xml +1 -1
  35. data/spec/fixtures/punch_out_setup_request_doc_with_ship_to.xml +7 -0
  36. data/spec/fixtures/response_status_200.xml +1 -1
  37. data/spec/fixtures/response_status_400.xml +2 -2
  38. data/spec/invoice_detail_request_spec.rb +21 -1
  39. data/spec/item_in_spec.rb +5 -0
  40. data/spec/money_spec.rb +8 -0
  41. data/spec/output/.gitkeep +0 -0
  42. data/spec/punch_out_order_message_spec.rb +5 -0
  43. data/spec/punch_out_setup_request_spec.rb +2 -0
  44. data/spec/purchase_order_request_spec.rb +6 -1
  45. data/spec/sender_spec.rb +6 -0
  46. data/spec/spec_helper.rb +27 -0
  47. metadata +20 -5
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
 
3
- <!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2...oiceDetail.dtd">
3
+ <!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.037/InvoiceDetail.dtd">
4
4
 
5
5
  <cXML version="1.0" payloadID="1240598937@SUBDOMAIN.coupahost.com" timestamp="2018-05-04T01:24:51-07:00">
6
6
 
@@ -176,11 +176,9 @@
176
176
 
177
177
  <DiscountPercent percent="1" />
178
178
 
179
- <DiscountDueDays>1</DiscountDueDays>
180
179
 
181
180
  </Discount>
182
181
 
183
- <NetDueDays>1</NetDueDays>
184
182
 
185
183
  </PaymentTerm>
186
184
 
@@ -4,8 +4,9 @@
4
4
  <SupplierPartAuxiliaryID>lkajsdflsdf</SupplierPartAuxiliaryID>
5
5
  </ItemID>
6
6
  <ItemDetail>
7
- <Description xml:lang="en">AGENDA MAGAZINE RACK A4 CHARCOAL 25990</Description>
7
+ <Description xml:lang="en"><![CDATA[AGENDA MAGAZINE RACK A4 CHARCOAL 25990]]></Description>
8
8
  <UnitOfMeasure>EA</UnitOfMeasure>
9
9
  <UnitPrice> <Money currency="GBP">5.35</Money> </UnitPrice>
10
+ <Classification domain="UNSPSC">44000000</Classification>
10
11
  </ItemDetail>
11
12
  </ItemIn>
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0"?>
2
- <cxml version="1.2.011" payloadID="1346769469000.process.162998590@officedepot.com" timestamp="2012-09-04T02:37:49-05:00">
2
+ <cxml version="1.2.020" payloadID="1346769469000.process.162998590@officedepot.com" timestamp="2012-09-04T02:37:49-05:00">
3
3
  <Header>
4
4
  <From>
5
5
  <Credential domain="NetworkID">
@@ -39,6 +39,13 @@
39
39
  <Country isoCountryCode="US">United States</Country>
40
40
  </PostalAddress>
41
41
  <Email name="default">jmadden@coupa1.com</Email>
42
+ <Phone name="work">
43
+ <TelephoneNumber>
44
+ <CountryCode isoCountryCode="US">1</CountryCode>
45
+ <AreaOrCityCode>855</AreaOrCityCode>
46
+ <Number>8671234</Number>
47
+ </TelephoneNumber>
48
+ </Phone>
42
49
  </Address>
43
50
  </ShipTo>
44
51
  </PunchOutSetupRequest>
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <cXML version="1.2.011" payloadID="1346769469000.process.162998590@officedepot.com" timestamp="2012-09-04T02:37:49-05:00">
2
+ <cXML version="1.2.020" payloadID="1346769469000.process.162998590@officedepot.com" timestamp="2012-09-04T02:37:49-05:00">
3
3
  <Response>
4
4
  <Status code="200" text="OK"/>
5
5
  <PunchOutSetupResponse>
@@ -1,5 +1,5 @@
1
- <cXML version="1.2.011" payloadID="1352382581000.process.454701738@domain.com" timestamp="2012-11-08T01:49:41-05:00">
1
+ <cXML version="1.2.020" payloadID="1352382581000.process.454701738@domain.com" timestamp="2012-11-08T01:49:41-05:00">
2
2
  <Response>
3
3
  <Status code="400" text="java.lang.Exception: missing required parameter 'document'"/>
4
4
  </Response>
5
- </cXML>
5
+ </cXML>
@@ -50,34 +50,54 @@ describe CXML::InvoiceDetailRequest do
50
50
  data = CXML::Parser.new(data: fixture('invoice_taxes_at_line.xml')).parse
51
51
  doc = CXML::Document.new(data)
52
52
  CXML::Parser.new(data: doc.to_xml).parse.should eq(data)
53
+ next unless test_for_xmllint
54
+
55
+ lint_doc_with_dtd(doc).should be true
53
56
  end
54
57
  it 'serializes the same output' do
55
58
  data = CXML::Parser.new(data: fixture('invoice_backed_and_unbacked_by_pos.xml')).parse
56
59
  doc = CXML::Document.new(data)
57
60
  CXML::Parser.new(data: doc.to_xml).parse.should eq(data)
61
+ next unless test_for_xmllint
62
+
63
+ lint_doc_with_dtd(doc).should be true
58
64
  end
59
65
  it 'serializes the same output' do
60
66
  data = CXML::Parser.new(data: fixture('invoice_backed_by_multiple_pos.xml')).parse
61
67
  doc = CXML::Document.new(data)
62
68
  CXML::Parser.new(data: doc.to_xml).parse.should eq(data)
69
+ next unless test_for_xmllint
70
+
71
+ lint_doc_with_dtd(doc).should be true
63
72
  end
64
73
  it 'serializes the same output' do
65
74
  data = CXML::Parser.new(data: fixture('invoice_taxes_at_line_multiple_taxes.xml')).parse
66
75
  doc = CXML::Document.new(data)
67
76
  CXML::Parser.new(data: doc.to_xml).parse.should eq(data)
77
+ next unless test_for_xmllint
78
+
79
+ lint_doc_with_dtd(doc).should be true
68
80
  end
69
81
  it 'serializes the same output' do
70
82
  fixture_xml = fixture('invoice_taxes_at_total.xml')
71
83
  data = CXML::Parser.new(data: fixture_xml).parse
72
84
  doc = CXML::Document.new(data)
73
85
  CXML::Parser.new(data: doc.to_xml).parse.should eq(data)
86
+ next unless test_for_xmllint
87
+
88
+ lint_doc_with_dtd(doc).should be true
74
89
  end
75
90
  it 'serializes from an instance' do
76
91
  money = CXML::Money.new(amount: '5', currency: 'USD')
77
92
  summary = CXML::InvoiceDetailSummary.new(gross_amount: CXML::GrossAmount.new(money: money))
78
93
  instance = described_class.new(invoice_detail_summary: summary)
79
94
  data = CXML::Request.new(invoice_detail_request: instance)
80
- doc = CXML::Document.new(request: data)
95
+ doc = CXML::Document.new(
96
+ request: data,
97
+ header: CXML::Header.new,
98
+ dtd: 'InvoiceDetail',
99
+ payload_id: 'foo'
100
+ )
81
101
  parsed = CXML::Parser.new(data: doc.to_xml).parse
82
102
  parsed[:request][:invoice_detail_request]
83
103
  .should eq(instance.serializable_hash)
@@ -35,5 +35,10 @@ describe CXML::ItemIn do
35
35
  item_in_output_data[:item_id].should_not be_empty
36
36
  item_in_output_data[:item_detail].should_not be_empty
37
37
  end
38
+ it 'validates against the DTD' do
39
+ next unless test_for_xmllint
40
+
41
+ lint_doc_with_dtd(CXML::Document.new.from_xml(output_xml)).should be true
42
+ end
38
43
  end
39
44
  end
@@ -38,5 +38,13 @@ describe CXML::Money do
38
38
  it 'contains the required nodes' do
39
39
  money_output_data[:currency].should_not be_empty
40
40
  end
41
+
42
+ it 'can render non-string values' do
43
+ CXML::Document.new(message: { punch_out_order_message: {
44
+ punch_out_order_message_header: {
45
+ total: { money: { content: 12.3 } },
46
+ },
47
+ } }).to_xml
48
+ end
41
49
  end
42
50
  end
File without changes
@@ -36,5 +36,10 @@ describe CXML::PunchOutOrderMessage do
36
36
  punch_out_order_message_output_data[:buyer_cookie].should_not be_empty
37
37
  punch_out_order_message_output_data.should include(:item_in)
38
38
  end
39
+ it 'validates against the DTD' do
40
+ next unless test_for_xmllint
41
+
42
+ lint_doc_with_dtd(CXML::Document.new.from_xml(output_xml)).should be true
43
+ end
39
44
  end
40
45
  end
@@ -38,6 +38,8 @@ describe CXML::PunchOutSetupRequest do
38
38
  doc = CXML::Document.new(data)
39
39
  doc.request.punch_out_setup_request.ship_to.should_not be_nil
40
40
  doc.request.punch_out_setup_request.ship_to.address.name.should_not be_nil
41
+ doc.request.punch_out_setup_request.ship_to.address.phone.should_not be_nil
42
+ doc.request.punch_out_setup_request.ship_to.address.phone.telephone_number.should_not be_nil
41
43
  end
42
44
  end
43
45
 
@@ -19,6 +19,11 @@ describe CXML::OrderRequest do
19
19
  order_request_output_data[:item_out].should be_a Array
20
20
  order_request_output_data[:item_out].length.should eq 2
21
21
  end
22
+ it 'validates against the DTD' do
23
+ next unless test_for_xmllint
24
+
25
+ lint_doc_with_dtd(doc).should be true
26
+ end
22
27
  end
23
28
  describe '#initialize' do
24
29
  it 'sets the required nodes' do
@@ -27,7 +32,7 @@ describe CXML::OrderRequest do
27
32
  order_request.items_out.first.should_not be_nil
28
33
  end
29
34
  it 'sets the required nodes via another order request' do
30
- request = CXML::Document.new.from_xml(fixture('order_request.cxml')).request
35
+ request = CXML::Document.new.from_xml(fixture('order_request.xml')).request
31
36
  request.order_request.order_request_header.should_not be_nil
32
37
  request.order_request.order_request_header.order_id.should_not be_nil
33
38
  request.order_request.items_out.first.should_not be_nil
@@ -26,5 +26,11 @@ describe CXML::Sender do
26
26
  sender_output_data[:user_agent].should_not be_empty
27
27
  sender_output_data[:credential].should_not be_empty
28
28
  end
29
+
30
+ it 'validates against the DTD' do
31
+ next unless test_for_xmllint
32
+
33
+ lint_doc_with_dtd(CXML::Document.new.from_xml(output_xml)).should be true
34
+ end
29
35
  end
30
36
  end
@@ -9,6 +9,7 @@ Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
9
9
 
10
10
  RSpec.configure do |config|
11
11
  config.expect_with(:rspec) { |c| c.syntax = :should }
12
+ config.default_formatter = 'doc' if config.files_to_run.one?
12
13
  end
13
14
 
14
15
  def fixture_path(filename = nil)
@@ -19,3 +20,29 @@ end
19
20
  def fixture(file)
20
21
  File.read(File.join(fixture_path, file))
21
22
  end
23
+
24
+ def dtd_path_from_url(url)
25
+ return 'spec/fixtures/1.2.037-cXML.dtd' unless url
26
+
27
+ match = url.match(%r{/(\d+\.\d+\.\d+)/(\w+\.dtd)}).to_a
28
+ file = "spec/fixtures/#{match.last(2).join('-')}"
29
+ return file if File.exist?(file)
30
+
31
+ system("curl #{url} -O && mv #{match.last} #{file}")
32
+ file
33
+ end
34
+
35
+ def test_for_xmllint
36
+ return true if system('type xmllint > /dev/null 2>&1')
37
+
38
+ puts 'skipping DTD validation without xmllint'
39
+ false
40
+ end
41
+
42
+ def lint_doc_with_dtd(doc)
43
+ file = "spec/output/#{rand}.xml"
44
+ File.open(file, 'w') { |f| f.puts doc.to_xml }
45
+ linted = system("xmllint --noout --dtdvalid #{dtd_path_from_url(doc.dtd_url)} #{file}")
46
+ File.delete(file) if File.exist?(file)
47
+ linted
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cxml-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Beckman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-04-20 00:00:00.000000000 Z
12
+ date: 2021-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ox
@@ -108,16 +108,19 @@ files:
108
108
  - lib/cxml/browser_form_post.rb
109
109
  - lib/cxml/charge.rb
110
110
  - lib/cxml/classification.rb
111
+ - lib/cxml/comment.rb
111
112
  - lib/cxml/confirmation_header.rb
112
113
  - lib/cxml/confirmation_item.rb
113
114
  - lib/cxml/confirmation_request.rb
114
115
  - lib/cxml/confirmation_status.rb
115
116
  - lib/cxml/contact.rb
116
117
  - lib/cxml/country.rb
118
+ - lib/cxml/country_code.rb
117
119
  - lib/cxml/credential.rb
118
120
  - lib/cxml/credential_mac.rb
119
121
  - lib/cxml/deducted_price.rb
120
122
  - lib/cxml/deduction_amount.rb
123
+ - lib/cxml/deposit_amount.rb
121
124
  - lib/cxml/description.rb
122
125
  - lib/cxml/discount.rb
123
126
  - lib/cxml/discount_percent.rb
@@ -168,6 +171,7 @@ files:
168
171
  - lib/cxml/parser.rb
169
172
  - lib/cxml/payment_term.rb
170
173
  - lib/cxml/period.rb
174
+ - lib/cxml/phone.rb
171
175
  - lib/cxml/postal_address.rb
172
176
  - lib/cxml/protocol.rb
173
177
  - lib/cxml/punch_out_order_message.rb
@@ -193,6 +197,7 @@ files:
193
197
  - lib/cxml/tax_detail.rb
194
198
  - lib/cxml/tax_location.rb
195
199
  - lib/cxml/taxable_amount.rb
200
+ - lib/cxml/telephone_number.rb
196
201
  - lib/cxml/to.rb
197
202
  - lib/cxml/total.rb
198
203
  - lib/cxml/total_allowances.rb
@@ -204,6 +209,10 @@ files:
204
209
  - spec/cxml_spec.rb
205
210
  - spec/document_spec.rb
206
211
  - spec/fixtures/.gitkeep
212
+ - spec/fixtures/1.2.014-cXML.dtd
213
+ - spec/fixtures/1.2.020-InvoiceDetail.dtd
214
+ - spec/fixtures/1.2.020-cXML.dtd
215
+ - spec/fixtures/1.2.037-InvoiceDetail.dtd
207
216
  - spec/fixtures/envelope.xml
208
217
  - spec/fixtures/envelope2.xml
209
218
  - spec/fixtures/invoice_backed_and_unbacked_by_pos.xml
@@ -212,7 +221,7 @@ files:
212
221
  - spec/fixtures/invoice_taxes_at_line_multiple_taxes.xml
213
222
  - spec/fixtures/invoice_taxes_at_total.xml
214
223
  - spec/fixtures/item_in.xml
215
- - spec/fixtures/order_request.cxml
224
+ - spec/fixtures/order_request.xml
216
225
  - spec/fixtures/punch_out_order_message_doc.xml
217
226
  - spec/fixtures/punch_out_setup_request_doc.xml
218
227
  - spec/fixtures/punch_out_setup_request_doc_coupa.xml
@@ -227,6 +236,7 @@ files:
227
236
  - spec/item_id_spec.rb
228
237
  - spec/item_in_spec.rb
229
238
  - spec/money_spec.rb
239
+ - spec/output/.gitkeep
230
240
  - spec/parser_spec.rb
231
241
  - spec/protocol_spec.rb
232
242
  - spec/punch_out_order_message_header_spec.rb
@@ -251,7 +261,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
251
261
  requirements:
252
262
  - - ">="
253
263
  - !ruby/object:Gem::Version
254
- version: '0'
264
+ version: '2.4'
255
265
  required_rubygems_version: !ruby/object:Gem::Requirement
256
266
  requirements:
257
267
  - - ">="
@@ -267,6 +277,10 @@ test_files:
267
277
  - spec/cxml_spec.rb
268
278
  - spec/document_spec.rb
269
279
  - spec/fixtures/.gitkeep
280
+ - spec/fixtures/1.2.014-cXML.dtd
281
+ - spec/fixtures/1.2.020-InvoiceDetail.dtd
282
+ - spec/fixtures/1.2.020-cXML.dtd
283
+ - spec/fixtures/1.2.037-InvoiceDetail.dtd
270
284
  - spec/fixtures/envelope.xml
271
285
  - spec/fixtures/envelope2.xml
272
286
  - spec/fixtures/invoice_backed_and_unbacked_by_pos.xml
@@ -275,7 +289,7 @@ test_files:
275
289
  - spec/fixtures/invoice_taxes_at_line_multiple_taxes.xml
276
290
  - spec/fixtures/invoice_taxes_at_total.xml
277
291
  - spec/fixtures/item_in.xml
278
- - spec/fixtures/order_request.cxml
292
+ - spec/fixtures/order_request.xml
279
293
  - spec/fixtures/punch_out_order_message_doc.xml
280
294
  - spec/fixtures/punch_out_setup_request_doc.xml
281
295
  - spec/fixtures/punch_out_setup_request_doc_coupa.xml
@@ -290,6 +304,7 @@ test_files:
290
304
  - spec/item_id_spec.rb
291
305
  - spec/item_in_spec.rb
292
306
  - spec/money_spec.rb
307
+ - spec/output/.gitkeep
293
308
  - spec/parser_spec.rb
294
309
  - spec/protocol_spec.rb
295
310
  - spec/punch_out_order_message_header_spec.rb