quickbooks-ruby 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quickbooks/model/base_model_json.rb +16 -0
- data/lib/quickbooks/model/base_reference.rb +2 -1
- data/lib/quickbooks/model/change_model.rb +10 -0
- data/lib/quickbooks/model/credit_memo_change.rb +8 -0
- data/lib/quickbooks/model/customer_change.rb +2 -6
- data/lib/quickbooks/model/definition.rb +38 -34
- data/lib/quickbooks/model/entity.rb +1 -1
- data/lib/quickbooks/model/invoice_change.rb +1 -5
- data/lib/quickbooks/model/item_change.rb +2 -6
- data/lib/quickbooks/model/payment_change.rb +8 -0
- data/lib/quickbooks/model/reports.rb +2 -2
- data/lib/quickbooks/model/sales_receipt.rb +1 -1
- data/lib/quickbooks/model/tax_agency.rb +18 -0
- data/lib/quickbooks/model/tax_rate_detail_line.rb +23 -0
- data/lib/quickbooks/model/tax_service.rb +52 -0
- data/lib/quickbooks/model/vendor_change.rb +2 -6
- data/lib/quickbooks/service/base_service.rb +34 -9
- data/lib/quickbooks/service/base_service_json.rb +39 -0
- data/lib/quickbooks/service/change_service.rb +28 -0
- data/lib/quickbooks/service/credit_memo_change.rb +16 -0
- data/lib/quickbooks/service/customer_change.rb +6 -13
- data/lib/quickbooks/service/invoice_change.rb +5 -12
- data/lib/quickbooks/service/item_change.rb +6 -13
- data/lib/quickbooks/service/payment_change.rb +16 -0
- data/lib/quickbooks/service/reports.rb +18 -8
- data/lib/quickbooks/service/service_crud.rb +2 -1
- data/lib/quickbooks/service/service_crud_json.rb +31 -0
- data/lib/quickbooks/service/tax_agency.rb +12 -0
- data/lib/quickbooks/service/tax_service.rb +11 -0
- data/lib/quickbooks/service/vendor_change.rb +6 -13
- data/lib/quickbooks/version.rb +1 -1
- data/lib/quickbooks-ruby.rb +15 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dba56b54b2268020885411d264f5c4b6314d553
|
4
|
+
data.tar.gz: e80fd5e293a8815acba2a21ad382943207cb95c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 388f2bb468bc4ee848b5b82c8e98648579612221bddcb5342f391b60d576b8288ccec064b1dfa97e1fc6212b404da77a25dde46cfdd49922a1481e371dcc626b
|
7
|
+
data.tar.gz: 1c8b6eaa47a883cbd2380ddfc8e71fd0b74743049cfd872f026440d906b579c9d089903bbbbc88a8337638a53a687a462a9b192f580bcc17863d4e966a3a0ea8
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class BaseModelJSON < BaseModel
|
4
|
+
|
5
|
+
def to_json
|
6
|
+
params = {}
|
7
|
+
attributes.each_pair do |k, v|
|
8
|
+
next if v.blank?
|
9
|
+
params[k.camelize] = v.is_a?(Array) ? v.inject([]){|mem, item| mem << item.to_json; mem} : v
|
10
|
+
end
|
11
|
+
params.to_json
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -6,8 +6,9 @@ module Quickbooks
|
|
6
6
|
xml_accessor :value, :from => :content
|
7
7
|
xml_accessor :type, :from => '@type' # Attribute with name 'type'
|
8
8
|
|
9
|
-
def initialize(value =
|
9
|
+
def initialize(value=nil, attributes={})
|
10
10
|
self.value = value
|
11
|
+
attributes.each {|key, value| public_send("#{key}=", value) }
|
11
12
|
end
|
12
13
|
|
13
14
|
def to_i
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
# Refer to: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/change_data_capture
|
4
|
+
class ChangeModel < BaseModel
|
5
|
+
xml_accessor :id, :from => 'Id'
|
6
|
+
xml_accessor :status, :from => '@status'
|
7
|
+
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -1,12 +1,8 @@
|
|
1
1
|
module Quickbooks
|
2
2
|
module Model
|
3
3
|
# Refer to: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/change_data_capture
|
4
|
-
class CustomerChange <
|
4
|
+
class CustomerChange < ChangeModel
|
5
5
|
XML_NODE = "Customer"
|
6
|
-
|
7
|
-
xml_accessor :id, :from => 'Id'
|
8
|
-
xml_accessor :status, :from => '@status'
|
9
|
-
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
10
6
|
end
|
11
7
|
end
|
12
|
-
end
|
8
|
+
end
|
@@ -1,42 +1,46 @@
|
|
1
|
-
module
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
module Definition
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
9
|
+
module ClassMethods
|
10
|
+
# https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services
|
11
|
+
TRANSACTION_ENTITIES = %w{
|
12
|
+
Bill
|
13
|
+
BillPayment
|
14
|
+
CreditMemo
|
15
|
+
Estimate
|
16
|
+
Invoice
|
17
|
+
JournalEntry
|
18
|
+
Payment
|
19
|
+
Purchase
|
20
|
+
PurchaseOrder
|
21
|
+
RefundReceipt
|
22
|
+
SalesReceipt
|
23
|
+
TimeActivity
|
24
|
+
VendorCredit
|
25
|
+
}
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
def is_transaction_entity?
|
28
|
+
TRANSACTION_ENTITIES.include?(self.name.demodulize)
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def is_name_list_entity?
|
32
|
+
!self.is_transaction_entity?
|
33
|
+
end
|
34
|
+
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
def is_transaction_entity?
|
37
|
+
self.class.is_transaction_entity?
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
def is_name_list_entity?
|
41
|
+
self.class.is_name_list_entity?
|
42
|
+
end
|
41
43
|
|
44
|
+
end
|
45
|
+
end
|
42
46
|
end
|
@@ -1,12 +1,8 @@
|
|
1
1
|
module Quickbooks
|
2
2
|
module Model
|
3
3
|
# Refer to: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/change_data_capture
|
4
|
-
class InvoiceChange <
|
4
|
+
class InvoiceChange < ChangeModel
|
5
5
|
XML_NODE = "Invoice"
|
6
|
-
|
7
|
-
xml_accessor :id, :from => 'Id'
|
8
|
-
xml_accessor :status, :from => '@status'
|
9
|
-
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
10
6
|
end
|
11
7
|
end
|
12
8
|
end
|
@@ -1,12 +1,8 @@
|
|
1
1
|
module Quickbooks
|
2
2
|
module Model
|
3
3
|
# Refer to: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/change_data_capture
|
4
|
-
class ItemChange <
|
4
|
+
class ItemChange < ChangeModel
|
5
5
|
XML_NODE = "Item"
|
6
|
-
|
7
|
-
xml_accessor :id, :from => 'Id'
|
8
|
-
xml_accessor :status, :from => '@status'
|
9
|
-
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
10
6
|
end
|
11
7
|
end
|
12
|
-
end
|
8
|
+
end
|
@@ -5,7 +5,7 @@ module Quickbooks
|
|
5
5
|
XML_NODE = "Reports"
|
6
6
|
REST_RESOURCE = 'reports'
|
7
7
|
|
8
|
-
|
8
|
+
REPORT_TYPES = ['BalanceSheet', 'ProfitandLoss', 'ProfitAndLossDetail', 'TrialBalance', 'CashFlow', 'InventoryValuationSummary', 'CustomerSales', 'ItemSales', 'DepartmentSales', 'ClassSales', 'CustomerIncome', 'CustomerBalance', 'CustomerBalanceDetail', 'AgedReceivables', 'AgedReceivableDetail', 'VendorBalance', 'VendorBalanceDetail', 'AgedPayables', 'AgedPayableDetail', 'VendorExpenses', 'GeneralLedgerDetail']
|
9
9
|
|
10
10
|
xml_name XML_NODE
|
11
11
|
|
@@ -14,4 +14,4 @@ module Quickbooks
|
|
14
14
|
|
15
15
|
end
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
@@ -22,7 +22,7 @@ module Quickbooks
|
|
22
22
|
xml_accessor :bill_address, :from => 'BillAddr', :as => PhysicalAddress
|
23
23
|
xml_accessor :ship_address, :from => 'ShipAddr', :as => PhysicalAddress
|
24
24
|
xml_accessor :po_number, :from => 'PONumber'
|
25
|
-
xml_accessor :ship_method_ref, :from => 'ShipMethodRef'
|
25
|
+
xml_accessor :ship_method_ref, :from => 'ShipMethodRef', :as => BaseReference
|
26
26
|
xml_accessor :ship_date, :from => 'ShipDate', :as => Time
|
27
27
|
xml_accessor :tracking_num, :from => 'TrackingNum'
|
28
28
|
xml_accessor :payment_method_ref, :from => 'PaymentMethodRef', :as => BaseReference
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class TaxAgency < BaseModel
|
4
|
+
XML_COLLECTION_NODE = "TaxAgency"
|
5
|
+
XML_NODE = "TaxAgency"
|
6
|
+
REST_RESOURCE = "taxagency"
|
7
|
+
|
8
|
+
xml_accessor :id, :from => "Id"
|
9
|
+
xml_accessor :sync_token, :from => "SyncToken", :as => Integer
|
10
|
+
xml_accessor :meta_data, :from => "MetaData", :as => MetaData
|
11
|
+
xml_accessor :tax_tracked_on_purchases?, :from => "TaxTrackedOnPurchases"
|
12
|
+
xml_accessor :tax_tracked_on_sales?, :from => "TaxTrackedOnSales"
|
13
|
+
xml_accessor :display_name, :from => "DisplayName"
|
14
|
+
|
15
|
+
validates_presence_of :display_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class TaxRateDetailLine < BaseModel
|
4
|
+
|
5
|
+
xml_accessor :tax_rate_id, :from => "TaxRateId"
|
6
|
+
xml_accessor :tax_rate_name, :from => "TaxRateName"
|
7
|
+
xml_accessor :rate_value, :from => "RateValue"
|
8
|
+
xml_accessor :tax_agency_id, :from => "TaxAgencyId"
|
9
|
+
xml_accessor :tax_applicable_on, :from => 'TaxApplicableOn', :as => :text
|
10
|
+
|
11
|
+
validates :tax_rate_name, presence: true, length: { maximum: 100 }, if: Proc.new {|line| line.tax_rate_id.blank?}
|
12
|
+
validates :tax_agency_id, presence: true, numericality: {greater_than: 0}, if: Proc.new {|line| line.tax_rate_id.blank?}
|
13
|
+
validates :rate_value, presence: true, numericality: {less_than_or_equal_to: 100}, if: Proc.new {|line| line.tax_rate_id.blank?}
|
14
|
+
validates :tax_rate_id, numericality: true, if: Proc.new {|line| line.tax_rate_name.blank? && tax_agency_id.blank? && rate_value.blank? }
|
15
|
+
|
16
|
+
validates :tax_applicable_on, inclusion: {in: %w(Sales Purchase)}
|
17
|
+
|
18
|
+
def to_json
|
19
|
+
attributes.inject({}){|mem, item| mem[item.first.camelize] = item.last if item.last.present?; mem}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class TaxService < BaseModelJSON
|
4
|
+
REST_RESOURCE = "taxservice/taxcode"
|
5
|
+
|
6
|
+
xml_accessor :tax_code_id, :from => "TaxCodeId"
|
7
|
+
xml_accessor :tax_code, :from => "TaxCode"
|
8
|
+
xml_accessor :tax_rate_details, :from => 'TaxRateDetails', :as => [TaxRateDetailLine]
|
9
|
+
|
10
|
+
validates :tax_code, presence: true, length: { maximum: 100 }
|
11
|
+
|
12
|
+
validate :check_details_item
|
13
|
+
|
14
|
+
def initialize(options = {})
|
15
|
+
self.tax_rate_details = options['tax_rate_details'] || []
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.from_json(response)
|
20
|
+
result = JSON.parse(response)
|
21
|
+
if result.present?
|
22
|
+
ts = Quickbooks::Model::TaxService.new
|
23
|
+
ts.tax_code = result['TaxCode']
|
24
|
+
ts.tax_code_id = result['TaxCodeId']
|
25
|
+
result['TaxRateDetails'].each do |item|
|
26
|
+
attrs = item.keys.inject({}){|mem, k| mem[k.underscore] = item[k]; mem}
|
27
|
+
ts.tax_rate_details << Quickbooks::Model::TaxRateDetailLine.new(attrs)
|
28
|
+
end
|
29
|
+
return ts
|
30
|
+
else
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def check_details_item
|
36
|
+
if tax_rate_details.blank?
|
37
|
+
errors.add(:tax_rate_details, "must have at least one item")
|
38
|
+
else
|
39
|
+
tax_rate_details.each do |line|
|
40
|
+
unless line.valid?
|
41
|
+
errors.add(:base, line.errors.full_messages.join(', '))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
names = tax_rate_details.map(&:tax_rate_name).uniq
|
45
|
+
if names.size < tax_rate_details.size
|
46
|
+
errors.add(:tax_rate_name, "Duplicate Tax Rate Name")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,12 +1,8 @@
|
|
1
1
|
module Quickbooks
|
2
2
|
module Model
|
3
3
|
# Refer to: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/change_data_capture
|
4
|
-
class VendorChange <
|
4
|
+
class VendorChange < ChangeModel
|
5
5
|
XML_NODE = "Vendor"
|
6
|
-
|
7
|
-
xml_accessor :id, :from => 'Id'
|
8
|
-
xml_accessor :status, :from => '@status'
|
9
|
-
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
10
6
|
end
|
11
7
|
end
|
12
|
-
end
|
8
|
+
end
|
@@ -45,6 +45,10 @@ module Quickbooks
|
|
45
45
|
"#{@base_uri}/#{@company_id}"
|
46
46
|
end
|
47
47
|
|
48
|
+
def is_json?
|
49
|
+
self.class::HTTP_CONTENT_TYPE == "application/json"
|
50
|
+
end
|
51
|
+
|
48
52
|
def default_model_query
|
49
53
|
"SELECT * FROM #{self.class.name.split("::").last}"
|
50
54
|
end
|
@@ -196,10 +200,10 @@ module Quickbooks
|
|
196
200
|
raise "OAuth client has not been initialized. Initialize with setter access_token="
|
197
201
|
end
|
198
202
|
unless headers.has_key?('Content-Type')
|
199
|
-
headers['Content-Type'] = HTTP_CONTENT_TYPE
|
203
|
+
headers['Content-Type'] = self.class::HTTP_CONTENT_TYPE
|
200
204
|
end
|
201
205
|
unless headers.has_key?('Accept')
|
202
|
-
headers['Accept'] = HTTP_ACCEPT
|
206
|
+
headers['Accept'] = self.class::HTTP_ACCEPT
|
203
207
|
end
|
204
208
|
unless headers.has_key?('Accept-Encoding')
|
205
209
|
headers['Accept-Encoding'] = HTTP_ACCEPT_ENCODING
|
@@ -208,8 +212,7 @@ module Quickbooks
|
|
208
212
|
log "------ QUICKBOOKS-RUBY REQUEST ------"
|
209
213
|
log "METHOD = #{method}"
|
210
214
|
log "RESOURCE = #{url}"
|
211
|
-
|
212
|
-
log(log_xml(body))
|
215
|
+
log_request_body(body)
|
213
216
|
log "REQUEST HEADERS = #{headers.inspect}"
|
214
217
|
|
215
218
|
response = case method
|
@@ -222,7 +225,7 @@ module Quickbooks
|
|
222
225
|
else
|
223
226
|
raise "Do not know how to perform that HTTP operation"
|
224
227
|
end
|
225
|
-
check_response(response, :
|
228
|
+
check_response(response, :request => body)
|
226
229
|
end
|
227
230
|
|
228
231
|
def add_query_string_to_url(url, params)
|
@@ -236,9 +239,7 @@ module Quickbooks
|
|
236
239
|
def check_response(response, options = {})
|
237
240
|
log "------ QUICKBOOKS-RUBY RESPONSE ------"
|
238
241
|
log "RESPONSE CODE = #{response.code}"
|
239
|
-
|
240
|
-
log(log_xml(response.plain_body))
|
241
|
-
parse_xml(response.plain_body)
|
242
|
+
log_response_body(response)
|
242
243
|
status = response.code.to_i
|
243
244
|
case status
|
244
245
|
when 200
|
@@ -263,13 +264,37 @@ module Quickbooks
|
|
263
264
|
end
|
264
265
|
end
|
265
266
|
|
267
|
+
def log_response_body(response)
|
268
|
+
log "RESPONSE BODY:"
|
269
|
+
if is_json?
|
270
|
+
log ">>>>#{response.plain_body.inspect}"
|
271
|
+
parse_json(response.plain_body)
|
272
|
+
else
|
273
|
+
log(log_xml(response.plain_body))
|
274
|
+
parse_xml(response.plain_body)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def log_request_body(body)
|
279
|
+
log "REQUEST BODY:"
|
280
|
+
if is_json?
|
281
|
+
log(body.inspect)
|
282
|
+
else
|
283
|
+
log(log_xml(body))
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
266
287
|
def parse_and_raise_exception(options = {})
|
267
288
|
err = parse_intuit_error
|
268
289
|
ex = Quickbooks::IntuitRequestException.new("#{err[:message]}:\n\t#{err[:detail]}")
|
269
290
|
ex.code = err[:code]
|
270
291
|
ex.detail = err[:detail]
|
271
292
|
ex.type = err[:type]
|
272
|
-
|
293
|
+
if is_json?
|
294
|
+
ex.request_json = options[:request]
|
295
|
+
else
|
296
|
+
ex.request_xml = options[:request]
|
297
|
+
end
|
273
298
|
raise ex
|
274
299
|
end
|
275
300
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Service
|
3
|
+
class BaseServiceJSON < BaseService
|
4
|
+
include ServiceCrudJSON
|
5
|
+
HTTP_CONTENT_TYPE = 'application/json'
|
6
|
+
HTTP_ACCEPT = 'application/json'
|
7
|
+
attr_reader :last_response_json
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def parse_json(json)
|
12
|
+
@last_response_json = json
|
13
|
+
end
|
14
|
+
|
15
|
+
def response_is_error?
|
16
|
+
@last_response_json['Fault'].present?
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_intuit_error
|
20
|
+
error = {:message => "", :detail => "", :type => nil, :code => 0}
|
21
|
+
resp = JSON.parse(@last_response_json)
|
22
|
+
fault = resp['Fault']
|
23
|
+
if fault.present?
|
24
|
+
error[:type] = fault['type'] if fault.has_key?('type')
|
25
|
+
if fault_error = fault['Error'].first
|
26
|
+
error[:message] = fault_error['Message']
|
27
|
+
error[:detail] = fault_error['Detail']
|
28
|
+
error[:code] = fault_error['code']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
error
|
32
|
+
rescue Exception => exception
|
33
|
+
error[:detail] = @last_response_json.to_s
|
34
|
+
error
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Service
|
3
|
+
class ChangeService < BaseService
|
4
|
+
|
5
|
+
def url_for_query(query = nil, start_position = 1, max_results = 20)
|
6
|
+
q = entity
|
7
|
+
q = "#{q}&#{query}" if query.present?
|
8
|
+
|
9
|
+
"#{url_for_base}/cdc?entities=#{q}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def since(timestamp)
|
13
|
+
query("changedSince=#{URI.encode_www_form_component(timestamp.iso8601)}")
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def entity
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
|
22
|
+
def model
|
23
|
+
raise NotImplementedError
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,23 +1,16 @@
|
|
1
1
|
module Quickbooks
|
2
2
|
module Service
|
3
|
-
class CustomerChange <
|
4
|
-
|
5
|
-
def url_for_query(query = nil, start_position = 1, max_results = 20)
|
6
|
-
q = "Customer"
|
7
|
-
q = "#{q}&#{query}" if query.present?
|
3
|
+
class CustomerChange < ChangeService
|
8
4
|
|
9
|
-
|
10
|
-
end
|
5
|
+
private
|
11
6
|
|
12
|
-
def
|
13
|
-
|
7
|
+
def entity
|
8
|
+
"Customer"
|
14
9
|
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
10
|
+
|
18
11
|
def model
|
19
12
|
Quickbooks::Model::CustomerChange
|
20
13
|
end
|
21
14
|
end
|
22
15
|
end
|
23
|
-
end
|
16
|
+
end
|
@@ -1,20 +1,13 @@
|
|
1
1
|
module Quickbooks
|
2
2
|
module Service
|
3
|
-
class InvoiceChange <
|
4
|
-
|
5
|
-
def url_for_query(query = nil, start_position = 1, max_results = 20)
|
6
|
-
q = "Invoice"
|
7
|
-
q = "#{q}&#{query}" if query.present?
|
3
|
+
class InvoiceChange < ChangeService
|
8
4
|
|
9
|
-
|
10
|
-
end
|
5
|
+
private
|
11
6
|
|
12
|
-
def
|
13
|
-
|
7
|
+
def entity
|
8
|
+
"Invoice"
|
14
9
|
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
10
|
+
|
18
11
|
def model
|
19
12
|
Quickbooks::Model::InvoiceChange
|
20
13
|
end
|
@@ -1,23 +1,16 @@
|
|
1
1
|
module Quickbooks
|
2
2
|
module Service
|
3
|
-
class ItemChange <
|
4
|
-
|
5
|
-
def url_for_query(query = nil, start_position = 1, max_results = 20)
|
6
|
-
q = "Item"
|
7
|
-
q = "#{q}&#{query}" if query.present?
|
3
|
+
class ItemChange < ChangeService
|
8
4
|
|
9
|
-
|
10
|
-
end
|
5
|
+
private
|
11
6
|
|
12
|
-
def
|
13
|
-
|
7
|
+
def entity
|
8
|
+
"Item"
|
14
9
|
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
10
|
+
|
18
11
|
def model
|
19
12
|
Quickbooks::Model::ItemChange
|
20
13
|
end
|
21
14
|
end
|
22
15
|
end
|
23
|
-
end
|
16
|
+
end
|
@@ -2,27 +2,37 @@ module Quickbooks
|
|
2
2
|
module Service
|
3
3
|
class Reports < BaseService
|
4
4
|
|
5
|
-
def url_for_query(which_report = 'BalanceSheet', date_macro = 'This Fiscal Year-to-date')
|
6
|
-
|
5
|
+
def url_for_query(which_report = 'BalanceSheet', date_macro = 'This Fiscal Year-to-date', options = {})
|
6
|
+
if(options == {})
|
7
|
+
return "#{url_for_base}/reports/#{which_report}?date_macro=#{URI.encode_www_form_component(date_macro)}"
|
8
|
+
else
|
9
|
+
options_string = ""
|
10
|
+
options.each do |key, value|
|
11
|
+
options_string += "#{key}=#{value}&"
|
12
|
+
end
|
13
|
+
options_string = options_string[0..-2]
|
14
|
+
options_string.gsub!(/\s/,"%20")
|
15
|
+
return "#{url_for_base}/reports/#{which_report}?#{options_string}"
|
16
|
+
end
|
7
17
|
end
|
8
18
|
|
9
|
-
def fetch_collection(model, date_macro, object_query)
|
10
|
-
response = do_http_get(url_for_query(object_query, date_macro))
|
19
|
+
def fetch_collection(model, date_macro, object_query, options = {})
|
20
|
+
response = do_http_get(url_for_query(object_query, date_macro, options))
|
11
21
|
|
12
22
|
parse_collection(response, model)
|
13
23
|
|
14
24
|
end
|
15
25
|
|
16
|
-
def query(object_query = 'BalanceSheet', date_macro = 'This Fiscal Year-to-date')
|
17
|
-
fetch_collection(model, date_macro , object_query)
|
26
|
+
def query(object_query = 'BalanceSheet', date_macro = 'This Fiscal Year-to-date', options = {})
|
27
|
+
fetch_collection(model, date_macro , object_query, options)
|
18
28
|
end
|
19
29
|
|
20
30
|
private
|
21
|
-
|
31
|
+
|
22
32
|
def model
|
23
33
|
Quickbooks::Model::Reports
|
24
34
|
end
|
25
35
|
|
26
36
|
end
|
27
37
|
end
|
28
|
-
end
|
38
|
+
end
|
@@ -24,7 +24,8 @@ module Quickbooks
|
|
24
24
|
def create(entity, options = {})
|
25
25
|
raise Quickbooks::InvalidModelException.new(entity.errors.full_messages.join(',')) unless entity.valid?
|
26
26
|
xml = entity.to_xml_ns(options)
|
27
|
-
|
27
|
+
|
28
|
+
response = do_http_post(url_for_resource(model.resource_for_singular), valid_xml_document(xml), options[:query])
|
28
29
|
if response.code.to_i == 200
|
29
30
|
model.from_xml(parse_singular_entity_response(model, response.plain_body))
|
30
31
|
else
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Service
|
3
|
+
module ServiceCrudJSON
|
4
|
+
|
5
|
+
def fetch_by_id(id, params = {})
|
6
|
+
raise NotImplementedError
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(entity, options = {})
|
10
|
+
raise Quickbooks::InvalidModelException.new(entity.errors.full_messages.join(',')) unless entity.valid?
|
11
|
+
response = do_http(:post, url_for_resource(model.resource_for_singular), entity.to_json, options)
|
12
|
+
if response.code.to_i == 200
|
13
|
+
JSON.parse(response.plain_body)
|
14
|
+
else
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
alias :update :create
|
19
|
+
|
20
|
+
def delete
|
21
|
+
raise NotImplementedError
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_by_query_string
|
25
|
+
raise NotImplementedError
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -1,23 +1,16 @@
|
|
1
1
|
module Quickbooks
|
2
2
|
module Service
|
3
|
-
class VendorChange <
|
4
|
-
|
5
|
-
def url_for_query(query = nil, start_position = 1, max_results = 20)
|
6
|
-
q = "Vendor"
|
7
|
-
q = "#{q}&#{query}" if query.present?
|
3
|
+
class VendorChange < ChangeService
|
8
4
|
|
9
|
-
|
10
|
-
end
|
5
|
+
private
|
11
6
|
|
12
|
-
def
|
13
|
-
|
7
|
+
def entity
|
8
|
+
"Vendor"
|
14
9
|
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
10
|
+
|
18
11
|
def model
|
19
12
|
Quickbooks::Model::VendorChange
|
20
13
|
end
|
21
14
|
end
|
22
15
|
end
|
23
|
-
end
|
16
|
+
end
|
data/lib/quickbooks/version.rb
CHANGED
data/lib/quickbooks-ruby.rb
CHANGED
@@ -18,6 +18,7 @@ require 'quickbooks/util/query_builder'
|
|
18
18
|
require 'quickbooks/model/definition'
|
19
19
|
require 'quickbooks/model/validator'
|
20
20
|
require 'quickbooks/model/base_model'
|
21
|
+
require 'quickbooks/model/base_model_json'
|
21
22
|
require 'quickbooks/model/base_reference'
|
22
23
|
require 'quickbooks/model/document_numbering'
|
23
24
|
require 'quickbooks/model/global_tax_calculation'
|
@@ -89,24 +90,32 @@ require 'quickbooks/model/delivery_info'
|
|
89
90
|
require 'quickbooks/model/invoice'
|
90
91
|
require 'quickbooks/model/tax_rate'
|
91
92
|
require 'quickbooks/model/tax_rate_detail'
|
93
|
+
require 'quickbooks/model/tax_rate_detail_line'
|
92
94
|
require 'quickbooks/model/sales_tax_rate_list'
|
93
95
|
require 'quickbooks/model/purchase_tax_rate_list'
|
96
|
+
require 'quickbooks/model/tax_agency'
|
97
|
+
require 'quickbooks/model/tax_service'
|
94
98
|
require 'quickbooks/model/tax_code'
|
95
99
|
require 'quickbooks/model/fault'
|
96
100
|
require 'quickbooks/model/batch_request'
|
97
101
|
require 'quickbooks/model/batch_response'
|
98
102
|
require 'quickbooks/model/preferences'
|
99
103
|
require 'quickbooks/model/refund_receipt'
|
104
|
+
require 'quickbooks/model/change_model'
|
100
105
|
require 'quickbooks/model/invoice_change'
|
101
106
|
require 'quickbooks/model/customer_change'
|
102
107
|
require 'quickbooks/model/vendor_change'
|
103
108
|
require 'quickbooks/model/item_change'
|
104
109
|
require 'quickbooks/model/reports'
|
110
|
+
require 'quickbooks/model/credit_memo_change'
|
111
|
+
require 'quickbooks/model/payment_change'
|
105
112
|
|
106
113
|
|
107
114
|
#== Services
|
108
115
|
require 'quickbooks/service/service_crud'
|
116
|
+
require 'quickbooks/service/service_crud_json'
|
109
117
|
require 'quickbooks/service/base_service'
|
118
|
+
require 'quickbooks/service/base_service_json'
|
110
119
|
require 'quickbooks/service/access_token'
|
111
120
|
require 'quickbooks/service/class'
|
112
121
|
require 'quickbooks/service/attachable'
|
@@ -135,9 +144,12 @@ require 'quickbooks/service/vendor_credit'
|
|
135
144
|
require 'quickbooks/service/estimate'
|
136
145
|
require 'quickbooks/service/tax_rate'
|
137
146
|
require 'quickbooks/service/tax_code'
|
147
|
+
require 'quickbooks/service/tax_agency'
|
148
|
+
require 'quickbooks/service/tax_service'
|
138
149
|
require 'quickbooks/service/batch'
|
139
150
|
require 'quickbooks/service/preferences'
|
140
151
|
require 'quickbooks/service/refund_receipt'
|
152
|
+
require 'quickbooks/service/change_service'
|
141
153
|
require 'quickbooks/service/invoice_change'
|
142
154
|
require 'quickbooks/service/customer_change'
|
143
155
|
require 'quickbooks/service/upload'
|
@@ -145,6 +157,8 @@ require 'quickbooks/util/multipart'
|
|
145
157
|
require 'quickbooks/service/vendor_change'
|
146
158
|
require 'quickbooks/service/item_change'
|
147
159
|
require 'quickbooks/service/reports'
|
160
|
+
require 'quickbooks/service/credit_memo_change'
|
161
|
+
require 'quickbooks/service/payment_change'
|
148
162
|
|
149
163
|
module Quickbooks
|
150
164
|
@@sandbox_mode = false
|
@@ -198,7 +212,7 @@ module Quickbooks
|
|
198
212
|
class MissingRealmError < StandardError; end
|
199
213
|
|
200
214
|
class IntuitRequestException < StandardError
|
201
|
-
attr_accessor :message, :code, :detail, :type, :request_xml
|
215
|
+
attr_accessor :message, :code, :detail, :type, :request_xml, :request_json
|
202
216
|
def initialize(msg)
|
203
217
|
self.message = msg
|
204
218
|
super(msg)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickbooks-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Caughlan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/quickbooks/model/attachable.rb
|
191
191
|
- lib/quickbooks/model/attachable_ref.rb
|
192
192
|
- lib/quickbooks/model/base_model.rb
|
193
|
+
- lib/quickbooks/model/base_model_json.rb
|
193
194
|
- lib/quickbooks/model/base_reference.rb
|
194
195
|
- lib/quickbooks/model/batch_request.rb
|
195
196
|
- lib/quickbooks/model/batch_response.rb
|
@@ -201,11 +202,13 @@ files:
|
|
201
202
|
- lib/quickbooks/model/bill_payment_line_item.rb
|
202
203
|
- lib/quickbooks/model/budget.rb
|
203
204
|
- lib/quickbooks/model/budget_line_item.rb
|
205
|
+
- lib/quickbooks/model/change_model.rb
|
204
206
|
- lib/quickbooks/model/check_payment.rb
|
205
207
|
- lib/quickbooks/model/class.rb
|
206
208
|
- lib/quickbooks/model/company_info.rb
|
207
209
|
- lib/quickbooks/model/credit_card_payment.rb
|
208
210
|
- lib/quickbooks/model/credit_memo.rb
|
211
|
+
- lib/quickbooks/model/credit_memo_change.rb
|
209
212
|
- lib/quickbooks/model/custom_field.rb
|
210
213
|
- lib/quickbooks/model/customer.rb
|
211
214
|
- lib/quickbooks/model/customer_change.rb
|
@@ -242,6 +245,7 @@ files:
|
|
242
245
|
- lib/quickbooks/model/name_value.rb
|
243
246
|
- lib/quickbooks/model/other_contact_info.rb
|
244
247
|
- lib/quickbooks/model/payment.rb
|
248
|
+
- lib/quickbooks/model/payment_change.rb
|
245
249
|
- lib/quickbooks/model/payment_line_detail.rb
|
246
250
|
- lib/quickbooks/model/payment_method.rb
|
247
251
|
- lib/quickbooks/model/physical_address.rb
|
@@ -256,11 +260,14 @@ files:
|
|
256
260
|
- lib/quickbooks/model/sales_receipt.rb
|
257
261
|
- lib/quickbooks/model/sales_tax_rate_list.rb
|
258
262
|
- lib/quickbooks/model/sub_total_line_detail.rb
|
263
|
+
- lib/quickbooks/model/tax_agency.rb
|
259
264
|
- lib/quickbooks/model/tax_code.rb
|
260
265
|
- lib/quickbooks/model/tax_line.rb
|
261
266
|
- lib/quickbooks/model/tax_line_detail.rb
|
262
267
|
- lib/quickbooks/model/tax_rate.rb
|
263
268
|
- lib/quickbooks/model/tax_rate_detail.rb
|
269
|
+
- lib/quickbooks/model/tax_rate_detail_line.rb
|
270
|
+
- lib/quickbooks/model/tax_service.rb
|
264
271
|
- lib/quickbooks/model/telephone_number.rb
|
265
272
|
- lib/quickbooks/model/term.rb
|
266
273
|
- lib/quickbooks/model/time_activity.rb
|
@@ -275,13 +282,16 @@ files:
|
|
275
282
|
- lib/quickbooks/service/account.rb
|
276
283
|
- lib/quickbooks/service/attachable.rb
|
277
284
|
- lib/quickbooks/service/base_service.rb
|
285
|
+
- lib/quickbooks/service/base_service_json.rb
|
278
286
|
- lib/quickbooks/service/batch.rb
|
279
287
|
- lib/quickbooks/service/bill.rb
|
280
288
|
- lib/quickbooks/service/bill_payment.rb
|
281
289
|
- lib/quickbooks/service/budget.rb
|
290
|
+
- lib/quickbooks/service/change_service.rb
|
282
291
|
- lib/quickbooks/service/class.rb
|
283
292
|
- lib/quickbooks/service/company_info.rb
|
284
293
|
- lib/quickbooks/service/credit_memo.rb
|
294
|
+
- lib/quickbooks/service/credit_memo_change.rb
|
285
295
|
- lib/quickbooks/service/customer.rb
|
286
296
|
- lib/quickbooks/service/customer_change.rb
|
287
297
|
- lib/quickbooks/service/department.rb
|
@@ -294,6 +304,7 @@ files:
|
|
294
304
|
- lib/quickbooks/service/item_change.rb
|
295
305
|
- lib/quickbooks/service/journal_entry.rb
|
296
306
|
- lib/quickbooks/service/payment.rb
|
307
|
+
- lib/quickbooks/service/payment_change.rb
|
297
308
|
- lib/quickbooks/service/payment_method.rb
|
298
309
|
- lib/quickbooks/service/preferences.rb
|
299
310
|
- lib/quickbooks/service/purchase.rb
|
@@ -302,8 +313,11 @@ files:
|
|
302
313
|
- lib/quickbooks/service/reports.rb
|
303
314
|
- lib/quickbooks/service/sales_receipt.rb
|
304
315
|
- lib/quickbooks/service/service_crud.rb
|
316
|
+
- lib/quickbooks/service/service_crud_json.rb
|
317
|
+
- lib/quickbooks/service/tax_agency.rb
|
305
318
|
- lib/quickbooks/service/tax_code.rb
|
306
319
|
- lib/quickbooks/service/tax_rate.rb
|
320
|
+
- lib/quickbooks/service/tax_service.rb
|
307
321
|
- lib/quickbooks/service/term.rb
|
308
322
|
- lib/quickbooks/service/time_activity.rb
|
309
323
|
- lib/quickbooks/service/upload.rb
|