to_qbxml 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MWUzZjZkYjBjOWNlYjY3YmZmYzk0ZTk3Y2FiZmI0Mzg5MDM2Mjg5Ng==
5
- data.tar.gz: !binary |-
6
- NzllM2E0ZGJjYjU3ZTU0NGU4NTY4ODcwMTUxNzkyZjZjYmY0OWI4NQ==
2
+ SHA1:
3
+ metadata.gz: 7d0fae5d6caaaad3ea2983cbc676bab80fa7b4f2
4
+ data.tar.gz: 7240d049dbdd4087a97fca788f43cf2c6030af2b
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MGM2YzNmNGNlMTI0YTA0MGM1YTlmNDZkOTg0NjA5OWJiZjQwMTM1Mzk4YTc1
10
- YWFiZThiODdkN2RlYmM0NDg2YTA0OWY4YzVkNTg0YWQ3Nzc3OTRhZGIxMGJi
11
- ZDY4MTBiYmRjMDA2MjI2ODM4YzdkNTkxNmQ0M2E1ZTMzNDgzNWU=
12
- data.tar.gz: !binary |-
13
- N2NlNmZlOWMwN2Q3NzJkNzc1ZmY4NWZmZDFhNTM4NTdmYzYwZmNjOTQ5ZGQx
14
- MmE5NGZiMDFjYTFlYTA2OTFiYTdkYWRkNmQxZWQyZGM0MjU5M2VjYjgyY2Ni
15
- YmU3YjM4MTU4MzkyNjdmMWEyMjkyZTEwZDlmNzJlNjhjOWViZjU=
6
+ metadata.gz: 1ade8547d07b29bd8d134d0b04e6a14ade7131261a6adfdfbbbb8f306a01497bf2ce10e8b327f5725407fa175660e06bfb6193ed6be8f28766ea702a9ec4f8e4
7
+ data.tar.gz: 1931412d8a4eae44df43828960de1cd89f8eb206163695fc9c3dcf68aec60d76d624cf1f197020afb663da397a6a00be47b1ea1310e363125ea9dab4cf9d0aba
data/README.md CHANGED
@@ -18,6 +18,15 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ ### Configuration
22
+ ```
23
+ ToQbxml.configure do |config|
24
+ config.version = '11.0'
25
+ config.on_error = 'continueOnError'
26
+ end
27
+
28
+ ```
29
+
21
30
  ### Create an add request
22
31
  ```ruby
23
32
  def line_item(line_number)
@@ -45,7 +54,7 @@ Or install it yourself as:
45
54
  ```
46
55
 
47
56
  ```xml
48
- <?xml version="1.0" encoding="utf-8"?>
57
+ <?xml version="1.0" encoding="US-ASCII"?>
49
58
  <?qbxml version="7.0"?>
50
59
  <QBXML>
51
60
  <QBXMLMsgsRq onError="stopOnError">
@@ -106,7 +115,7 @@ Use the parent node *repeat* to make repeating nodes such as *InvoiceLineAdd* an
106
115
  ```
107
116
 
108
117
  ```xml
109
- <?xml version="1.0" encoding="utf-8"?>
118
+ <?xml version="1.0" encoding="US-ASCII"?>
110
119
  <?qbxml version="7.0"?>
111
120
  <QBXML>
112
121
  <QBXMLMsgsRq onError="stopOnError">
@@ -132,8 +141,8 @@ Use the parent node *repeat* to make repeating nodes such as *InvoiceLineAdd* an
132
141
  ```
133
142
 
134
143
  ```xml
135
- <?xml version="1.0" encoding="utf-8"?>
136
- <?qbxml version="7.0"?>
144
+ <?xml version="1.0" encoding="US-ASCII"?>
145
+ <?qbxml version="12.0"?>
137
146
  <QBXML>
138
147
  <QBXMLMsgsRq onError="stopOnError">
139
148
  <InvoiceQueryRq requestID="1">
@@ -156,7 +165,7 @@ Use the parent node *repeat* to make repeating nodes such as *InvoiceLineAdd* an
156
165
  ```
157
166
 
