quickbooks-ruby-base 1.0.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 +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +138 -0
- data/Rakefile +7 -0
- data/lib/quickbooks/base/configuration.rb +29 -0
- data/lib/quickbooks/base.rb +82 -0
- data/lib/quickbooks-ruby-base.rb +1 -0
- data/quickbooks-ruby-base.gemspec +23 -0
- data/spec/fixtures/invoices.xml +152 -0
- data/spec/fixtures/tax_codes.xml +58 -0
- data/spec/fixtures/vendors.xml +95 -0
- data/spec/quickbooks_ruby_base_spec.rb +97 -0
- data/spec/spec_helper.rb +6 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTQ4YTRkMzhlOWMyMGZhNWEzNDVhNTY0ZjM1Zjc5ZGU0NTkyZGY3Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjU3N2RjMDgyNzE5ODEzMjMwNTYzODY3ZWM0NzY4N2UxYjAyZDcwZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjcxODk1NDAxMzMzMTRlOGJhNzMwZWI4ZDM0NzlkMWM0Yzc4Y2M5YTE2YTdh
|
10
|
+
OWEwZmFlZTRmNjNhMjkzZjNmYzk1NTBjNDQ0YmJhNTIwODFhMGM1Yzg2NGVj
|
11
|
+
YmU5Mzk0ZTdjNjhlOWExMTViMmFlNDljMGZkYTBjNTM0NDg1NDI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MzllMDg1NGFhOGRkNmE5MjMwZDRjNDE2Mjc4ZjFkMmU4YTY0MGFhMDNjMWVi
|
14
|
+
M2RmMTJiOGM3ODE2MzY4ZTI4NWRmNDJjMzg1ODI0Zjg2ZjM5ZDcxYWJiNWZl
|
15
|
+
ZjYyMDdjZWIwOTQwMTgxMWMxZjhhZjRlMjIzM2UxZmQyMWNlNzU=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Christian
|
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,138 @@
|
|
1
|
+
# Quickbooks::Base
|
2
|
+
|
3
|
+
A gem to complement the [`quickbooks-ruby`](https://github.com/ruckus/quickbooks-ruby) gem by providing a base class to handle routine tasks like creating a model, service, and displaying information.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'quickbooks-ruby-base'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install quickbooks-ruby-base
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
1. The first argument is required and is a persistent object holding Intuit OAuth information (see Configuration section).
|
21
|
+
2. The second argument is optional but if passed must be a valid `quickbooks-ruby` service type such as Invoice, Customer, Item, PaymentMethod, etc. When passing in a symbol, snake case must be used e.g. `:payment_method`. If a string you must use the explicit name, e.g. 'PaymentMethod'
|
22
|
+
```
|
23
|
+
def initialize(account, type = nil)
|
24
|
+
@account = account
|
25
|
+
create_service_for(type) if type
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
### qr_model(*args)
|
30
|
+
Generate a `quickbooks-ruby` model. First argument must be valid `quickbooks-ruby` model.
|
31
|
+
```
|
32
|
+
>> base = Quickbooks::Base.new(account)
|
33
|
+
>> customer = base.qr_model(:customer)
|
34
|
+
|
35
|
+
# Accepts more than 1 argument e.g.
|
36
|
+
>> base = Quickbooks::Base.new(account)
|
37
|
+
>> qb_invoice = base.qr_model :invoice
|
38
|
+
>> qb_invoice.bill_email = base.qr_model(:email_address, invoice.customer.email)
|
39
|
+
```
|
40
|
+
|
41
|
+
### service()
|
42
|
+
Returns `quickbooks-ruby` service.
|
43
|
+
```
|
44
|
+
>> base = Quickbooks::Base.new(account, :customer)
|
45
|
+
>> base.service
|
46
|
+
=> #<Quickbooks::Service::Customer:0x007faf7fe3f130 @base_uri="https://qb.sbfinance.intuit.com/v3/company", .etc
|
47
|
+
>> customer = base.qr_model(:customer)
|
48
|
+
>> customer.display_name = 'Minimul X'
|
49
|
+
# Do a create
|
50
|
+
>> base.service.create(customer)
|
51
|
+
# Or an update
|
52
|
+
>> base.service.update(customer)
|
53
|
+
# Execute a query
|
54
|
+
>> base.service.query('SELECT * FROM INVOICES')
|
55
|
+
```
|
56
|
+
|
57
|
+
### show(options = {})
|
58
|
+
Returns an array of the QuickBooks' IDs and a "smart" description. Smart, meaning that different services have different identifiers. For a customer, employee, and vendor the `DESC` is `display_name`. For invoice, it is `doc_number`. For item, tax_code, and payment_method it is the `name`.
|
59
|
+
```
|
60
|
+
base = Quickbooks::Base.new(account, :invoice)
|
61
|
+
>> base.service.create(qb_invoice)
|
62
|
+
# Returns an array of payment_methods from QBO account
|
63
|
+
base = Quickbooks::Base.new(account, :payment_method)
|
64
|
+
>> base.show
|
65
|
+
# Returns an array of payment_methods from QBO account
|
66
|
+
>> b.show
|
67
|
+
=> ["QBID: 5 DESC: American Express", "QBID: 1 DESC: Cash", "QBID: 2 DESC: Check", "QBID: 6 DESC: Diners Club", "QBID: 7 DESC: Discover", "QBID: 4 DESC: MasterCard", "QBID: 3 DESC: Visa"]
|
68
|
+
# With options
|
69
|
+
>> b.show page:1, per_page: 3
|
70
|
+
=> ["QBID: 5 DESC: American Express", "QBID: 1 DESC: Cash", "QBID: 2 DESC: Check"]
|
71
|
+
|
72
|
+
```
|
73
|
+
|
74
|
+
## Configuration
|
75
|
+
|
76
|
+
As the first argument, the `Quickbooks::Base` class expects a persistent object that holds OAuth connection information.
|
77
|
+
|
78
|
+
For example, if an account's OAuth information is stored like this:
|
79
|
+
```
|
80
|
+
account.qb_token
|
81
|
+
account.qb_secret
|
82
|
+
account.qb_company_id
|
83
|
+
```
|
84
|
+
|
85
|
+
Your `Quickbooks::Base` configuration would look like this.
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
QB_KEY = ENV['MINIMULCASTS_CONSUMER_KEY']
|
90
|
+
QB_SECRET = ENV['MINIMULCASTS_CONSUMER_SECRET']
|
91
|
+
|
92
|
+
$qb_oauth_consumer = OAuth::Consumer.new(QB_KEY, QB_SECRET, {
|
93
|
+
:site => "https://oauth.intuit.com",
|
94
|
+
:request_token_path => "/oauth/v1/get_request_token",
|
95
|
+
:authorize_url => "https://appcenter.intuit.com/Connect/Begin",
|
96
|
+
:access_token_path => "/oauth/v1/get_access_token"
|
97
|
+
})
|
98
|
+
|
99
|
+
Quickbooks::Base.configure do |c|
|
100
|
+
c.persistent_token = 'qb_token'
|
101
|
+
c.persistent_secret = 'qb_secret'
|
102
|
+
c.persistent_company_id = 'qb_company_id'
|
103
|
+
end
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
### Configuration defaults
|
108
|
+
```
|
109
|
+
p Quickbooks::Base.persistent_token
|
110
|
+
# "settings.qb_token"
|
111
|
+
p Quickbooks::Base.persistent_secret
|
112
|
+
# "settings.qb_secret"
|
113
|
+
p Quickbooks::Base.persistent_company_id
|
114
|
+
# "settings.qb_company_id"
|
115
|
+
```
|
116
|
+
By default `quickbooks-base-ruby` uses the `$qb_oauth_consumer` global var but can be overridden e.g.:
|
117
|
+
|
118
|
+
```
|
119
|
+
$intuit_oauth_consumer = OAuth::Consumer.new(QB_KEY, QB_SECRET, {
|
120
|
+
:site => "https://oauth.intuit.com",
|
121
|
+
:request_token_path => "/oauth/v1/get_request_token",
|
122
|
+
:authorize_url => "https://appcenter.intuit.com/Connect/Begin",
|
123
|
+
:access_token_path => "/oauth/v1/get_access_token"
|
124
|
+
})
|
125
|
+
|
126
|
+
Quickbooks::Base.configure do |c|
|
127
|
+
c.oauth_consumer = $intuit_oauth_consumer
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
131
|
+
## Contributing
|
132
|
+
|
133
|
+
1. Fork it ( http://github.com/<my-github-username>/quickbooks-ruby-base/fork )
|
134
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
135
|
+
3. Create a spec to test your feature.
|
136
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
137
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
138
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
class Base
|
3
|
+
module Configuration
|
4
|
+
def configure
|
5
|
+
yield self
|
6
|
+
end
|
7
|
+
|
8
|
+
def oauth_consumer=(var)
|
9
|
+
@oauth_consumer = var
|
10
|
+
end
|
11
|
+
|
12
|
+
def oauth_consumer
|
13
|
+
@oauth_consumer ||= $qb_oauth_consumer
|
14
|
+
end
|
15
|
+
|
16
|
+
%w(token secret company_id).each do |type|
|
17
|
+
class_eval <<-eos
|
18
|
+
def persistent_#{type}=(location)
|
19
|
+
@persistent_#{type} = location
|
20
|
+
end
|
21
|
+
|
22
|
+
def persistent_#{type}
|
23
|
+
@persistent_#{type} ||= 'settings.qb_#{type}'
|
24
|
+
end
|
25
|
+
eos
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'quickbooks-ruby'
|
2
|
+
require_relative 'base/configuration'
|
3
|
+
|
4
|
+
module Quickbooks
|
5
|
+
class Base
|
6
|
+
attr_reader :service
|
7
|
+
extend Configuration
|
8
|
+
|
9
|
+
def initialize(account, type = nil)
|
10
|
+
@account = account
|
11
|
+
create_service_for(type) if type
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_quickbooks_ruby_namespace(which, type = 'Model')
|
15
|
+
which = which.to_s.camelcase if which.is_a?(Symbol)
|
16
|
+
"Quickbooks::#{type}::#{which}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def quickbooks_ruby_model(which, *args)
|
20
|
+
generate_quickbooks_ruby_namespace(which, 'Model').constantize.new(*args)
|
21
|
+
end
|
22
|
+
alias_method :qr_model, :quickbooks_ruby_model
|
23
|
+
|
24
|
+
def quickbooks_ruby_service(which)
|
25
|
+
generate_quickbooks_ruby_namespace(which, 'Service').constantize.new
|
26
|
+
end
|
27
|
+
alias_method :qr_service, :quickbooks_ruby_service
|
28
|
+
|
29
|
+
def oauth_client
|
30
|
+
@oauth_client ||= OAuth::AccessToken.new(Quickbooks::Base.oauth_consumer, token, secret)
|
31
|
+
end
|
32
|
+
|
33
|
+
def show(options = {})
|
34
|
+
options = { per_page: 20, page: 1 }.merge(options)
|
35
|
+
method = describing_method
|
36
|
+
@service.query(nil, options).entries.collect { |e| "QBID: #{e.id} DESC: #{e.send(method) if method}" }
|
37
|
+
end
|
38
|
+
|
39
|
+
def describing_method
|
40
|
+
case @service.class.name
|
41
|
+
when /(Item|TaxCode|PaymentMethod)/
|
42
|
+
'name'
|
43
|
+
when /(Invoice|Payment)/
|
44
|
+
'doc_number'
|
45
|
+
when /(Vendor|Customer|Employee)/
|
46
|
+
'display_name'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def token
|
51
|
+
retrieve(:token)
|
52
|
+
end
|
53
|
+
|
54
|
+
def secret
|
55
|
+
retrieve(:secret)
|
56
|
+
end
|
57
|
+
|
58
|
+
def company_id
|
59
|
+
retrieve(:company_id)
|
60
|
+
end
|
61
|
+
|
62
|
+
def retrieve(type)
|
63
|
+
meth = "persistent_#{type}"
|
64
|
+
arr = Quickbooks::Base.send(meth).split('.')
|
65
|
+
send_chain(arr)
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_service_for(type)
|
69
|
+
@service = quickbooks_ruby_service(type)
|
70
|
+
@service.access_token = oauth_client
|
71
|
+
@service.company_id = company_id
|
72
|
+
@service
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def send_chain(arr)
|
78
|
+
arr.inject(@account) {|o, a| o.send(a) }
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'quickbooks/base'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'quickbooks-ruby-base'
|
7
|
+
spec.version = '1.0.0'
|
8
|
+
spec.authors = ["Christian"]
|
9
|
+
spec.email = ["christian@minimul.com"]
|
10
|
+
spec.summary = %q{Base class to provide common methods for the quickbooks-ruby gem}
|
11
|
+
spec.description = %q{}
|
12
|
+
spec.homepage = "https://github.com/minimul/quickbooks-ruby-base"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.test_files = spec.files.grep %r{^spec/}
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency 'quickbooks-ruby'
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rspec"
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-04-04T04:52:19.963-07:00">
|
3
|
+
<QueryResponse startPosition="1" maxResults="20" totalCount="20">
|
4
|
+
<Invoice domain="QBO" sparse="false">
|
5
|
+
<Id>29</Id>
|
6
|
+
<SyncToken>0</SyncToken>
|
7
|
+
<MetaData>
|
8
|
+
<CreateTime>2014-04-01T08:19:48-07:00</CreateTime>
|
9
|
+
<LastUpdatedTime>2014-04-01T08:19:48-07:00</LastUpdatedTime>
|
10
|
+
</MetaData>
|
11
|
+
<DocNumber>1234</DocNumber>
|
12
|
+
<TxnDate>2014-04-01</TxnDate>
|
13
|
+
<Line>
|
14
|
+
<Id>1</Id>
|
15
|
+
<LineNum>1</LineNum>
|
16
|
+
<Description>Some big thingy</Description>
|
17
|
+
<Amount>64.99</Amount>
|
18
|
+
<DetailType>SalesItemLineDetail</DetailType>
|
19
|
+
<SalesItemLineDetail>
|
20
|
+
<ItemRef name="Services">1</ItemRef>
|
21
|
+
<UnitPrice>64.99</UnitPrice>
|
22
|
+
<Qty>1</Qty>
|
23
|
+
<TaxCodeRef>TAX</TaxCodeRef>
|
24
|
+
</SalesItemLineDetail>
|
25
|
+
</Line>
|
26
|
+
<Line>
|
27
|
+
<Id>2</Id>
|
28
|
+
<LineNum>2</LineNum>
|
29
|
+
<Description>Some big thingy</Description>
|
30
|
+
<Amount>64.99</Amount>
|
31
|
+
<DetailType>SalesItemLineDetail</DetailType>
|
32
|
+
<SalesItemLineDetail>
|
33
|
+
<ItemRef name="Services">1</ItemRef>
|
34
|
+
<UnitPrice>64.99</UnitPrice>
|
35
|
+
<Qty>1</Qty>
|
36
|
+
<TaxCodeRef>TAX</TaxCodeRef>
|
37
|
+
</SalesItemLineDetail>
|
38
|
+
</Line>
|
39
|
+
<Line>
|
40
|
+
<Amount>129.98</Amount>
|
41
|
+
<DetailType>SubTotalLineDetail</DetailType>
|
42
|
+
<SubTotalLineDetail/>
|
43
|
+
</Line>
|
44
|
+
<TxnTaxDetail>
|
45
|
+
<TxnTaxCodeRef>2</TxnTaxCodeRef>
|
46
|
+
<TotalTax>0</TotalTax>
|
47
|
+
<TaxLine>
|
48
|
+
<Amount>0</Amount>
|
49
|
+
<DetailType>TaxLineDetail</DetailType>
|
50
|
+
<TaxLineDetail>
|
51
|
+
<TaxRateRef>1</TaxRateRef>
|
52
|
+
<PercentBased>true</PercentBased>
|
53
|
+
<TaxPercent>10</TaxPercent>
|
54
|
+
<NetAmountTaxable>129.98</NetAmountTaxable>
|
55
|
+
</TaxLineDetail>
|
56
|
+
</TaxLine>
|
57
|
+
</TxnTaxDetail>
|
58
|
+
<CustomerRef name="(empty)">6</CustomerRef>
|
59
|
+
<BillAddr>
|
60
|
+
<Id>3</Id>
|
61
|
+
<Line1>123 darkwing road</Line1>
|
62
|
+
<Line2>RT 101</Line2>
|
63
|
+
<City>Rockingham</City>
|
64
|
+
<CountrySubDivisionCode>NH</CountrySubDivisionCode>
|
65
|
+
<PostalCode>10002</PostalCode>
|
66
|
+
<Lat>40.7135097</Lat>
|
67
|
+
<Long>-73.9859414</Long>
|
68
|
+
</BillAddr>
|
69
|
+
<DueDate>2014-04-01</DueDate>
|
70
|
+
<TotalAmt>129.98</TotalAmt>
|
71
|
+
<ApplyTaxAfterDiscount>false</ApplyTaxAfterDiscount>
|
72
|
+
<PrintStatus>NeedToPrint</PrintStatus>
|
73
|
+
<EmailStatus>NotSet</EmailStatus>
|
74
|
+
<BillEmail>
|
75
|
+
<Address>john@doe.com</Address>
|
76
|
+
</BillEmail>
|
77
|
+
<Balance>129.98</Balance>
|
78
|
+
<Deposit>0</Deposit>
|
79
|
+
<AllowIPNPayment>false</AllowIPNPayment>
|
80
|
+
<AllowOnlinePayment>false</AllowOnlinePayment>
|
81
|
+
<AllowOnlineCreditCardPayment>false</AllowOnlineCreditCardPayment>
|
82
|
+
<AllowOnlineACHPayment>false</AllowOnlineACHPayment>
|
83
|
+
</Invoice>
|
84
|
+
<Invoice domain="QBO" sparse="false">
|
85
|
+
<Id>28</Id>
|
86
|
+
<SyncToken>0</SyncToken>
|
87
|
+
<MetaData>
|
88
|
+
<CreateTime>2014-04-01T07:04:10-07:00</CreateTime>
|
89
|
+
<LastUpdatedTime>2014-04-01T07:04:10-07:00</LastUpdatedTime>
|
90
|
+
</MetaData>
|
91
|
+
<DocNumber>1234</DocNumber>
|
92
|
+
<TxnDate>2014-04-01</TxnDate>
|
93
|
+
<Line>
|
94
|
+
<Id>1</Id>
|
95
|
+
<LineNum>1</LineNum>
|
96
|
+
<Description>Some big thingy</Description>
|
97
|
+
<Amount>64.99</Amount>
|
98
|
+
<DetailType>SalesItemLineDetail</DetailType>
|
99
|
+
<SalesItemLineDetail>
|
100
|
+
<ItemRef name="Services">1</ItemRef>
|
101
|
+
<UnitPrice>64.99</UnitPrice>
|
102
|
+
<Qty>1</Qty>
|
103
|
+
<TaxCodeRef>TAX</TaxCodeRef>
|
104
|
+
</SalesItemLineDetail>
|
105
|
+
</Line>
|
106
|
+
<Line>
|
107
|
+
<Amount>64.99</Amount>
|
108
|
+
<DetailType>SubTotalLineDetail</DetailType>
|
109
|
+
<SubTotalLineDetail/>
|
110
|
+
</Line>
|
111
|
+
<TxnTaxDetail>
|
112
|
+
<TxnTaxCodeRef>2</TxnTaxCodeRef>
|
113
|
+
<TotalTax>0</TotalTax>
|
114
|
+
<TaxLine>
|
115
|
+
<Amount>0</Amount>
|
116
|
+
<DetailType>TaxLineDetail</DetailType>
|
117
|
+
<TaxLineDetail>
|
118
|
+
<TaxRateRef>1</TaxRateRef>
|
119
|
+
<PercentBased>true</PercentBased>
|
120
|
+
<TaxPercent>10</TaxPercent>
|
121
|
+
<NetAmountTaxable>64.99</NetAmountTaxable>
|
122
|
+
</TaxLineDetail>
|
123
|
+
</TaxLine>
|
124
|
+
</TxnTaxDetail>
|
125
|
+
<CustomerRef name="(empty)">6</CustomerRef>
|
126
|
+
<BillAddr>
|
127
|
+
<Id>3</Id>
|
128
|
+
<Line1>123 darkwing road</Line1>
|
129
|
+
<Line2>RT 101</Line2>
|
130
|
+
<City>Rockingham</City>
|
131
|
+
<CountrySubDivisionCode>NH</CountrySubDivisionCode>
|
132
|
+
<PostalCode>10002</PostalCode>
|
133
|
+
<Lat>40.7135097</Lat>
|
134
|
+
<Long>-73.9859414</Long>
|
135
|
+
</BillAddr>
|
136
|
+
<DueDate>2014-04-01</DueDate>
|
137
|
+
<TotalAmt>64.99</TotalAmt>
|
138
|
+
<ApplyTaxAfterDiscount>false</ApplyTaxAfterDiscount>
|
139
|
+
<PrintStatus>NeedToPrint</PrintStatus>
|
140
|
+
<EmailStatus>NotSet</EmailStatus>
|
141
|
+
<BillEmail>
|
142
|
+
<Address>john@doe.com</Address>
|
143
|
+
</BillEmail>
|
144
|
+
<Balance>64.99</Balance>
|
145
|
+
<Deposit>0</Deposit>
|
146
|
+
<AllowIPNPayment>false</AllowIPNPayment>
|
147
|
+
<AllowOnlinePayment>false</AllowOnlinePayment>
|
148
|
+
<AllowOnlineCreditCardPayment>false</AllowOnlineCreditCardPayment>
|
149
|
+
<AllowOnlineACHPayment>false</AllowOnlineACHPayment>
|
150
|
+
</Invoice>
|
151
|
+
</QueryResponse>
|
152
|
+
</IntuitResponse>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-04-04T04:50:02.406-07:00">
|
2
|
+
<QueryResponse startPosition="1" maxResults="4" totalCount="4">
|
3
|
+
<TaxCode>
|
4
|
+
<Id>TAX</Id>
|
5
|
+
<MetaData>
|
6
|
+
<CreateTime>2013-08-26T12:24:57-07:00</CreateTime>
|
7
|
+
<LastUpdatedTime>2013-08-26T12:24:57-07:00</LastUpdatedTime>
|
8
|
+
</MetaData>
|
9
|
+
<Name>TAX</Name>
|
10
|
+
<Description>TAX</Description>
|
11
|
+
<Taxable>true</Taxable>
|
12
|
+
<TaxGroup>false</TaxGroup>
|
13
|
+
</TaxCode>
|
14
|
+
<TaxCode>
|
15
|
+
<Id>NON</Id>
|
16
|
+
<MetaData>
|
17
|
+
<CreateTime>2013-08-26T12:24:57-07:00</CreateTime>
|
18
|
+
<LastUpdatedTime>2013-08-26T12:24:57-07:00</LastUpdatedTime>
|
19
|
+
</MetaData>
|
20
|
+
<Name>NON</Name>
|
21
|
+
<Description>NON</Description>
|
22
|
+
<Taxable>false</Taxable>
|
23
|
+
<TaxGroup>false</TaxGroup>
|
24
|
+
</TaxCode>
|
25
|
+
<TaxCode>
|
26
|
+
<Id>CustomSalesTax</Id>
|
27
|
+
<MetaData>
|
28
|
+
<CreateTime>2013-08-26T12:24:57-07:00</CreateTime>
|
29
|
+
<LastUpdatedTime>2013-08-26T12:24:57-07:00</LastUpdatedTime>
|
30
|
+
</MetaData>
|
31
|
+
<Name>CustomSalesTax</Name>
|
32
|
+
<Description>CustomSalesTax</Description>
|
33
|
+
<Taxable>true</Taxable>
|
34
|
+
<TaxGroup>true</TaxGroup>
|
35
|
+
</TaxCode>
|
36
|
+
<TaxCode domain="QBO" sparse="false">
|
37
|
+
<Id>2</Id>
|
38
|
+
<SyncToken>0</SyncToken>
|
39
|
+
<MetaData>
|
40
|
+
<CreateTime>2014-03-28T13:52:48-07:00</CreateTime>
|
41
|
+
<LastUpdatedTime>2014-03-28T13:52:48-07:00</LastUpdatedTime>
|
42
|
+
</MetaData>
|
43
|
+
<Name>New York City</Name>
|
44
|
+
<Description>New York City</Description>
|
45
|
+
<Active>true</Active>
|
46
|
+
<Taxable>true</Taxable>
|
47
|
+
<TaxGroup>true</TaxGroup>
|
48
|
+
<SalesTaxRateList>
|
49
|
+
<TaxRateDetail>
|
50
|
+
<TaxRateRef name="New York City">1</TaxRateRef>
|
51
|
+
<TaxTypeApplicable>TaxOnAmount</TaxTypeApplicable>
|
52
|
+
<TaxOrder>0</TaxOrder>
|
53
|
+
</TaxRateDetail>
|
54
|
+
</SalesTaxRateList>
|
55
|
+
<PurchaseTaxRateList/>
|
56
|
+
</TaxCode>
|
57
|
+
</QueryResponse>
|
58
|
+
</IntuitResponse>
|
@@ -0,0 +1,95 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-04-04T06:31:21.480-07:00">
|
3
|
+
<QueryResponse startPosition="1" maxResults="6">
|
4
|
+
<Vendor domain="QBO" sparse="false">
|
5
|
+
<Id>11</Id>
|
6
|
+
<SyncToken>1</SyncToken>
|
7
|
+
<MetaData>
|
8
|
+
<CreateTime>2014-02-04T14:27:38-08:00</CreateTime>
|
9
|
+
<LastUpdatedTime>2014-02-04T14:39:34-08:00</LastUpdatedTime>
|
10
|
+
</MetaData>
|
11
|
+
<GivenName>Bill</GivenName>
|
12
|
+
<FamilyName>Sales</FamilyName>
|
13
|
+
<CompanyName>Catherines Cupcakes</CompanyName>
|
14
|
+
<DisplayName>Catherines Cupcakes</DisplayName>
|
15
|
+
<PrintOnCheckName>Catherines Cupcakes</PrintOnCheckName>
|
16
|
+
<Active>true</Active>
|
17
|
+
<PrimaryPhone>
|
18
|
+
<FreeFormNumber>603-344-5555</FreeFormNumber>
|
19
|
+
</PrimaryPhone>
|
20
|
+
<PrimaryEmailAddr>
|
21
|
+
<Address>cathy@donkey.io</Address>
|
22
|
+
</PrimaryEmailAddr>
|
23
|
+
<BillAddr>
|
24
|
+
<Id>7</Id>
|
25
|
+
<Line1>44 Billings Circle</Line1>
|
26
|
+
<City>Keene</City>
|
27
|
+
<CountrySubDivisionCode>NH</CountrySubDivisionCode>
|
28
|
+
<PostalCode>03455</PostalCode>
|
29
|
+
<Lat>42.9453196</Lat>
|
30
|
+
<Long>-72.31237449999999</Long>
|
31
|
+
</BillAddr>
|
32
|
+
<Balance>0</Balance>
|
33
|
+
<Vendor1099>false</Vendor1099>
|
34
|
+
</Vendor>
|
35
|
+
<Vendor domain="QBO" sparse="false">
|
36
|
+
<Id>3</Id>
|
37
|
+
<SyncToken>2</SyncToken>
|
38
|
+
<MetaData>
|
39
|
+
<CreateTime>2013-12-16T07:07:30-08:00</CreateTime>
|
40
|
+
<LastUpdatedTime>2013-12-16T07:15:32-08:00</LastUpdatedTime>
|
41
|
+
</MetaData>
|
42
|
+
<GivenName>Christian</GivenName>
|
43
|
+
<DisplayName>Christian</DisplayName>
|
44
|
+
<PrintOnCheckName>Christian</PrintOnCheckName>
|
45
|
+
<Active>true</Active>
|
46
|
+
<PrimaryEmailAddr>
|
47
|
+
<Address>christian@minimul.io</Address>
|
48
|
+
</PrimaryEmailAddr>
|
49
|
+
<Balance>0</Balance>
|
50
|
+
<Vendor1099>false</Vendor1099>
|
51
|
+
</Vendor>
|
52
|
+
<Vendor domain="QBO" sparse="false">
|
53
|
+
<Id>1</Id>
|
54
|
+
<SyncToken>0</SyncToken>
|
55
|
+
<MetaData>
|
56
|
+
<CreateTime>2013-10-29T02:59:05-07:00</CreateTime>
|
57
|
+
<LastUpdatedTime>2013-10-29T02:59:05-07:00</LastUpdatedTime>
|
58
|
+
</MetaData>
|
59
|
+
<DisplayName>John Doe</DisplayName>
|
60
|
+
<PrintOnCheckName>John Doe</PrintOnCheckName>
|
61
|
+
<Active>true</Active>
|
62
|
+
<Balance>0</Balance>
|
63
|
+
<Vendor1099>false</Vendor1099>
|
64
|
+
</Vendor>
|
65
|
+
<Vendor domain="QBO" sparse="false">
|
66
|
+
<Id>2</Id>
|
67
|
+
<SyncToken>1</SyncToken>
|
68
|
+
<MetaData>
|
69
|
+
<CreateTime>2013-11-02T05:17:06-07:00</CreateTime>
|
70
|
+
<LastUpdatedTime>2013-11-02T07:16:45-07:00</LastUpdatedTime>
|
71
|
+
</MetaData>
|
72
|
+
<DisplayName>Minimul</DisplayName>
|
73
|
+
<PrintOnCheckName>Minimul</PrintOnCheckName>
|
74
|
+
<Active>true</Active>
|
75
|
+
<PrimaryEmailAddr>
|
76
|
+
<Address>christian@minimul.io</Address>
|
77
|
+
</PrimaryEmailAddr>
|
78
|
+
<Balance>0</Balance>
|
79
|
+
<Vendor1099>false</Vendor1099>
|
80
|
+
</Vendor>
|
81
|
+
<Vendor domain="QBO" sparse="false">
|
82
|
+
<Id>13</Id>
|
83
|
+
<SyncToken>0</SyncToken>
|
84
|
+
<MetaData>
|
85
|
+
<CreateTime>2014-04-01T06:17:50-07:00</CreateTime>
|
86
|
+
<LastUpdatedTime>2014-04-01T06:17:50-07:00</LastUpdatedTime>
|
87
|
+
</MetaData>
|
88
|
+
<DisplayName>Musty Musketts</DisplayName>
|
89
|
+
<PrintOnCheckName>Musty Musketts</PrintOnCheckName>
|
90
|
+
<Active>true</Active>
|
91
|
+
<Balance>0</Balance>
|
92
|
+
<Vendor1099>false</Vendor1099>
|
93
|
+
</Vendor>
|
94
|
+
</QueryResponse>
|
95
|
+
</IntuitResponse>
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Quickbooks::Base do
|
4
|
+
let(:account) { double }
|
5
|
+
let(:qr_base) { Quickbooks::Base.new(account) }
|
6
|
+
|
7
|
+
describe ".quickbooks_ruby_namespace" do
|
8
|
+
it "should generate quickbooks ruby model namespace given a symbol" do
|
9
|
+
expect(qr_base.generate_quickbooks_ruby_namespace(:access_token)).to eq "Quickbooks::Model::AccessToken"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should generate quickbooks ruby service namespace given a string" do
|
13
|
+
expect(qr_base.generate_quickbooks_ruby_namespace('AccessToken', 'Service')).to eq "Quickbooks::Service::AccessToken"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".qr_model" do
|
18
|
+
|
19
|
+
it "should create a new instance of a quickbooks-ruby model" do
|
20
|
+
expect(qr_base.qr_model(:invoice).class.name).to eq 'Quickbooks::Model::Invoice'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should create a new instance of a quickbooks-ruby model that take more than 1 argument" do
|
24
|
+
result = qr_base.qr_model(:email_address, 'test@email.com')
|
25
|
+
expect(result.address).to eq 'test@email.com'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".show" do
|
30
|
+
let(:account) { account = double(settings: double( qb_token: 'tttttttttt', qb_secret: 'ssssssss', qb_company_id: '1234567')) }
|
31
|
+
|
32
|
+
it "should display using the name as the given name" do
|
33
|
+
xml = File.read(File.join('spec', 'fixtures', 'vendors.xml'))
|
34
|
+
response = Struct.new(:plain_body, :code).new(xml, 200)
|
35
|
+
allow_any_instance_of(OAuth::AccessToken).to receive(:get).and_return(response)
|
36
|
+
qr = Quickbooks::Base.new(account, :vendor)
|
37
|
+
expect(qr.show.first).to match /Catherines Cupcakes/
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should display using the name and not doc_number" do
|
41
|
+
xml = File.read(File.join('spec', 'fixtures', 'tax_codes.xml'))
|
42
|
+
response = Struct.new(:plain_body, :code).new(xml, 200)
|
43
|
+
allow_any_instance_of(OAuth::AccessToken).to receive(:get).and_return(response)
|
44
|
+
qr = Quickbooks::Base.new(account, :tax_code)
|
45
|
+
expect(qr.show.last).to match /New York City/
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should display using the doc_number and not name" do
|
49
|
+
xml = File.read(File.join('spec', 'fixtures', 'invoices.xml'))
|
50
|
+
response = Struct.new(:plain_body, :code).new(xml, 200)
|
51
|
+
allow_any_instance_of(OAuth::AccessToken).to receive(:get).and_return(response)
|
52
|
+
qr = Quickbooks::Base.new(account, :invoice)
|
53
|
+
expect(qr.show.last).to match /1234/
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe ".retrieve" do
|
58
|
+
after do
|
59
|
+
Quickbooks::Base.configure { |c| c.persistent_token = nil; c.persistent_secret = nil; c.persistent_company_id = nil }
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should set the persistence token location" do
|
63
|
+
Quickbooks::Base.configure do |c|
|
64
|
+
c.persistent_token = 'quickbooks_token'
|
65
|
+
c.persistent_company_id = 'quickbooks_company_id'
|
66
|
+
end
|
67
|
+
expect(Quickbooks::Base.persistent_token).to eq 'quickbooks_token'
|
68
|
+
expect(Quickbooks::Base.persistent_company_id).to eq 'quickbooks_company_id'
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should retrieve token configuration that is 2 levels deep, which is the default" do
|
72
|
+
token = 'xxxxxxxxxxxxxx'
|
73
|
+
account = double(settings: double( qb_token: token ))
|
74
|
+
qr_base = Quickbooks::Base.new(account)
|
75
|
+
expect(qr_base.retrieve(:token)).to eq token
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should retrieve token configuration that is 1 level deep" do
|
79
|
+
token = 'xxxxxxxxxxxxxx'
|
80
|
+
Quickbooks::Base.configure do |c|
|
81
|
+
c.persistent_token = 'quickbooks_token'
|
82
|
+
end
|
83
|
+
account = double( quickbooks_token: token )
|
84
|
+
qr_base = Quickbooks::Base.new(account)
|
85
|
+
expect(qr_base.retrieve(:token)).to eq token
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe ".create_service_for" do
|
90
|
+
it "creates a access_token service" do
|
91
|
+
account = double(settings: double( qb_token: 'tttttttttt', qb_secret: 'ssssssss', qb_company_id: '1234567'))
|
92
|
+
qb = Quickbooks::Base.new(account)
|
93
|
+
service = qb.create_service_for :access_token
|
94
|
+
expect(service.class.name).to match /Service::AccessToken/
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quickbooks-ruby-base
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: quickbooks-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- christian@minimul.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/quickbooks-ruby-base.rb
|
82
|
+
- lib/quickbooks/base.rb
|
83
|
+
- lib/quickbooks/base/configuration.rb
|
84
|
+
- quickbooks-ruby-base.gemspec
|
85
|
+
- spec/fixtures/invoices.xml
|
86
|
+
- spec/fixtures/tax_codes.xml
|
87
|
+
- spec/fixtures/vendors.xml
|
88
|
+
- spec/quickbooks_ruby_base_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: https://github.com/minimul/quickbooks-ruby-base
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.2.2
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Base class to provide common methods for the quickbooks-ruby gem
|
114
|
+
test_files:
|
115
|
+
- spec/fixtures/invoices.xml
|
116
|
+
- spec/fixtures/tax_codes.xml
|
117
|
+
- spec/fixtures/vendors.xml
|
118
|
+
- spec/quickbooks_ruby_base_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
has_rdoc:
|