quickbooks-ruby-oauth2 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/quickbooks/faraday/middleware/gzip.rb +72 -0
- data/lib/quickbooks/model/access_token_response.rb +29 -0
- data/lib/quickbooks/model/account.rb +78 -0
- data/lib/quickbooks/model/account_based_expense_line_detail.rb +15 -0
- data/lib/quickbooks/model/attachable.rb +33 -0
- data/lib/quickbooks/model/attachable_ref.rb +22 -0
- data/lib/quickbooks/model/base_model.rb +120 -0
- data/lib/quickbooks/model/base_model_json.rb +16 -0
- data/lib/quickbooks/model/base_reference.rb +23 -0
- data/lib/quickbooks/model/batch_request.rb +45 -0
- data/lib/quickbooks/model/batch_response.rb +33 -0
- data/lib/quickbooks/model/bill.rb +45 -0
- data/lib/quickbooks/model/bill_line_item.rb +42 -0
- data/lib/quickbooks/model/bill_payment.rb +40 -0
- data/lib/quickbooks/model/bill_payment_check.rb +12 -0
- data/lib/quickbooks/model/bill_payment_credit_card.rb +10 -0
- data/lib/quickbooks/model/bill_payment_line_item.rb +21 -0
- data/lib/quickbooks/model/budget.rb +27 -0
- data/lib/quickbooks/model/budget_line_item.rb +15 -0
- data/lib/quickbooks/model/change_data_capture.rb +42 -0
- data/lib/quickbooks/model/change_model.rb +10 -0
- data/lib/quickbooks/model/check_payment.rb +11 -0
- data/lib/quickbooks/model/class.rb +31 -0
- data/lib/quickbooks/model/company_info.rb +69 -0
- data/lib/quickbooks/model/credit_card_payment.rb +17 -0
- data/lib/quickbooks/model/credit_memo.rb +59 -0
- data/lib/quickbooks/model/credit_memo_change.rb +8 -0
- data/lib/quickbooks/model/custom_field.rb +13 -0
- data/lib/quickbooks/model/customer.rb +76 -0
- data/lib/quickbooks/model/customer_change.rb +8 -0
- data/lib/quickbooks/model/definition.rb +46 -0
- data/lib/quickbooks/model/delivery_info.rb +8 -0
- data/lib/quickbooks/model/department.rb +31 -0
- data/lib/quickbooks/model/deposit.rb +44 -0
- data/lib/quickbooks/model/deposit_line_detail.rb +17 -0
- data/lib/quickbooks/model/deposit_line_item.rb +35 -0
- data/lib/quickbooks/model/description_line_detail.rb +7 -0
- data/lib/quickbooks/model/discount_line_detail.rb +15 -0
- data/lib/quickbooks/model/discount_override.rb +13 -0
- data/lib/quickbooks/model/document_numbering.rb +18 -0
- data/lib/quickbooks/model/effective_tax_rate.rb +15 -0
- data/lib/quickbooks/model/email_address.rb +19 -0
- data/lib/quickbooks/model/employee.rb +47 -0
- data/lib/quickbooks/model/entity.rb +16 -0
- data/lib/quickbooks/model/entity_ref.rb +8 -0
- data/lib/quickbooks/model/estimate.rb +76 -0
- data/lib/quickbooks/model/exchange_rate.rb +23 -0
- data/lib/quickbooks/model/fault.rb +16 -0
- data/lib/quickbooks/model/global_tax_calculation.rb +13 -0
- data/lib/quickbooks/model/group_line_detail.rb +13 -0
- data/lib/quickbooks/model/has_line_items.rb +14 -0
- data/lib/quickbooks/model/invoice.rb +107 -0
- data/lib/quickbooks/model/invoice_change.rb +9 -0
- data/lib/quickbooks/model/invoice_group_line_detail.rb +14 -0
- data/lib/quickbooks/model/invoice_line_item.rb +88 -0
- data/lib/quickbooks/model/item.rb +87 -0
- data/lib/quickbooks/model/item_based_expense_line_detail.rb +20 -0
- data/lib/quickbooks/model/item_change.rb +8 -0
- data/lib/quickbooks/model/item_group_detail.rb +9 -0
- data/lib/quickbooks/model/item_group_line.rb +20 -0
- data/lib/quickbooks/model/journal_entry.rb +36 -0
- data/lib/quickbooks/model/journal_entry_line_detail.rb +27 -0
- data/lib/quickbooks/model/line.rb +95 -0
- data/lib/quickbooks/model/line_ex.rb +9 -0
- data/lib/quickbooks/model/linked_transaction.rb +9 -0
- data/lib/quickbooks/model/markup_info.rb +12 -0
- data/lib/quickbooks/model/meta_data.rb +24 -0
- data/lib/quickbooks/model/name_value.rb +8 -0
- data/lib/quickbooks/model/other_contact_info.rb +8 -0
- data/lib/quickbooks/model/payment.rb +43 -0
- data/lib/quickbooks/model/payment_change.rb +8 -0
- data/lib/quickbooks/model/payment_line_detail.rb +12 -0
- data/lib/quickbooks/model/payment_method.rb +25 -0
- data/lib/quickbooks/model/physical_address.rb +40 -0
- data/lib/quickbooks/model/preferences.rb +49 -0
- data/lib/quickbooks/model/purchase.rb +57 -0
- data/lib/quickbooks/model/purchase_line_item.rb +44 -0
- data/lib/quickbooks/model/purchase_order.rb +50 -0
- data/lib/quickbooks/model/purchase_tax_rate_list.rb +11 -0
- data/lib/quickbooks/model/refund_receipt.rb +62 -0
- data/lib/quickbooks/model/refund_receipt_change.rb +8 -0
- data/lib/quickbooks/model/report.rb +52 -0
- data/lib/quickbooks/model/sales_item_line_detail.rb +16 -0
- data/lib/quickbooks/model/sales_receipt.rb +65 -0
- data/lib/quickbooks/model/sales_tax_rate_list.rb +11 -0
- data/lib/quickbooks/model/sub_total_line_detail.rb +13 -0
- data/lib/quickbooks/model/tax_agency.rb +18 -0
- data/lib/quickbooks/model/tax_code.rb +21 -0
- data/lib/quickbooks/model/tax_line.rb +15 -0
- data/lib/quickbooks/model/tax_line_detail.rb +16 -0
- data/lib/quickbooks/model/tax_rate.rb +28 -0
- data/lib/quickbooks/model/tax_rate_detail.rb +15 -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/telephone_number.rb +13 -0
- data/lib/quickbooks/model/term.rb +28 -0
- data/lib/quickbooks/model/time_activity.rb +79 -0
- data/lib/quickbooks/model/transaction_tax_detail.rb +12 -0
- data/lib/quickbooks/model/transfer.rb +21 -0
- data/lib/quickbooks/model/upload.rb +35 -0
- data/lib/quickbooks/model/validator.rb +10 -0
- data/lib/quickbooks/model/vendor.rb +53 -0
- data/lib/quickbooks/model/vendor_change.rb +8 -0
- data/lib/quickbooks/model/vendor_credit.rb +40 -0
- data/lib/quickbooks/model/web_site_address.rb +16 -0
- data/lib/quickbooks/service/access_token.rb +38 -0
- data/lib/quickbooks/service/account.rb +17 -0
- data/lib/quickbooks/service/attachable.rb +12 -0
- data/lib/quickbooks/service/base_service.rb +445 -0
- data/lib/quickbooks/service/base_service_json.rb +39 -0
- data/lib/quickbooks/service/batch.rb +11 -0
- data/lib/quickbooks/service/bill.rb +16 -0
- data/lib/quickbooks/service/bill_payment.rb +16 -0
- data/lib/quickbooks/service/budget.rb +12 -0
- data/lib/quickbooks/service/change_data_capture.rb +24 -0
- data/lib/quickbooks/service/change_service.rb +28 -0
- data/lib/quickbooks/service/class.rb +23 -0
- data/lib/quickbooks/service/company_info.rb +12 -0
- data/lib/quickbooks/service/credit_memo.rb +16 -0
- data/lib/quickbooks/service/credit_memo_change.rb +16 -0
- data/lib/quickbooks/service/customer.rb +18 -0
- data/lib/quickbooks/service/customer_change.rb +16 -0
- data/lib/quickbooks/service/department.rb +23 -0
- data/lib/quickbooks/service/deposit.rb +16 -0
- data/lib/quickbooks/service/employee.rb +24 -0
- data/lib/quickbooks/service/estimate.rb +22 -0
- data/lib/quickbooks/service/exchange_rate.rb +25 -0
- data/lib/quickbooks/service/invoice.rb +45 -0
- data/lib/quickbooks/service/invoice_change.rb +16 -0
- data/lib/quickbooks/service/item.rb +32 -0
- data/lib/quickbooks/service/item_change.rb +16 -0
- data/lib/quickbooks/service/journal_entry.rb +16 -0
- data/lib/quickbooks/service/payment.rb +29 -0
- data/lib/quickbooks/service/payment_change.rb +16 -0
- data/lib/quickbooks/service/payment_method.rb +30 -0
- data/lib/quickbooks/service/preferences.rb +12 -0
- data/lib/quickbooks/service/purchase.rb +16 -0
- data/lib/quickbooks/service/purchase_order.rb +16 -0
- data/lib/quickbooks/service/refund_receipt.rb +16 -0
- data/lib/quickbooks/service/refund_receipt_change.rb +16 -0
- data/lib/quickbooks/service/reports.rb +33 -0
- data/lib/quickbooks/service/responses/methods.rb +17 -0
- data/lib/quickbooks/service/responses/oauth1_http_response.rb +42 -0
- data/lib/quickbooks/service/responses/oauth2_http_response.rb +43 -0
- data/lib/quickbooks/service/responses/oauth_http_response.rb +21 -0
- data/lib/quickbooks/service/sales_receipt.rb +46 -0
- data/lib/quickbooks/service/service_crud.rb +75 -0
- data/lib/quickbooks/service/service_crud_json.rb +31 -0
- data/lib/quickbooks/service/tax_agency.rb +12 -0
- data/lib/quickbooks/service/tax_code.rb +12 -0
- data/lib/quickbooks/service/tax_rate.rb +12 -0
- data/lib/quickbooks/service/tax_service.rb +11 -0
- data/lib/quickbooks/service/term.rb +17 -0
- data/lib/quickbooks/service/time_activity.rb +16 -0
- data/lib/quickbooks/service/transfer.rb +16 -0
- data/lib/quickbooks/service/upload.rb +39 -0
- data/lib/quickbooks/service/vendor.rb +24 -0
- data/lib/quickbooks/service/vendor_change.rb +16 -0
- data/lib/quickbooks/service/vendor_credit.rb +16 -0
- data/lib/quickbooks/util/collection.rb +18 -0
- data/lib/quickbooks/util/http_encoding_helper.rb +54 -0
- data/lib/quickbooks/util/logging.rb +19 -0
- data/lib/quickbooks/util/multipart.rb +85 -0
- data/lib/quickbooks/util/name_entity.rb +85 -0
- data/lib/quickbooks/util/query_builder.rb +35 -0
- data/lib/quickbooks/version.rb +5 -0
- data/lib/quickbooks-ruby.rb +255 -0
- metadata +378 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2c9c2d528c57e9e6d09996f5074a207f9ed11c52c8f41b1577d8a659e1b803bc
|
4
|
+
data.tar.gz: 900287d6e0a8d4a86065d89d657c32bb821dfc28503ac4203ffefd55f2fb1250
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 11486f7112333779da49608738d6ce7affd6fc37aed76d8f0ffe3483c09f25d454b6b35a80b82d679e2c13cbc0cfa2f5e1038548369820ea8590821d2d61813a
|
7
|
+
data.tar.gz: 9b30b67dcc88b031a685abea47ac9b24883f012da7d75ab7b49e8c47c28b6bbb8115aead480f2fcc9cfd3951a0b6880322900b21273195ba669c5c0249e87e28
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# https://github.com/lostisland/faraday_middleware/blob/master/lib/faraday_middleware/gzip.rb
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
# Middleware to automatically decompress response bodies. If the
|
6
|
+
# "Accept-Encoding" header wasn't set in the request, this sets it to
|
7
|
+
# "gzip,deflate" and appropriately handles the compressed response from the
|
8
|
+
# server. This resembles what Ruby 1.9+ does internally in Net::HTTP#get.
|
9
|
+
#
|
10
|
+
# This middleware is NOT necessary when these adapters are used:
|
11
|
+
# - net_http on Ruby 1.9+
|
12
|
+
# - net_http_persistent on Ruby 2.0+
|
13
|
+
# - em_http
|
14
|
+
class Gzip < Faraday::Middleware
|
15
|
+
dependency 'zlib'
|
16
|
+
|
17
|
+
ACCEPT_ENCODING = 'Accept-Encoding'.freeze
|
18
|
+
CONTENT_ENCODING = 'Content-Encoding'.freeze
|
19
|
+
CONTENT_LENGTH = 'Content-Length'.freeze
|
20
|
+
SUPPORTED_ENCODINGS = 'gzip,deflate,br'.freeze
|
21
|
+
RUBY_ENCODING = '1.9'.respond_to?(:force_encoding)
|
22
|
+
|
23
|
+
def call(env)
|
24
|
+
env[:request_headers][ACCEPT_ENCODING] ||= SUPPORTED_ENCODINGS
|
25
|
+
@app.call(env).on_complete do |response_env|
|
26
|
+
case response_env[:response_headers][CONTENT_ENCODING]
|
27
|
+
when 'gzip'
|
28
|
+
reset_body(response_env, &method(:uncompress_gzip))
|
29
|
+
when 'deflate'
|
30
|
+
reset_body(response_env, &method(:inflate))
|
31
|
+
when 'br'
|
32
|
+
reset_body(response_env, &method(:brotli_inflate))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def reset_body(env)
|
38
|
+
env[:body] = yield(env[:body])
|
39
|
+
env[:response_headers].delete(CONTENT_ENCODING)
|
40
|
+
env[:response_headers][CONTENT_LENGTH] = env[:body].length
|
41
|
+
end
|
42
|
+
|
43
|
+
def uncompress_gzip(body)
|
44
|
+
io = StringIO.new(body)
|
45
|
+
gzip_reader = if RUBY_ENCODING
|
46
|
+
Zlib::GzipReader.new(io, :encoding => 'ASCII-8BIT')
|
47
|
+
else
|
48
|
+
Zlib::GzipReader.new(io)
|
49
|
+
end
|
50
|
+
gzip_reader.read
|
51
|
+
end
|
52
|
+
|
53
|
+
def inflate(body)
|
54
|
+
# Inflate as a DEFLATE (RFC 1950+RFC 1951) stream
|
55
|
+
Zlib::Inflate.inflate(body)
|
56
|
+
rescue Zlib::DataError
|
57
|
+
# Fall back to inflating as a "raw" deflate stream which
|
58
|
+
# Microsoft servers return
|
59
|
+
inflate = Zlib::Inflate.new(-Zlib::MAX_WBITS)
|
60
|
+
begin
|
61
|
+
inflate.inflate(body)
|
62
|
+
ensure
|
63
|
+
inflate.close
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def brotli_inflate(body)
|
68
|
+
self.class.dependency 'brotli'
|
69
|
+
|
70
|
+
Brotli.inflate(body)
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class AccessTokenResponse < BaseModel
|
4
|
+
xml_convention :camelcase
|
5
|
+
xml_accessor :error_code, :from => 'ErrorCode'
|
6
|
+
xml_accessor :error_message, :from => 'ErrorMessage'
|
7
|
+
xml_accessor :token, :from => 'OAuthToken'
|
8
|
+
xml_accessor :secret, :from => 'OAuthTokenSecret'
|
9
|
+
xml_accessor :server_time, :from => 'ServerTime', :as => Time
|
10
|
+
|
11
|
+
def error?
|
12
|
+
error_code.to_i != 0
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
=begin
|
20
|
+
<?xml version="1.0"?>
|
21
|
+
<ReconnectResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://platform.intuit.com/api/v1">
|
22
|
+
<ErrorMessage/>
|
23
|
+
<ErrorCode>0</ErrorCode>
|
24
|
+
<ServerTime>2012-01-04T19:21:21.0782072Z</ServerTime>
|
25
|
+
<OAuthToken>qye2eIdQ5H5yMyrlJflUWh712xfFXjyNnW1MfbC0rz04TfCP</OAuthToken>
|
26
|
+
<OAuthTokenSecret>cyDeUNQTkFzoR0KkDn7viN6uLQxWTobeEUKW7I79</OAuthTokenSecret>
|
27
|
+
</ReconnectResponse>
|
28
|
+
|
29
|
+
=end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class Account < BaseModel
|
4
|
+
XML_COLLECTION_NODE = "Account"
|
5
|
+
XML_NODE = "Account"
|
6
|
+
REST_RESOURCE = 'account'
|
7
|
+
|
8
|
+
ASSET = 'Asset'
|
9
|
+
EQUITY = 'Equity'
|
10
|
+
EXPENSE = 'Expense'
|
11
|
+
LIABILITY = 'Liability'
|
12
|
+
REVENUE = 'Revenue'
|
13
|
+
|
14
|
+
ACCOUNT_CLASSIFICATION = [ASSET, EQUITY, EXPENSE, LIABILITY, REVENUE]
|
15
|
+
|
16
|
+
xml_name XML_NODE
|
17
|
+
|
18
|
+
xml_accessor :id, :from => 'Id'
|
19
|
+
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
|
20
|
+
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
21
|
+
xml_accessor :has_attachment?, :from => 'HasAttachment'
|
22
|
+
xml_accessor :name, :from => 'Name'
|
23
|
+
xml_accessor :description, :from => 'Description'
|
24
|
+
xml_accessor :fully_qualified_name, :from => 'FullyQualifiedName' # ReadOnly
|
25
|
+
|
26
|
+
xml_accessor :sub_account?, :from => 'SubAccount'
|
27
|
+
xml_accessor :parent_ref, :from => 'ParentRef', :as => BaseReference
|
28
|
+
|
29
|
+
xml_accessor :active?, :from => 'Active'
|
30
|
+
|
31
|
+
xml_accessor :classification, :from => 'Classification'
|
32
|
+
xml_accessor :account_type, :from => 'AccountType'
|
33
|
+
xml_accessor :account_sub_type, :from => 'AccountSubType'
|
34
|
+
|
35
|
+
xml_accessor :acct_num, :from => 'AcctNum'
|
36
|
+
xml_accessor :bank_num, :from => 'BankNum'
|
37
|
+
|
38
|
+
xml_accessor :current_balance, :from => 'CurrentBalance', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
39
|
+
xml_accessor :current_balance_with_sub_accounts, :from => 'CurrentBalanceWithSubAccounts', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
40
|
+
xml_accessor :opening_balance, :from => 'OpeningBalance', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
41
|
+
xml_accessor :opening_balance_date, :from => 'OpeningBalanceDate', :as => DateTime
|
42
|
+
xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
|
43
|
+
xml_accessor :tax_account?, :from => 'TaxAccount'
|
44
|
+
xml_accessor :tax_code_ref, :from => 'TaxCodeRef', :as => BaseReference
|
45
|
+
|
46
|
+
reference_setters :parent_ref, :currency_ref, :tax_code_ref
|
47
|
+
|
48
|
+
#== Validations
|
49
|
+
validates_inclusion_of :classification, :in => ACCOUNT_CLASSIFICATION
|
50
|
+
validates_length_of :name, :minimum => 1, :maximum => 100
|
51
|
+
validate :name_cannot_contain_invalid_characters
|
52
|
+
|
53
|
+
def name_cannot_contain_invalid_characters
|
54
|
+
if name && (name.index(':') || name.index('"'))
|
55
|
+
errors.add('name', ":#{name} cannot contain a colon (:) or double quotes (\").")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def valid_for_update?
|
60
|
+
if sync_token.nil?
|
61
|
+
errors.add(:sync_token, "Missing required attribute SyncToken for update")
|
62
|
+
end
|
63
|
+
errors.empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
def valid_for_create?
|
67
|
+
valid?
|
68
|
+
errors.empty?
|
69
|
+
end
|
70
|
+
|
71
|
+
def valid_for_deletion?
|
72
|
+
return false if(id.nil? || sync_token.nil?)
|
73
|
+
id.to_i > 0 && !sync_token.to_s.empty? && sync_token.to_i >= 0
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class AccountBasedExpenseLineDetail < BaseModel
|
4
|
+
xml_accessor :customer_ref, :from => 'CustomerRef', :as => BaseReference
|
5
|
+
xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
|
6
|
+
xml_accessor :account_ref, :from => 'AccountRef', :as => BaseReference
|
7
|
+
xml_accessor :billable_status, :from => 'BillableStatus'
|
8
|
+
xml_accessor :tax_amount, :from => 'UnitPrice', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
9
|
+
xml_accessor :tax_code_ref, :from => 'TaxCodeRef', :as => BaseReference
|
10
|
+
|
11
|
+
reference_setters :customer_ref, :class_ref, :account_ref, :tax_code_ref
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'quickbooks/model/attachable_ref'
|
2
|
+
|
3
|
+
module Quickbooks
|
4
|
+
module Model
|
5
|
+
class Attachable < BaseModel
|
6
|
+
|
7
|
+
XML_COLLECTION_NODE = "Attachable"
|
8
|
+
XML_NODE = "Attachable"
|
9
|
+
REST_RESOURCE = 'attachable'
|
10
|
+
|
11
|
+
xml_accessor :id, :from => 'Id'
|
12
|
+
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
|
13
|
+
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
14
|
+
xml_accessor :attachable_ref, :as => AttachableRef
|
15
|
+
xml_accessor :file_name
|
16
|
+
xml_accessor :file_access_uri
|
17
|
+
xml_accessor :temp_download_uri
|
18
|
+
xml_accessor :size
|
19
|
+
xml_accessor :content_type
|
20
|
+
xml_accessor :category
|
21
|
+
xml_accessor :lat
|
22
|
+
xml_accessor :long
|
23
|
+
xml_accessor :place_name
|
24
|
+
xml_accessor :note
|
25
|
+
xml_accessor :tag
|
26
|
+
xml_accessor :thumbnail_file_access_uri
|
27
|
+
xml_accessor :thumbnail_temp_download_uri
|
28
|
+
|
29
|
+
reference_setters :attachable_ref
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'quickbooks/model/entity_ref'
|
2
|
+
require 'quickbooks/model/custom_field'
|
3
|
+
|
4
|
+
module Quickbooks
|
5
|
+
module Model
|
6
|
+
class AttachableRef < BaseModel
|
7
|
+
xml_accessor :entity_ref, :as => BaseReference
|
8
|
+
xml_accessor :line_info
|
9
|
+
xml_accessor :include_on_send?
|
10
|
+
xml_accessor :inactive?
|
11
|
+
xml_accessor :no_ref_only?
|
12
|
+
xml_accessor :custom_fields, :as => [CustomField]
|
13
|
+
|
14
|
+
def initialize(an_entity_ref = nil)
|
15
|
+
if an_entity_ref
|
16
|
+
self.entity_ref = an_entity_ref
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class BaseModel
|
4
|
+
include Definition
|
5
|
+
include ActiveModel::Validations
|
6
|
+
include Validator
|
7
|
+
include ROXML
|
8
|
+
|
9
|
+
xml_convention :camelcase
|
10
|
+
|
11
|
+
def initialize(attributes={})
|
12
|
+
attributes.each {|key, value| public_send("#{key}=", value) }
|
13
|
+
end
|
14
|
+
|
15
|
+
# ROXML doesnt insert the namespaces into generated XML so we need to do it ourselves
|
16
|
+
# insert the static namespaces in the first opening tag that matches the +model_name+
|
17
|
+
def to_xml_inject_ns(model_name, options = {})
|
18
|
+
s = StringIO.new
|
19
|
+
xml = to_xml(options).write_to(s, :indent => 0, :indent_text => '')
|
20
|
+
destination_name = options.fetch(:destination_name, nil)
|
21
|
+
destination_name ||= model_name
|
22
|
+
|
23
|
+
sparse = options.fetch(:sparse, false)
|
24
|
+
sparse_string = %{sparse="#{sparse}"}
|
25
|
+
step1 = s.string.sub("<#{model_name}>", "<#{destination_name} #{Quickbooks::Service::BaseService::XML_NS} #{sparse_string}>")
|
26
|
+
step2 = step1.sub("</#{model_name}>", "</#{destination_name}>")
|
27
|
+
step2
|
28
|
+
end
|
29
|
+
|
30
|
+
def as_json(options = nil)
|
31
|
+
options = {} if options.nil?
|
32
|
+
except_conditions = ["roxml_references"]
|
33
|
+
except_conditions << options[:except]
|
34
|
+
options[:except] = except_conditions.flatten.uniq.compact
|
35
|
+
super(options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_xml_ns(options = {})
|
39
|
+
to_xml_inject_ns(self.class::XML_NODE, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
delegate :[], :fetch, :to => :attributes
|
43
|
+
|
44
|
+
def attributes
|
45
|
+
attributes = self.class.attribute_names.map do |name|
|
46
|
+
value = public_send(name)
|
47
|
+
value = value.attributes if value.respond_to?(:attributes)
|
48
|
+
[name, value]
|
49
|
+
end
|
50
|
+
|
51
|
+
HashWithIndifferentAccess[attributes]
|
52
|
+
end
|
53
|
+
|
54
|
+
def inspect
|
55
|
+
# it would be nice if we could inspect all the children,
|
56
|
+
# but it's likely to blow the stack in some cases
|
57
|
+
"#<#{self.class} " +
|
58
|
+
"#{attributes.map{|k,v| "#{k}: #{v.nil? ? 'nil' : v.to_s }"}.join ", "}>"
|
59
|
+
end
|
60
|
+
class << self
|
61
|
+
def to_xml_big_decimal
|
62
|
+
Proc.new { |val| val.nil? ? nil : val.to_f }
|
63
|
+
end
|
64
|
+
|
65
|
+
def attribute_names
|
66
|
+
roxml_attrs.map(&:accessor)
|
67
|
+
end
|
68
|
+
|
69
|
+
# These can be over-ridden in each model object as needed
|
70
|
+
def resource_for_collection
|
71
|
+
self::REST_RESOURCE
|
72
|
+
end
|
73
|
+
|
74
|
+
def resource_for_singular
|
75
|
+
self::REST_RESOURCE
|
76
|
+
end
|
77
|
+
|
78
|
+
# Automatically generate an ID setter.
|
79
|
+
# Example:
|
80
|
+
# reference_setters :discount_ref
|
81
|
+
# Would generate a method like:
|
82
|
+
# def discount_id=(id)
|
83
|
+
# self.discount_ref = BaseReference.new(id)
|
84
|
+
# end
|
85
|
+
def reference_setters(*args)
|
86
|
+
references = args.empty? ? reference_attrs : args
|
87
|
+
|
88
|
+
references.each do |attribute|
|
89
|
+
last_index = attribute.to_s.rindex('_ref')
|
90
|
+
field_name = !last_index.nil? ? attribute.to_s.slice(0, last_index) : attribute
|
91
|
+
method_name = "#{field_name}_id=".to_sym
|
92
|
+
unless instance_methods(false).include?(method_name)
|
93
|
+
method_definition = <<-METH
|
94
|
+
def #{method_name}(id)
|
95
|
+
self.#{attribute} = BaseReference.new(id)
|
96
|
+
end
|
97
|
+
METH
|
98
|
+
class_eval(method_definition)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def reference_attrs
|
104
|
+
matches = roxml_attrs.select{|attr| attr.sought_type == Quickbooks::Model::BaseReference}.map{|attr| attr.accessor}
|
105
|
+
end
|
106
|
+
|
107
|
+
def inspect
|
108
|
+
"#{super}(#{attrs_with_types.join " "})"
|
109
|
+
end
|
110
|
+
|
111
|
+
def attrs_with_types
|
112
|
+
roxml_attrs.map do |attr|
|
113
|
+
"#{attr.accessor}:" +
|
114
|
+
"#{attr.class.block_shorthands.invert[attr.blocks.last]}:#{attr.sought_type}"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -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
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class BaseReference < BaseModel
|
4
|
+
xml_convention :camelcase
|
5
|
+
xml_accessor :name, :from => '@name' # Attribute with name 'name'
|
6
|
+
xml_accessor :value, :from => :content
|
7
|
+
xml_accessor :type, :from => '@type' # Attribute with name 'type'
|
8
|
+
|
9
|
+
def initialize(value=nil, attributes={})
|
10
|
+
self.value = value
|
11
|
+
attributes.each {|key, value| public_send("#{key}=", value) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_i
|
15
|
+
self.value.to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
self.value.to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Quickbooks::Model::BatchRequest < Quickbooks::Model::BaseModel
|
2
|
+
class BatchItemRequest
|
3
|
+
include ROXML
|
4
|
+
XML_NODE = "BatchItemRequest"
|
5
|
+
xml_name XML_NODE
|
6
|
+
|
7
|
+
xml_accessor :operation, :from => "@operation"
|
8
|
+
xml_accessor :bId, :from => "@bId"
|
9
|
+
|
10
|
+
# Supported Entities
|
11
|
+
xml_accessor :account, from: "Account", as: Quickbooks::Model::Account
|
12
|
+
xml_accessor :bill_payment, from: "BillPayment", as: Quickbooks::Model::BillPayment
|
13
|
+
xml_accessor :bill, from: "Bill", as: Quickbooks::Model::Bill
|
14
|
+
xml_accessor :credit_memo, from: "CreditMemo", as: Quickbooks::Model::CreditMemo
|
15
|
+
xml_accessor :customer, from: "Customer", as: Quickbooks::Model::Customer
|
16
|
+
xml_accessor :invoice, from: "Invoice", as: Quickbooks::Model::Invoice
|
17
|
+
xml_accessor :item, from: "Item", as: Quickbooks::Model::Item
|
18
|
+
xml_accessor :journal_entry, from: "JournalEntry", as: Quickbooks::Model::JournalEntry
|
19
|
+
xml_accessor :payment, from: "Payment", as: Quickbooks::Model::Payment
|
20
|
+
xml_accessor :purchase_order, from: "PurchaseOrder", as: Quickbooks::Model::PurchaseOrder
|
21
|
+
xml_accessor :purchase, from: "Purchase", as: Quickbooks::Model::Purchase
|
22
|
+
xml_accessor :refund_receipt, from: "RefundReceipt", as: Quickbooks::Model::RefundReceipt
|
23
|
+
xml_accessor :sales_receipt, from: "SalesReceipt", as: Quickbooks::Model::SalesReceipt
|
24
|
+
xml_accessor :time_activity, from: "TimeActivity", as: Quickbooks::Model::TimeActivity
|
25
|
+
xml_accessor :vendor, from: "Vendor", as: Quickbooks::Model::Vendor
|
26
|
+
end
|
27
|
+
|
28
|
+
XML_COLLECTION_NODE = "IntuitBatchRequest"
|
29
|
+
XML_NODE = "IntuitBatchRequest"
|
30
|
+
REST_RESOURCE = 'batch'
|
31
|
+
xml_name XML_NODE
|
32
|
+
xml_accessor :request_items, from: "BatchItemRequest", as: [Quickbooks::Model::BatchRequest::BatchItemRequest]
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
self.request_items = []
|
36
|
+
end
|
37
|
+
|
38
|
+
def add(batch_item_id, batch_item, operation)
|
39
|
+
bir = Quickbooks::Model::BatchRequest::BatchItemRequest.new
|
40
|
+
bir.operation = operation
|
41
|
+
bir.bId = batch_item_id
|
42
|
+
bir.send("#{batch_item.class::XML_NODE.underscore}=", batch_item)
|
43
|
+
self.request_items << bir
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Quickbooks::Model::BatchResponse < Quickbooks::Model::BaseModel
|
2
|
+
class BatchItemResponse
|
3
|
+
include ROXML
|
4
|
+
xml_name "BatchItemResponse"
|
5
|
+
|
6
|
+
xml_accessor :bId, :from => "@bId"
|
7
|
+
xml_accessor :fault, :from => 'Fault', :as => Quickbooks::Model::Fault
|
8
|
+
|
9
|
+
# Supported Entities
|
10
|
+
xml_accessor :account, from: "Account", as: Quickbooks::Model::Account
|
11
|
+
xml_accessor :bill_payment, from: "BillPayment", as: Quickbooks::Model::BillPayment
|
12
|
+
xml_accessor :bill, from: "Bill", as: Quickbooks::Model::Bill
|
13
|
+
xml_accessor :credit_memo, from: "CreditMemo", as: Quickbooks::Model::CreditMemo
|
14
|
+
xml_accessor :customer, from: "Customer", as: Quickbooks::Model::Customer
|
15
|
+
xml_accessor :invoice, from: "Invoice", as: Quickbooks::Model::Invoice
|
16
|
+
xml_accessor :item, from: "Item", as: Quickbooks::Model::Item
|
17
|
+
xml_accessor :journal_entry, from: "JournalEntry", as: Quickbooks::Model::JournalEntry
|
18
|
+
xml_accessor :payment, from: "Payment", as: Quickbooks::Model::Payment
|
19
|
+
xml_accessor :purchase_order, from: "PurchaseOrder", as: Quickbooks::Model::PurchaseOrder
|
20
|
+
xml_accessor :purchase, from: "Purchase", as: Quickbooks::Model::Purchase
|
21
|
+
xml_accessor :refund_receipt, from: "RefundReceipt", as: Quickbooks::Model::RefundReceipt
|
22
|
+
xml_accessor :sales_receipt, from: "SalesReceipt", as: Quickbooks::Model::SalesReceipt
|
23
|
+
xml_accessor :time_activity, from: "TimeActivity", as: Quickbooks::Model::TimeActivity
|
24
|
+
xml_accessor :vendor, from: "Vendor", as: Quickbooks::Model::Vendor
|
25
|
+
|
26
|
+
def fault?
|
27
|
+
fault
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
xml_name "IntuitResponse"
|
32
|
+
xml_accessor :response_items, :from => :BatchItemResponse, as: [Quickbooks::Model::BatchResponse::BatchItemResponse]
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class Bill < BaseModel
|
4
|
+
include GlobalTaxCalculation
|
5
|
+
include HasLineItems
|
6
|
+
|
7
|
+
XML_COLLECTION_NODE = "Bill"
|
8
|
+
XML_NODE = "Bill"
|
9
|
+
REST_RESOURCE = 'bill'
|
10
|
+
|
11
|
+
xml_accessor :id, :from => 'Id'
|
12
|
+
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
|
13
|
+
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
14
|
+
xml_accessor :doc_number, :from => 'DocNumber'
|
15
|
+
xml_accessor :txn_date, :from => 'TxnDate', :as => Date
|
16
|
+
xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
|
17
|
+
|
18
|
+
xml_accessor :line_items, :from => 'Line', :as => [BillLineItem]
|
19
|
+
|
20
|
+
xml_accessor :private_note, :from => 'PrivateNote'
|
21
|
+
|
22
|
+
xml_accessor :vendor_ref, :from => 'VendorRef', :as => BaseReference
|
23
|
+
xml_accessor :payer_ref, :from => 'PayerRef', :as => BaseReference
|
24
|
+
xml_accessor :sales_term_ref, :from => 'SalesTermRef', :as => BaseReference
|
25
|
+
xml_accessor :attachable_ref, :from => 'AttachableRef', :as => BaseReference
|
26
|
+
xml_accessor :ap_account_ref, :from => 'APAccountRef', :as => BaseReference
|
27
|
+
|
28
|
+
xml_accessor :due_date, :from => 'DueDate', :as => Date
|
29
|
+
xml_accessor :remit_to_address, :from => 'RemitToAddr', :as => PhysicalAddress
|
30
|
+
xml_accessor :ship_address, :from => 'ShipAddr', :as => PhysicalAddress
|
31
|
+
xml_accessor :exchange_rate, :from => 'ExchangeRate', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
32
|
+
xml_accessor :balance, :from => 'Balance', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
33
|
+
|
34
|
+
# readonly
|
35
|
+
xml_accessor :bill_email, :from => 'BillEmail', :as => EmailAddress
|
36
|
+
xml_accessor :reply_email, :from => 'ReplyEmail', :as => EmailAddress
|
37
|
+
xml_accessor :total, :from => 'TotalAmt', :as => BigDecimal
|
38
|
+
xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
|
39
|
+
|
40
|
+
validate :line_item_size
|
41
|
+
|
42
|
+
reference_setters :department_ref, :vendor_ref, :payer_ref, :sales_term_ref, :currency_ref, :attachable_ref, :ap_account_ref
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class BillLineItem < BaseModel
|
4
|
+
|
5
|
+
#== Constants
|
6
|
+
ACCOUNT_BASED_EXPENSE_LINE_DETAIL = 'AccountBasedExpenseLineDetail'
|
7
|
+
ITEM_BASED_EXPENSE_LINE_DETAIL = 'ItemBasedExpenseLineDetail'
|
8
|
+
|
9
|
+
xml_accessor :id, :from => 'Id'
|
10
|
+
xml_accessor :line_num, :from => 'LineNum', :as => Integer
|
11
|
+
xml_accessor :description, :from => 'Description'
|
12
|
+
xml_accessor :amount, :from => 'Amount', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
13
|
+
xml_accessor :detail_type, :from => 'DetailType'
|
14
|
+
|
15
|
+
#== Various detail types
|
16
|
+
xml_accessor :account_based_expense_line_detail, :from => 'AccountBasedExpenseLineDetail', :as => AccountBasedExpenseLineDetail
|
17
|
+
xml_accessor :item_based_expense_line_detail, :from => 'ItemBasedExpenseLineDetail', :as => ItemBasedExpenseLineDetail
|
18
|
+
|
19
|
+
def account_based_expense_item?
|
20
|
+
detail_type.to_s == ACCOUNT_BASED_EXPENSE_LINE_DETAIL
|
21
|
+
end
|
22
|
+
|
23
|
+
def item_based_expense_item?
|
24
|
+
detail_type.to_s == ITEM_BASED_EXPENSE_LINE_DETAIL
|
25
|
+
end
|
26
|
+
|
27
|
+
def account_based_expense_item!
|
28
|
+
self.detail_type = ACCOUNT_BASED_EXPENSE_LINE_DETAIL
|
29
|
+
self.account_based_expense_line_detail = AccountBasedExpenseLineDetail.new
|
30
|
+
|
31
|
+
yield self.account_based_expense_line_detail if block_given?
|
32
|
+
end
|
33
|
+
|
34
|
+
def item_based_expense_item!
|
35
|
+
self.detail_type = ITEM_BASED_EXPENSE_LINE_DETAIL
|
36
|
+
self.item_based_expense_line_detail = ItemBasedExpenseLineDetail.new
|
37
|
+
|
38
|
+
yield self.item_based_expense_line_detail if block_given?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class BillPayment < BaseModel
|
4
|
+
include HasLineItems
|
5
|
+
|
6
|
+
XML_COLLECTION_NODE = "BillPayment"
|
7
|
+
XML_NODE = "BillPayment"
|
8
|
+
REST_RESOURCE = 'billpayment'
|
9
|
+
|
10
|
+
xml_accessor :id, :from => 'Id'
|
11
|
+
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
|
12
|
+
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
13
|
+
xml_accessor :doc_number, :from => 'DocNumber'
|
14
|
+
xml_accessor :txn_date, :from => 'TxnDate', :as => Date
|
15
|
+
|
16
|
+
xml_accessor :line_items, :from => 'Line', :as => [BillPaymentLineItem]
|
17
|
+
|
18
|
+
xml_accessor :private_note, :from => 'PrivateNote'
|
19
|
+
|
20
|
+
xml_accessor :vendor_ref, :from => 'VendorRef', :as => BaseReference
|
21
|
+
xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
|
22
|
+
xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
|
23
|
+
xml_accessor :exchange_rate, :from => 'ExchangeRate', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
24
|
+
xml_accessor :ap_account_ref, :from => 'APAccountRef', :as => BaseReference
|
25
|
+
xml_accessor :pay_type, :from => 'PayType'
|
26
|
+
xml_accessor :process_bill_payment?, :from => 'ProcessBillPayment'
|
27
|
+
|
28
|
+
## Required if PayType is Check.
|
29
|
+
xml_accessor :check_payment, :from => 'CheckPayment', :as => BillPaymentCheck
|
30
|
+
## Required if PayType is CreditCard.
|
31
|
+
xml_accessor :credit_card_payment, :from => 'CreditCardPayment', :as => BillPaymentCreditCard
|
32
|
+
|
33
|
+
xml_accessor :total, :from => 'TotalAmt', :as => BigDecimal
|
34
|
+
|
35
|
+
validate :line_item_size
|
36
|
+
|
37
|
+
reference_setters
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class BillPaymentCheck < BaseModel
|
4
|
+
xml_accessor :bank_account_ref, :from => 'BankAccountRef', :as => BaseReference
|
5
|
+
xml_accessor :print_status, :from => 'PrintStatus'
|
6
|
+
xml_accessor :check_detail, :from => 'CheckDetail', :as => CheckPayment
|
7
|
+
xml_accessor :payee_address, :from => 'PayeeAddr', :as => PhysicalAddress
|
8
|
+
|
9
|
+
reference_setters :bank_account_ref
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class BillPaymentCreditCard < BaseModel
|
4
|
+
xml_accessor :cc_account_ref, :from => 'CCAccountRef', :as => BaseReference
|
5
|
+
xml_accessor :cc_detail, :from => 'CCDetail', :as => CreditCardPayment
|
6
|
+
|
7
|
+
reference_setters
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|