158
167
  ```xml
159
- <?xml version="1.0" encoding="utf-8"?>
168
+ <?xml version="1.0" encoding="US-ASCII"?>
160
169
  <?qbxml version="7.0"?>
161
170
  <QBXML>
162
171
  <QBXMLMsgsRq onError="stopOnError">
@@ -186,6 +195,10 @@ Takes 2 arguments:
186
195
  ### Examples:
187
196
  See the [specs](https://github.com/minimul/to_qbxml/blob/master/spec/lib/to_qbxml/to_qbxml_spec.rb) for more examples
188
197
 
198
+ ### What about encoding?
199
+
200
+ This library is hard coded for US-ASCII because that is what is accepted by the QBSDK. Fool around with UTF-8 at your own peril.
201
+
189
202
  ### What about validation?
190
203
  This library provides no validation or schema validation. In my experience, it is best to use the [OCR docs](http://developer-static.intuit.com/qbsdk-current/common/newosr/index.html) and the [QBXML validator and SDKTest utilities](https://developer.intuit.com/docs/0250_qb/0010_get_oriented/0060_sdk_components) that come bundled with the standard QBSDK installation. These tools are only available on Windows but if you are wanting to do any serious integration with QuickBooks Desktop then you better have a Windows machine or VM handy.
191
204
 
@@ -195,7 +208,7 @@ Here are some quick examples:
195
208
 
196
209
  #### Given
197
210
  ```xml
198
- <?xml version="1.0" encoding="utf-8"?>
211
+ <?xml version="1.0" encoding="US-ASCII"?>
199
212
  <?qbxml version="7.0"?>
200
213
  <QBXML>
201
214
  <QBXMLMsgsRq onError="stopOnError">
@@ -1,16 +1,35 @@
1
1
  class ToQbxml
2
- #attr_reader :hash, :options
3
-
4
2
  ACRONYMS = [/Ap\z/, /Ar/, /Cogs/, /Com\z/, /Uom/, /Qbxml/, /Ui/, /Avs/, /Id\z/,
5
3
  /Pin/, /Ssn/, /Clsid/, /Fob/, /Ein/, /Uom/, /Po\z/, /Pin/, /Qb/]
6
4
  ATTR_ROOT = 'xml_attributes'.freeze
7
5
  IGNORED_KEYS = [ATTR_ROOT]
8
- ON_ERROR = 'stopOnError'
9
6
  REPEATABLE_KEY = 'Repeat'
10
7
 
11
8
  def initialize(hash, options = {})
12
9
  @hash = hash
13
10
  @options = options
11
+ @version = ToQbxml.version
12
+ @on_error = ToQbxml.on_error
13
+ end
14
+
15
+ def self.configure(&block)
16
+ yield self
17
+ end
18
+
19
+ def self.version
20
+ @version ||= '7.0'
21
+ end
22
+
23
+ def self.version=(number)
24
+ @version = number
25
+ end
26
+
27
+ def self.on_error
28
+ @on_error ||= 'stopOnError'
29
+ end
30
+
31
+ def self.on_error=(err_kind)
32
+ @on_error = err_kind
14
33
  end
15
34
 
16
35
  def make(type, boilerplate_options = {})
@@ -22,11 +41,11 @@ class ToQbxml
22
41
  @hash = convert_to_qbxml_hash
23
42
  xml = hash_to_xml(@hash, @options)
24
43
  handler = xml_handler(xml)
25
- @options[:doc] ? handler : handler.to_xml
44
+ @options[:doc] ? handler : handler.to_xml(encoding: 'US-ASCII')
26
45
  end
27
46
 
28
47
  def xml_handler(xml)
29
- doc = Nokogiri.XML(xml, nil, @options[:encoding] || 'utf-8')
48
+ doc = Nokogiri.XML(xml)
30
49
  remove_tags_preserve_content(doc, REPEATABLE_KEY)
31
50
  end
32
51
 
@@ -55,7 +74,7 @@ class ToQbxml
55
74
  opts = opts.dup
56
75
  opts[:indent] ||= 0
57
76
  opts[:root] ||= :QBXML
58
- opts[:version] ||= '7.0'
77
+ opts[:version] ||= @version
59
78
  opts[:attributes] ||= (hash.delete(ATTR_ROOT) || {})
