to_qbxml 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +252 -0
- data/Rakefile +7 -0
- data/lib/to_qbxml/to_qbxml.rb +129 -0
- data/lib/to_qbxml/version.rb +3 -0
- data/lib/to_qbxml.rb +6 -0
- data/spec/lib/to_qbxml/to_qbxml_spec.rb +96 -0
- data/spec/spec_helper.rb +7 -0
- data/to_qbxml.gemspec +28 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Mzk2ZDQ3MjZjN2FjNWRhOTQyM2RhYmMyNjdkMzljY2RkNmQyMjIzNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTJkZTUzNzRlNjA2MWY3YzljNzMwMDAzY2U5M2U5MjYwODRhZWIzMA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTc5ZmQxZDBlNDZiNTY0ZTQ0YWVjNzM3NzJhOWVhYzJjMDkwOTZiNDk3ODM1
|
10
|
+
YTI0MGNlMTEzZTQ5MGU3NjI4OTVjNzc4NjdkYTViMjBkZDkwZjRmYmUwZGFh
|
11
|
+
ZWQ2NDUxMmI1YjdhODE3YTkwYWMzN2M4M2I3ZjI2YTNkZTQyZGE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGFmY2Q3NDQzNzAxNjdjN2ZiODU2YzQwMzIwOWQ4NDQ2Y2NmYzBmODljOTVm
|
14
|
+
NjI1ZTM2Zjk5MDMwOTRhZjE5NmI5M2ZkZjMwYWQwYTIyZjQxMjc2N2VhYmM5
|
15
|
+
YjA3NDQzNGE2MjFmYzE2ZjRiZjRjNmRjYTQ5YTU0MTJmNjQwYzc=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Christian Pelczarski
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
# ToQbxml
|
2
|
+
|
3
|
+
ToQbxml creates QuickBooks XML Requests from a Ruby Hash
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'to_qbxml'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install to_qbxml
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Create an add request
|
22
|
+
```ruby
|
23
|
+
def line_item(line_number)
|
24
|
+
{
|
25
|
+
invoice_line_add: {
|
26
|
+
item_ref: {
|
27
|
+
list_id: '3243'
|
28
|
+
},
|
29
|
+
desc: "Line #{line_number}",
|
30
|
+
amount: 10.99,
|
31
|
+
is_taxable: true,
|
32
|
+
quantity: 3,
|
33
|
+
rate_percent: 0,
|
34
|
+
repeat: [{
|
35
|
+
line: {
|
36
|
+
desc: 'inside'
|
37
|
+
}
|
38
|
+
}]
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
hash = { repeat: [ line_item(1), line_item(2) ] }
|
43
|
+
xml = ToQbxml.new(hash).make(:invoice)
|
44
|
+
puts xml
|
45
|
+
```
|
46
|
+
|
47
|
+
```xml
|
48
|
+
<?xml version="1.0" encoding="utf-8"?>
|
49
|
+
<?qbxml version="7.0"?>
|
50
|
+
<QBXML>
|
51
|
+
<QBXMLMsgsRq onError="stopOnError">
|
52
|
+
<InvoiceAddRq requestID="1">
|
53
|
+
<InvoiceAdd>
|
54
|
+
<InvoiceLineAdd>
|
55
|
+
<ItemRef>
|
56
|
+
<ListID>3243</ListID>
|
57
|
+
</ItemRef>
|
58
|
+
<Desc>Line 1</Desc>
|
59
|
+
<Amount>10.99</Amount>
|
60
|
+
<IsTaxable>true</IsTaxable>
|
61
|
+
<Quantity>3</Quantity>
|
62
|
+
<RatePercent>0</RatePercent>
|
63
|
+
<Line>
|
64
|
+
<Desc>inside</Desc>
|
65
|
+
</Line>
|
66
|
+
</InvoiceLineAdd>
|
67
|
+
<InvoiceLineAdd>
|
68
|
+
<ItemRef>
|
69
|
+
<ListID>3243</ListID>
|
70
|
+
</ItemRef>
|
71
|
+
<Desc>Line 2</Desc>
|
72
|
+
<Amount>10.99</Amount>
|
73
|
+
<IsTaxable>true</IsTaxable>
|
74
|
+
<Quantity>3</Quantity>
|
75
|
+
<RatePercent>0</RatePercent>
|
76
|
+
<Line>
|
77
|
+
<Desc>inside</Desc>
|
78
|
+
</Line>
|
79
|
+
</InvoiceLineAdd>
|
80
|
+
</InvoiceAdd>
|
81
|
+
</InvoiceAddRq>
|
82
|
+
</QBXMLMsgsRq>
|
83
|
+
</QBXML>
|
84
|
+
```
|
85
|
+
|
86
|
+
### Notes on creating repeating nodes
|
87
|
+
Use the parent node *repeat* to make repeating nodes such as *InvoiceLineAdd* and *Line*
|
88
|
+
, therefore, the hash key will be **repeat** followed by an array of hashes.
|
89
|
+
```ruby
|
90
|
+
hash = {
|
91
|
+
repeat: [
|
92
|
+
line: {
|
93
|
+
desc: 'Line 1'
|
94
|
+
},
|
95
|
+
line: {
|
96
|
+
desc: 'Line 2'
|
97
|
+
}
|
98
|
+
]
|
99
|
+
}
|
100
|
+
```
|
101
|
+
|
102
|
+
### Create a mod request
|
103
|
+
```ruby
|
104
|
+
xml = ToQbxml.new({}).make(:invoice, action: :mod)
|
105
|
+
puts xml
|
106
|
+
```
|
107
|
+
|
108
|
+
```xml
|
109
|
+
<?xml version="1.0" encoding="utf-8"?>
|
110
|
+
<?qbxml version="7.0"?>
|
111
|
+
<QBXML>
|
112
|
+
<QBXMLMsgsRq onError="stopOnError">
|
113
|
+
<InvoiceModRq requestID="1">
|
114
|
+
<InvoiceMod/>
|
115
|
+
</InvoiceModRq>
|
116
|
+
</QBXMLMsgsRq>
|
117
|
+
</QBXML>
|
118
|
+
```
|
119
|
+
|
120
|
+
|
121
|
+
### Create a query request using QBXML version 12
|
122
|
+
```ruby
|
123
|
+
hash = {
|
124
|
+
include_line_items: true,
|
125
|
+
modified_date_range_filter: {
|
126
|
+
from_modified_date: '2003-02-14T00:00:00',
|
127
|
+
to_modified_date: '2003-04-14T00:00:00'
|
128
|
+
}
|
129
|
+
}
|
130
|
+
xml = ToQbxml.new(hash, version: '12.0').make(:invoice, action: :query)
|
131
|
+
puts xml
|
132
|
+
```
|
133
|
+
|
134
|
+
```xml
|
135
|
+
<?xml version="1.0" encoding="utf-8"?>
|
136
|
+
<?qbxml version="7.0"?>
|
137
|
+
<QBXML>
|
138
|
+
<QBXMLMsgsRq onError="stopOnError">
|
139
|
+
<InvoiceQueryRq requestID="1">
|
140
|
+
<IncludeLineItems>true</IncludeLineItems>
|
141
|
+
<ModifiedDateRangeFilter>
|
142
|
+
<FromModifiedDate>2003-02-14T00:00:00</FromModifiedDate>
|
143
|
+
<ToModifiedDate>2003-04-14T00:00:00</ToModifiedDate>
|
144
|
+
</ModifiedDateRangeFilter>
|
145
|
+
</InvoiceQueryRq>
|
146
|
+
</QBXMLMsgsRq>
|
147
|
+
</QBXML>
|
148
|
+
```
|
149
|
+
|
150
|
+
### Create an iterator query request returning a Nokogiri Document instead of XML
|
151
|
+
```ruby
|
152
|
+
n = ToQbxml.new({}, doc: true).make(:customer, action: :query, attrs: { 'iterator' => 'Start'})
|
153
|
+
puts n.at('CustomerQueryRq')['iterator'].content
|
154
|
+
## Output = 'Start'
|
155
|
+
puts n.to_xml
|
156
|
+
```
|
157
|
+
|
158
|
+
```xml
|
159
|
+
<?xml version="1.0" encoding="utf-8"?>
|
160
|
+
<?qbxml version="7.0"?>
|
161
|
+
<QBXML>
|
162
|
+
<QBXMLMsgsRq onError="stopOnError">
|
163
|
+
<CustomerQueryRq requestID="1" iterator="Start"/>
|
164
|
+
</QBXMLMsgsRq>
|
165
|
+
</QBXML>
|
166
|
+
```
|
167
|
+
|
168
|
+
### Notes on using the **attrs** options
|
169
|
+
This attributes hash will not be converted to QBXML camelcase so you must supply this yourself. Also, it is best to keep the attrs consistent using an *old school* Ruby Hash with String key e.g.
|
170
|
+
```ruby
|
171
|
+
attrs = { 'requestID' => 34, 'iterator' => 'Continue', 'iteratorID' => '{2343333-434343334}' }
|
172
|
+
```
|
173
|
+
|
174
|
+
### The *initialize* method
|
175
|
+
Takes 2 arguments:
|
176
|
+
|
177
|
+
1. a Hash. This is to be the body of the QBXML request.
|
178
|
+
2. a Hash of options. See this method for a full list.
|
179
|
+
|
180
|
+
### The *make* method
|
181
|
+
Takes 2 arguments:
|
182
|
+
|
183
|
+
1. The desired QBXML request in a snakecased Symbol or String. For example, ```.make(:sales_tax_code)``` equals SalesTaxCode
|
184
|
+
2. a Hash of options. See this method for a full list.
|
185
|
+
|
186
|
+
### Examples:
|
187
|
+
See the specs for more examples
|
188
|
+
|
189
|
+
### What about validation?
|
190
|
+
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
|
+
|
192
|
+
### What about reading and parsing QBXML?
|
193
|
+
I suggest using Nokogiri. See the specs for using Nokogiri to parse QBXML.
|
194
|
+
Here are some quick examples:
|
195
|
+
|
196
|
+
#### Given
|
197
|
+
```xml
|
198
|
+
<?xml version="1.0" encoding="utf-8"?>
|
199
|
+
<?qbxml version="7.0"?>
|
200
|
+
<QBXML>
|
201
|
+
<QBXMLMsgsRq onError="stopOnError">
|
202
|
+
<InvoiceAddRq requestID="1">
|
203
|
+
<InvoiceAdd>
|
204
|
+
<InvoiceLineAdd>
|
205
|
+
<ItemRef>
|
206
|
+
<ListID>3243</ListID>
|
207
|
+
</ItemRef>
|
208
|
+
<Desc>Line 1</Desc>
|
209
|
+
<Amount>10.99</Amount>
|
210
|
+
<IsTaxable>true</IsTaxable>
|
211
|
+
<Quantity>3</Quantity>
|
212
|
+
<RatePercent>0</RatePercent>
|
213
|
+
<Line>
|
214
|
+
<Desc>inside</Desc>
|
215
|
+
</Line>
|
216
|
+
</InvoiceLineAdd>
|
217
|
+
<InvoiceLineAdd>
|
218
|
+
<ItemRef>
|
219
|
+
<ListID>3243</ListID>
|
220
|
+
</ItemRef>
|
221
|
+
<Desc>Line 2</Desc>
|
222
|
+
<Amount>10.99</Amount>
|
223
|
+
<IsTaxable>true</IsTaxable>
|
224
|
+
<Quantity>3</Quantity>
|
225
|
+
<RatePercent>0</RatePercent>
|
226
|
+
<Line>
|
227
|
+
<Desc>inside</Desc>
|
228
|
+
</Line>
|
229
|
+
</InvoiceLineAdd>
|
230
|
+
</InvoiceAdd>
|
231
|
+
</InvoiceAddRq>
|
232
|
+
</QBXMLMsgsRq>
|
233
|
+
</QBXML>
|
234
|
+
```
|
235
|
+
|
236
|
+
```
|
237
|
+
xml = qbxml_example_for_above
|
238
|
+
n = Nokogiri::XML(xml)
|
239
|
+
expect(n.css('InvoiceLineAdd').size).to eq 2
|
240
|
+
expect(n.at('InvoiceLineAdd:last > Desc').content).to eq 'Line 2'
|
241
|
+
```
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
## Contributing
|
247
|
+
|
248
|
+
1. Fork it
|
249
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
250
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
251
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
252
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
class ToQbxml
|
2
|
+
#attr_reader :hash, :options
|
3
|
+
|
4
|
+
ACRONYMS = [/Ap\z/, /Ar/, /Cogs/, /Com\z/, /Uom/, /Qbxml/, /Ui/, /Avs/, /Id\z/,
|
5
|
+
/Pin/, /Ssn/, /Clsid/, /Fob/, /Ein/, /Uom/, /Po\z/, /Pin/, /Qb/]
|
6
|
+
ATTR_ROOT = 'xml_attributes'.freeze
|
7
|
+
IGNORED_KEYS = [ATTR_ROOT]
|
8
|
+
ON_ERROR = 'stopOnError'
|
9
|
+
REPEATABLE_KEY = 'Repeat'
|
10
|
+
|
11
|
+
def initialize(hash, options = {})
|
12
|
+
@hash = hash
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def make(type, boilerplate_options = {})
|
17
|
+
@hash = boilerplate(type, boilerplate_options)
|
18
|
+
generate
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate
|
22
|
+
@hash = convert_to_qbxml_hash
|
23
|
+
xml = hash_to_xml(@hash, @options)
|
24
|
+
handler = xml_handler(xml)
|
25
|
+
@options[:doc] ? handler : handler.to_xml
|
26
|
+
end
|
27
|
+
|
28
|
+
def xml_handler(xml)
|
29
|
+
doc = Nokogiri.XML(xml, nil, @options[:encoding] || 'utf-8')
|
30
|
+
remove_tags_preserve_content(doc, REPEATABLE_KEY)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Transforms to QBXML camelcase e.g. :first_name = FirstName
|
34
|
+
# There are also special cases handled within ACRONYMS e.g. :list_id = ListID | != ListId
|
35
|
+
def convert_to_qbxml_hash
|
36
|
+
key_proc = lambda { |k| k.camelize.gsub(Regexp.union(ACRONYMS)) { |val| val.upcase }}
|
37
|
+
deep_convert(@hash, &key_proc)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Removes the parent Repeat node intended for repeatable
|
41
|
+
# nodes like InvoiceLineAdd
|
42
|
+
def remove_tags_preserve_content(doc, name)
|
43
|
+
doc.xpath(".//#{name}").reverse.each do |element|
|
44
|
+
element.children.reverse.each do |child|
|
45
|
+
child_clone = child.clone
|
46
|
+
element.add_next_sibling child_clone
|
47
|
+
child.unlink
|
48
|
+
end
|
49
|
+
element.unlink
|
50
|
+
end
|
51
|
+
doc
|
52
|
+
end
|
53
|
+
|
54
|
+
def hash_to_xml(hash, opts = {})
|
55
|
+
opts = opts.dup
|
56
|
+
opts[:indent] ||= 0
|
57
|
+
opts[:root] ||= :QBXML
|
58
|
+
opts[:version] ||= '7.0'
|
59
|
+
opts[:attributes] ||= (hash.delete(ATTR_ROOT) || {})
|
60
|
+
opts[:builder] ||= Builder::XmlMarkup.new(indent: opts[:indent])
|
61
|
+
opts[:skip_types] = true unless opts.key?(:skip_types)
|
62
|
+
opts[:skip_instruct] = false unless opts.key?(:skip_instruct)
|
63
|
+
builder = opts[:builder]
|
64
|
+
|
65
|
+
unless opts.delete(:skip_instruct)
|
66
|
+
builder.instruct!(:qbxml, version: opts[:version])
|
67
|
+
end
|
68
|
+
|
69
|
+
builder.tag!(opts[:root], opts.delete(:attributes)) do
|
70
|
+
hash.each do |key, val|
|
71
|
+
case val
|
72
|
+
when Hash
|
73
|
+
self.hash_to_xml(val, opts.merge({root: key, skip_instruct: true}))
|
74
|
+
when Array
|
75
|
+
val.map { |i| self.hash_to_xml(i, opts.merge({root: key, skip_instruct: true})) }
|
76
|
+
else
|
77
|
+
builder.tag!(key, val, {})
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
yield builder if block_given?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def boilerplate_header(type, action)
|
86
|
+
"#{type}_#{action}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def boilerplate(type, opts = {})
|
90
|
+
head = boilerplate_header(type, opts[:action] || 'add')
|
91
|
+
body_hash = opts[:action] == :query ? @hash : { head => @hash }
|
92
|
+
{ :qbxml_msgs_rq =>
|
93
|
+
[
|
94
|
+
{
|
95
|
+
:xml_attributes => { "onError" => opts[:on_error] || ON_ERROR},
|
96
|
+
head + '_rq' =>
|
97
|
+
[
|
98
|
+
{
|
99
|
+
:xml_attributes => { "requestID" => "#{opts[:request_id] || 1}" }.merge(opts[:attrs] || {})
|
100
|
+
}.merge(body_hash)
|
101
|
+
]
|
102
|
+
}
|
103
|
+
]
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def deep_convert(hash, &block)
|
110
|
+
hash.inject(Hash.new) do |h, (k,v)|
|
111
|
+
k = k.to_s
|
112
|
+
ignored = IGNORED_KEYS.include?(k)
|
113
|
+
if ignored
|
114
|
+
h[k] = v
|
115
|
+
else
|
116
|
+
key = block_given? ? yield(k) : k
|
117
|
+
h[key] = \
|
118
|
+
case v
|
119
|
+
when Hash
|
120
|
+
deep_convert(v, &block)
|
121
|
+
when Array
|
122
|
+
v.map { |i| i.is_a?(Hash) ? deep_convert(i, &block) : i }
|
123
|
+
else v
|
124
|
+
end
|
125
|
+
end; h
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
data/lib/to_qbxml.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ToQbxml do
|
4
|
+
let(:repeat_key) { ToQbxml::REPEATABLE_KEY }
|
5
|
+
|
6
|
+
context 'add or modify requests' do
|
7
|
+
it "should remove all Repeat parent tags and correctly identify line item descriptions" do
|
8
|
+
hash = { repeat: [ line_item(1), line_item(2) ] }
|
9
|
+
n = ToQbxml.new(hash, doc: true).make(:invoice)
|
10
|
+
expect(n.at('InvoiceLineAdd:first > Desc').content).to eq 'Line 1'
|
11
|
+
expect(n.at('InvoiceLineAdd:last > Desc').content).to eq 'Line 2'
|
12
|
+
expect(n.css(repeat_key)).to be_empty
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should make a mod invoice" do
|
16
|
+
n = ToQbxml.new({}, doc: true).make(:invoice, action: :mod)
|
17
|
+
expect(n.css('InvoiceModRq')).to be_present
|
18
|
+
expect(n.css('InvoiceMod')).to be_present
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be able to change the onError status" do
|
22
|
+
n = ToQbxml.new({}, doc: true).make(:invoice, on_error: 'continueOnError')
|
23
|
+
expect(n.at('QBXMLMsgsRq')['onError']).to eq 'continueOnError'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be able to manipulate a mod requests attributes" do
|
27
|
+
n = ToQbxml.new({}, doc: true).make(:customer, action: :mod, attrs: { 'requestID' => 27, 'iterator' => 'Start' })
|
28
|
+
expect(n.at('CustomerModRq')['requestID']).to eq '27'
|
29
|
+
expect(n.at('CustomerModRq')['iterator']).to eq 'Start'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should remove all parent tags with a node just having the word 'repeat' a part of it" do
|
33
|
+
hash = { word_with_repeat: [ line_item(1), line_item(2) ] }
|
34
|
+
xml = ToQbxml.new(hash).make(:invoice)
|
35
|
+
expect(xml).to match /\<WordWithRepeat/
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be qbxml version 12" do
|
39
|
+
xml = ToQbxml.new({}, version: '12.0').generate
|
40
|
+
expect(xml).to match /version=\"12\.0/
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have the default encoding of utf-8" do
|
44
|
+
xml = ToQbxml.new({}).generate
|
45
|
+
expect(xml).to match /encoding=\"utf-8/
|
46
|
+
end
|
47
|
+
|
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/
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'query requests' do
|
55
|
+
it 'makes a simple iterator query request' do
|
56
|
+
n = ToQbxml.new({}, doc: true).make(:customer, action: :query, attrs: { 'iterator' => 'Start'})
|
57
|
+
#puts n.to_xml
|
58
|
+
expect(n.at('CustomerQueryRq')['iterator']).to eq 'Start'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'makes a complete query request' do
|
62
|
+
hash = {
|
63
|
+
include_line_items: true,
|
64
|
+
modified_date_range_filter: {
|
65
|
+
from_modified_date: '2003-02-14T00:00:00',
|
66
|
+
to_modified_date: '2003-04-14T00:00:00'
|
67
|
+
}
|
68
|
+
}
|
69
|
+
n = ToQbxml.new(hash, doc: true).make(:invoice, action: :query)
|
70
|
+
#puts n.to_xml
|
71
|
+
expect(n.at('InvoiceQueryRq > IncludeLineItems').content).to eq 'true'
|
72
|
+
expect(n.at('InvoiceQueryRq > ModifiedDateRangeFilter > FromModifiedDate').content).to eq hash[:modified_date_range_filter][:from_modified_date]
|
73
|
+
expect(n.at('InvoiceQueryRq > ModifiedDateRangeFilter > ToModifiedDate').content).to eq hash[:modified_date_range_filter][:to_modified_date]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def line_item(line_number)
|
78
|
+
{
|
79
|
+
invoice_line_add: {
|
80
|
+
item_ref: {
|
81
|
+
list_id: '3243'
|
82
|
+
},
|
83
|
+
desc: "Line #{line_number}",
|
84
|
+
amount: 10.99,
|
85
|
+
is_taxable: true,
|
86
|
+
quantity: 3,
|
87
|
+
rate_percent: 0,
|
88
|
+
repeat: [{
|
89
|
+
line: {
|
90
|
+
desc: 'inside'
|
91
|
+
}
|
92
|
+
}]
|
93
|
+
}
|
94
|
+
}
|
95
|
+
end
|
96
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/to_qbxml.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'to_qbxml/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "to_qbxml"
|
8
|
+
gem.version = ToQbxml::VERSION
|
9
|
+
gem.authors = ["Christian Pelczarski (minimul)"]
|
10
|
+
gem.email = ["christian@minimul.com"]
|
11
|
+
gem.description = %q{Ruby Hash to QuickBooks XML Request}
|
12
|
+
gem.summary = %q{Takes Ruby Hash and turns it into QuickBooks XML Request}
|
13
|
+
gem.homepage = "http://minimul.com"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency('activesupport', '~> 3.2')
|
21
|
+
gem.add_dependency('nokogiri', '~> 1.6')
|
22
|
+
gem.add_dependency('builder', '~> 3.0')
|
23
|
+
gem.add_dependency('json', '~> 1.8')
|
24
|
+
|
25
|
+
gem.add_development_dependency('bundler', '~> 1.5')
|
26
|
+
gem.add_development_dependency('rake', '~> 10.1')
|
27
|
+
gem.add_development_dependency('rspec', '~> 3.1', '>= 3.1.0')
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: to_qbxml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Pelczarski (minimul)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: builder
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.1'
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 3.1.0
|
107
|
+
type: :development
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ~>
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '3.1'
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 3.1.0
|
117
|
+
description: Ruby Hash to QuickBooks XML Request
|
118
|
+
email:
|
119
|
+
- christian@minimul.com
|
120
|
+
executables: []
|
121
|
+
extensions: []
|
122
|
+
extra_rdoc_files: []
|
123
|
+
files:
|
124
|
+
- .gitignore
|
125
|
+
- Gemfile
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- lib/to_qbxml.rb
|
130
|
+
- lib/to_qbxml/to_qbxml.rb
|
131
|
+
- lib/to_qbxml/version.rb
|
132
|
+
- spec/lib/to_qbxml/to_qbxml_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
- to_qbxml.gemspec
|
135
|
+
homepage: http://minimul.com
|
136
|
+
licenses: []
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ! '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.2.2
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Takes Ruby Hash and turns it into QuickBooks XML Request
|
158
|
+
test_files:
|
159
|
+
- spec/lib/to_qbxml/to_qbxml_spec.rb
|
160
|
+
- spec/spec_helper.rb
|
161
|
+
has_rdoc:
|