60
79
  opts[:builder] ||= Builder::XmlMarkup.new(indent: opts[:indent])
61
80
  opts[:skip_types] = true unless opts.key?(:skip_types)
@@ -92,7 +111,7 @@ class ToQbxml
92
111
  { :qbxml_msgs_rq =>
93
112
  [
94
113
  {
95
- :xml_attributes => { "onError" => opts[:on_error] || ON_ERROR},
114
+ :xml_attributes => { "onError" => opts[:on_error] || @on_error},
96
115
  head + '_rq' =>
97
116
  [
98
117
  {
@@ -1,3 +1,3 @@
1
1
  class ToQbxml
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe ToQbxml do
@@ -40,15 +41,36 @@ describe ToQbxml do
40
41
  expect(xml).to match /version=\"12\.0/
41
42
  end
42
43
 
43
- it "should have the default encoding of utf-8" do
44
+ it "default version is 7.0" do
44
45
  xml = ToQbxml.new({}).generate
45
- expect(xml).to match /encoding=\"utf-8/
46
+ expect(xml).to match /version=\"7\.0/
46
47
  end
47
48
 
48
- it "should be able to change the default encoding" do
49
- xml = ToQbxml.new({}, encoding: 'windows-1251').generate
50
- expect(xml).to match /encoding=\"windows-1251/
49
+ it "should change system-wide qbxml version to 10.0" do
50
+ ToQbxml.configure do |config|
51
+ config.version = '11.0'
52
+ end
53
+ xml = ToQbxml.new({}).generate
54
+ expect(xml).to match /version=\"11\.0/
55
+ end
56
+
57
+ it "default on_error is stopOnError" do
58
+ xml = ToQbxml.new({}).make(:customer)
59
+ expect(xml).to match /onError=\"stopOnError/
60
+ end
61
+
62
+ it "should change system-wide on_error" do
63
+ ToQbxml.on_error = 'continueOnError'
64
+ xml = ToQbxml.new({}).make(:invoice)
65
+ expect(xml).to match /onError=\"continueOnError/
66
+ end
67
+
68
+ it "should properly encode special characters" do
69
+ hash = { name: 'Lè Car <"Häns">'}
70
+ xml = ToQbxml.new(hash).make(:customer)
71
+ expect(xml).to match /Name\>L&#232; Car &lt;\"H&#228;ns\"&gt;/
51
72
  end
73
+
52
74
  end
53
75
 
54
76
  context 'query requests' do
metadata CHANGED
@@ -1,117 +1,117 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_qbxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Pelczarski (minimul)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.6'
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
40
  version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: builder
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.8'
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
68
  version: '1.8'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.5'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '10.1'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '10.1'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '3.1'
104
- - - ! '>='
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
106
  version: 3.1.0
107
107
  type: :development
108
108
  prerelease: false
109
109
  version_requirements: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - ~>
111
+ - - "~>"
112
112
  - !ruby/object:Gem::Version
113
113
  version: '3.1'
114
- - - ! '>='
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: 3.1.0
117
117
  description: Ruby Hash to QuickBooks XML Request
@@ -121,7 +121,7 @@ executables: []
121
121
  extensions: []
122
122
  extra_rdoc_files: []
123
123
  files:
124
- - .gitignore
124
+ - ".gitignore"
125
125
  - Gemfile
126
126
  - LICENSE.txt
127
127
  - README.md
@@ -141,21 +141,20 @@ require_paths:
141
141
  - lib
142
142
  required_ruby_version: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - ! '>='
144
+ - - ">="
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  requirements:
149
- - - ! '>='
149
+ - - ">="
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
153
  rubyforge_project:
154
- rubygems_version: 2.2.2
154
+ rubygems_version: 2.4.6
155
155
  signing_key:
156
156
  specification_version: 4
157
157
  summary: Takes Ruby Hash and turns it into QuickBooks XML Request
158
158
  test_files:
159
159
  - spec/lib/to_qbxml/to_qbxml_spec.rb
160
160
  - spec/spec_helper.rb
161
- has_rdoc: