quickbooks-ruby 0.0.5 → 0.0.6

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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/lib/quickbooks-ruby.rb +33 -6
  3. data/lib/quickbooks/model/account.rb +2 -0
  4. data/lib/quickbooks/model/base_model.rb +21 -1
  5. data/lib/quickbooks/model/base_reference.rb +1 -1
  6. data/lib/quickbooks/model/estimate.rb +77 -0
  7. data/lib/quickbooks/model/group_line_detail.rb +11 -0
  8. data/lib/quickbooks/model/item_based_expense_line_detail.rb +18 -0
  9. data/lib/quickbooks/model/markup_info.rb +12 -0
  10. data/lib/quickbooks/model/payment.rb +41 -0
  11. data/lib/quickbooks/model/purchase.rb +43 -0
  12. data/lib/quickbooks/model/purchase_line_item.rb +22 -0
  13. data/lib/quickbooks/model/purchase_order.rb +39 -0
  14. data/lib/quickbooks/model/sales_item_line_detail.rb +1 -1
  15. data/lib/quickbooks/model/tax_line.rb +15 -0
  16. data/lib/quickbooks/model/tax_line_detail.rb +16 -0
  17. data/lib/quickbooks/model/term.rb +28 -0
  18. data/lib/quickbooks/model/transaction_tax_detail.rb +11 -0
  19. data/lib/quickbooks/model/vendor_credit.rb +31 -0
  20. data/lib/quickbooks/service/base_service.rb +13 -29
  21. data/lib/quickbooks/service/customer.rb +1 -1
  22. data/lib/quickbooks/service/employee.rb +1 -1
  23. data/lib/quickbooks/service/estimate.rb +21 -0
  24. data/lib/quickbooks/service/payment.rb +21 -0
  25. data/lib/quickbooks/service/purchase.rb +15 -0
  26. data/lib/quickbooks/service/purchase_order.rb +15 -0
  27. data/lib/quickbooks/service/service_crud.rb +2 -2
  28. data/lib/quickbooks/service/term.rb +22 -0
  29. data/lib/quickbooks/service/vendor_credit.rb +15 -0
  30. data/lib/quickbooks/version.rb +1 -1
  31. metadata +29 -5
  32. data/lib/quickbooks/util/class_util.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f4883102897a891ec4461cf30ea0e193aeae3e0
4
- data.tar.gz: 060b71166e7cf0c1d44c9fef3f6f6d776863cdb5
3
+ metadata.gz: 91bc61de465110193b80e334f32e2a38f1d5a80b
4
+ data.tar.gz: 6122789bac338be996e22c7a2784b916706eb943
5
5
  SHA512:
6
- metadata.gz: f563e31ee5eb5614a823409262cc380876c8f3f61527eac6c4110ae1514d49aba5d1ee09b20ca58064d52db0bb39c6a4f3659fd8f4240d83dcc97e0bc992ec3f
7
- data.tar.gz: e710072fff70fad89c32496dddc544945e51fc4c26c7de0f151d656a96763567e0cb8825ebe2e47c0b238a924a65bb9815ae71957d78802b2ec4bdd811af4c2f
6
+ metadata.gz: f1032fc7945938f63b2623173dc4705f202123bf03a01bfb00c51080ded6dd5cabc28e5f9a9f67177afdef6a8a50bfa64709e2c96a54e40b6bf1bde5acb13cee
7
+ data.tar.gz: ba63a3754f73dca065d8909bfc5ccb81ab924bd53a0efb515584cf34a23997a6f401387d7352061108d73b4a763ded6a46cfef6f21bc71b53a6cec94657c0ea3
@@ -1,14 +1,13 @@
1
1
  require 'roxml'
2
2
  require 'logger'
3
3
  require 'nokogiri'
4
- require 'logger'
5
4
  require 'active_model'
6
5
  require 'cgi'
6
+ require 'uri'
7
7
  require 'date'
8
8
  require 'forwardable'
9
9
  require 'oauth'
10
10
  require 'quickbooks/util/logging'
11
- require 'quickbooks/util/class_util'
12
11
  require 'quickbooks/util/http_encoding_helper'
13
12
  require 'quickbooks/util/name_entity'
14
13
 
@@ -38,6 +37,7 @@ require 'quickbooks/model/invoice'
38
37
  require 'quickbooks/model/company_info'
39
38
  require 'quickbooks/model/customer'
40
39
  require 'quickbooks/model/sales_receipt'
40
+ require 'quickbooks/model/payment'
41
41
  require 'quickbooks/model/payment_method'
42
42
  require 'quickbooks/model/credit_memo'
43
43
  require 'quickbooks/model/bill_line_item'
@@ -48,6 +48,18 @@ require 'quickbooks/model/bill_payment_credit_card'
48
48
  require 'quickbooks/model/bill_payment'
49
49
  require 'quickbooks/model/vendor'
50
50
  require 'quickbooks/model/employee'
51
+ require 'quickbooks/model/term'
52
+ require 'quickbooks/model/markup_info'
53
+ require 'quickbooks/model/group_line_detail'
54
+ require 'quickbooks/model/item_based_expense_line_detail'
55
+ require 'quickbooks/model/tax_line_detail'
56
+ require 'quickbooks/model/tax_line'
57
+ require 'quickbooks/model/transaction_tax_detail'
58
+ require 'quickbooks/model/purchase_line_item'
59
+ require 'quickbooks/model/purchase'
60
+ require 'quickbooks/model/purchase_order'
61
+ require 'quickbooks/model/vendor_credit'
62
+ require 'quickbooks/model/estimate'
51
63
 
52
64
  #== Services
53
65
  require 'quickbooks/service/base_service'
@@ -64,10 +76,12 @@ require 'quickbooks/service/bill'
64
76
  require 'quickbooks/service/bill_payment'
65
77
  require 'quickbooks/service/vendor'
66
78
  require 'quickbooks/service/employee'
67
-
68
- unless Quickbooks::Util::ClassUtil.defined?("InvalidModelException")
69
- class InvalidModelException < StandardError; end
70
- end
79
+ require 'quickbooks/service/payment'
80
+ require 'quickbooks/service/term'
81
+ require 'quickbooks/service/purchase'
82
+ require 'quickbooks/service/purchase_order'
83
+ require 'quickbooks/service/vendor_credit'
84
+ require 'quickbooks/service/estimate'
71
85
 
72
86
  module Quickbooks
73
87
  @@logger = nil
@@ -97,6 +111,19 @@ module Quickbooks
97
111
  end
98
112
  end # << self
99
113
 
114
+ class InvalidModelException < StandardError; end
115
+
116
+ class AuthorizationFailure < StandardError; end
117
+
118
+ class IntuitRequestException < StandardError
119
+ attr_accessor :message, :code, :detail, :type
120
+ def initialize(msg)
121
+ self.message = msg
122
+ super(msg)
123
+ end
124
+ end
125
+
126
+
100
127
  class Collection
101
128
  attr_accessor :entries
102
129
 
@@ -34,6 +34,8 @@ module Quickbooks
34
34
  xml_accessor :acct_num, :from => 'AcctNum'
35
35
  xml_accessor :bank_num, :from => 'BankNum'
36
36
 
37
+ xml_accessor :current_balance, :from => 'CurrentBalance', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
38
+ xml_accessor :current_balance_with_sub_accounts, :from => 'CurrentBalanceWithSubAccounts', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
37
39
  xml_accessor :opening_balance, :from => 'OpeningBalance', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
38
40
  xml_accessor :opening_balance_date, :from => 'OpeningBalanceDate', :as => DateTime
39
41
  xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
@@ -3,8 +3,13 @@ module Quickbooks
3
3
  class BaseModel
4
4
  include ActiveModel::Validations
5
5
  include ROXML
6
+
6
7
  xml_convention :camelcase
7
8
 
9
+ def initialize(attributes={})
10
+ attributes.each {|key, value| public_send("#{key}=", value) }
11
+ end
12
+
8
13
  # ROXML doesnt insert the namespaces into generated XML so we need to do it ourselves
9
14
  # insert the static namespaces in the first opening tag that matches the +model_name+
10
15
  def to_xml_inject_ns(model_name, options = {})
@@ -24,7 +29,22 @@ module Quickbooks
24
29
  to_xml_inject_ns(self.class::XML_NODE, options)
25
30
  end
26
31
 
32
+ delegate :[], :fetch, :to => :attributes
33
+
34
+ def attributes
35
+ attributes = self.class.attribute_names.map do |name|
36
+ value = public_send(name)
37
+ value = value.attributes if value.respond_to?(:attributes)
38
+ [name, value]
39
+ end
40
+
41
+ HashWithIndifferentAccess[attributes]
42
+ end
43
+
27
44
  class << self
45
+ def attribute_names
46
+ roxml_attrs.map(&:accessor)
47
+ end
28
48
 
29
49
  # These can be over-ridden in each model object as needed
30
50
  def resource_for_collection
@@ -59,4 +79,4 @@ module Quickbooks
59
79
  end
60
80
  end
61
81
  end
62
- end
82
+ end
@@ -18,4 +18,4 @@ module Quickbooks
18
18
  end
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -0,0 +1,77 @@
1
+ # == Business Rules
2
+ # The Estimate object has the following business rules and validations:
3
+ # * An Estimate must have at least one line that describes an item.
4
+ # * An Estimate must have a reference to a customer.
5
+ # * If shipping address and billing address are not provided, the customer address is used to fill those values.
6
+ # * For US country, CustomSalesTax cannot be used as TaxCodeRef.
7
+
8
+ module Quickbooks
9
+ module Model
10
+ class Estimate < BaseModel
11
+
12
+ #== Constants
13
+ REST_RESOURCE = 'estimate'
14
+ XML_COLLECTION_NODE = "Estimate"
15
+ XML_NODE = "Estimate"
16
+
17
+ xml_accessor :id, :from => 'Id', :as => Integer
18
+ xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
19
+ xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
20
+ xml_accessor :custom_fields, :from => 'CustomField', :as => [CustomField]
21
+ xml_accessor :doc_number, :from => 'DocNumber'
22
+ xml_accessor :txn_date, :from => 'TxnDate', :as => Date
23
+ xml_accessor :private_note, :from => 'PrivateNote'
24
+
25
+ xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
26
+ xml_accessor :linked_transactions, :from => 'LinkedTxn', :as => [LinkedTransaction]
27
+ xml_accessor :line_items, :from => 'Line', :as => [InvoiceLineItem]
28
+ xml_accessor :txn_tax_detail, :from => 'TxnTaxDetail'
29
+ xml_accessor :txn_status, :from => 'TxnStatus'
30
+
31
+ xml_accessor :customer_ref, :from => 'CustomerRef', :as => BaseReference
32
+ xml_accessor :customer_memo, :from => 'CustomerMemo'
33
+ xml_accessor :billing_address, :from => 'BillAddr', :as => PhysicalAddress
34
+ xml_accessor :shipping_address, :from => 'ShipAddr', :as => PhysicalAddress
35
+ xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
36
+ xml_accessor :sales_term_ref, :from => 'SalesTermRef', :as => BaseReference
37
+ xml_accessor :total_amount, :from => 'TotalAmt', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
38
+ xml_accessor :ship_method_ref, :from => 'ShipMethodRef', :as => BaseReference
39
+ xml_accessor :ship_date, :from => 'ShipDate', :as => Date
40
+
41
+ xml_accessor :apply_tax_after_discount, :from => 'ApplyTaxAfterDiscount'
42
+ xml_accessor :print_status, :from => 'PrintStatus'
43
+ xml_accessor :email_status, :from => 'EmailStatus'
44
+ xml_accessor :bill_email, :from => 'BillEmail', :as => EmailAddress
45
+ xml_accessor :expiration_date, :from => 'ExpirationDate', :as => Date
46
+ xml_accessor :accepted_by, :from => 'AcceptedBy'
47
+ xml_accessor :accepted_date, :from => 'AcceptedDate', :as => Date
48
+
49
+ reference_setters :department_ref, :customer_ref, :class_ref, :sales_term_ref, :ship_method_ref
50
+
51
+ #== Validations
52
+ validates_length_of :line_items, :minimum => 1
53
+ validate :existence_of_customer_ref
54
+
55
+ def initialize
56
+ ensure_line_items_initialization
57
+ super
58
+ end
59
+
60
+ def apply_tax_after_discount?
61
+ apply_tax_after_discount.to_s == 'true'
62
+ end
63
+
64
+ private
65
+
66
+ def existence_of_customer_ref
67
+ if customer_ref.nil? || (customer_ref && customer_ref.value == 0)
68
+ errors.add(:customer_ref, "CustomerRef is required and must be a non-zero value.")
69
+ end
70
+ end
71
+
72
+ def ensure_line_items_initialization
73
+ self.line_items ||= []
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,11 @@
1
+ module Quickbooks
2
+ module Model
3
+ class GroupLineDetail < BaseModel
4
+ xml_accessor :group_item_ref, :from => 'CustomerRef', :as => BaseReference
5
+ xml_accessor :quantity, :from => 'Quantity', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
6
+ xml_accessor :line_items, :from => 'Line', :as => [Line]
7
+
8
+ reference_setters :group_item_ref
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Quickbooks
2
+ module Model
3
+ class ItemBasedExpenseLineDetail < BaseModel
4
+ xml_accessor :item_ref, :from => 'ItemRef', :as => BaseReference
5
+ xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
6
+ xml_accessor :unit_price, :from => 'UnitPrice', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
7
+ xml_accessor :rate_percent, :from => 'RatePercent', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
8
+ xml_accessor :price_level_ref, :from => 'PriceLevelRef', :as => BaseReference
9
+ xml_accessor :markup_info, :from => 'MarkupInfo', :as => MarkupInfo
10
+ xml_accessor :quantity, :from => 'Qty', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
11
+ xml_accessor :tax_code_ref, :from => 'TaxCodeRef', :as => BaseReference
12
+ xml_accessor :customer_ref, :from => 'CustomerRef', :as => BaseReference
13
+ xml_accessor :billable_status, :from => 'BillableStatus'
14
+
15
+ reference_setters :item_ref, :class_ref, :price_level_ref, :customer_ref, :tax_code_ref
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module Quickbooks
2
+ module Model
3
+ class MarkupInfo < BaseModel
4
+ xml_accessor :percent_based, :from => 'PercentBased'
5
+ xml_accessor :value, :from => 'Value', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
6
+ xml_accessor :percent, :from => 'Percent', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
7
+ xml_accessor :price_level_ref, :from => 'PriceLevelRef', :as => BaseReference
8
+
9
+ reference_setters :price_level_ref
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ module Quickbooks
2
+ module Model
3
+ class Payment < BaseModel
4
+ XML_COLLECTION_NODE = "Payment"
5
+ XML_NODE = "Payment"
6
+ REST_RESOURCE = 'payment'
7
+
8
+ xml_accessor :id, :from => 'Id', :as => Integer
9
+ xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
10
+ xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
11
+ xml_accessor :txn_date, :from => 'TxnDate', :as => Date
12
+ xml_accessor :private_note, :from => 'PrivateNote'
13
+ xml_accessor :txn_status, :from => 'TxnStatus'
14
+ xml_accessor :line, :from => 'Line', :as => Line
15
+ xml_accessor :customer_ref, :from => 'CustomerRef', :as => BaseReference
16
+ xml_accessor :ar_account_ref, :from => 'ARAccountRef', :as => BaseReference
17
+ xml_accessor :deposit_to_account_ref, :from => 'DepositToAccountRef', :as => BaseReference
18
+ xml_accessor :payment_method_ref, :from => 'PaymentMethodRef', :as => BaseReference
19
+ xml_accessor :payment_method_number, :from => 'PaymentMethodNum'
20
+ xml_accessor :credit_card_payment, :from => 'CreditCardPayment', :as => CreditCardPayment
21
+ xml_accessor :total, :from => 'TotalAmt', :as => BigDecimal, :to_xml => :to_f.to_proc
22
+ xml_accessor :unapplied_amount, :from => 'UnappliedAmt', :as => BigDecimal, :to_xml => :to_f.to_proc
23
+ xml_accessor :process_payment, :from => 'ProcessPayment'
24
+ xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
25
+ xml_accessor :exchange_rate, :from => 'ExchangeRate', :as => BigDecimal, :to_xml => :to_f.to_proc
26
+
27
+ reference_setters :customer_ref
28
+ reference_setters :payment_method_ref
29
+
30
+ validate :existence_of_customer_ref
31
+
32
+ private
33
+
34
+ def existence_of_customer_ref
35
+ if customer_ref.nil? || (customer_ref && customer_ref.value == 0)
36
+ errors.add(:customer_ref, "CustomerRef is required and must be a non-zero value.")
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,43 @@
1
+ # == General
2
+ # This entity represents expenses, such as a purchase made from a vendor.
3
+ # There are three types of Purchases: Cash, Check, and Credit Card.
4
+ # * Cash Purchase contains information regarding a payment made in cash.
5
+ # * Check Purchase contains information regarding a payment made by check.
6
+ # * Credit Card Purchase contains information regarding a payment made by credit card.
7
+ #
8
+ # == Business Rules
9
+ # * You must specify an AccountRef for all puchases.
10
+ # * TotalAmt attribute must add up to sum of Line.Amount attributes
11
+
12
+ module Quickbooks
13
+ module Model
14
+ class Purchase < BaseModel
15
+
16
+ #== Constants
17
+ REST_RESOURCE = 'purchase'
18
+ XML_COLLECTION_NODE = "Purchase"
19
+ XML_NODE = "Purchase"
20
+
21
+ xml_accessor :id, :from => 'Id', :as => Integer
22
+ xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
23
+ xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
24
+ xml_accessor :doc_number, :from => 'DocNumber'
25
+ xml_accessor :txn_date, :from => 'TxnDate', :as => Date
26
+ xml_accessor :private_note, :from => 'PrivateNote'
27
+
28
+ xml_accessor :line_items, :from => 'Line', :as => [PurchaseLineItem]
29
+ xml_accessor :account_ref, :from => 'AccountRef', :as => BaseReference
30
+ xml_accessor :txn_tax_detail, :from => 'TxnTaxDetail', :as => TransactionTaxDetail
31
+
32
+ xml_accessor :payment_type, :from => 'PaymentType'
33
+ xml_accessor :entity_ref, :from => 'EntityRef', :as => BaseReference
34
+ xml_accessor :remit_to_address, :from => 'RemitToAddr', :as => PhysicalAddress
35
+ xml_accessor :total_amount, :from => 'TotalAmt', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
36
+ xml_accessor :print_status, :from => 'PrintStatus'
37
+ xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
38
+
39
+ reference_setters :account_ref, :entity_ref, :department_ref
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ module Quickbooks
2
+ module Model
3
+ class PurchaseLineItem < BaseModel
4
+
5
+ #== Constants
6
+ ITEM_BASED_EXPENSE_LINE_DETAIL = 'ItemBasedExpenseLineDetail'
7
+ GROUP_LINE_DETAIL = 'GroupLineDetail'
8
+
9
+ xml_accessor :id, :from => 'Id', :as => Integer
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 => Proc.new { |val| val.to_f }
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 => ITEM_BASED_EXPENSE_LINE_DETAIL, :as => ItemBasedExpenseLineDetail
18
+ xml_accessor :group_line_detail, :from => GROUP_LINE_DETAIL, :as => GroupLineDetail
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ module Quickbooks
2
+ module Model
3
+ class PurchaseOrder < BaseModel
4
+
5
+ #== Constants
6
+ REST_RESOURCE = 'purchase_order'
7
+ XML_COLLECTION_NODE = "PurchaseOrder"
8
+ XML_NODE = "PurchaseOrder"
9
+
10
+ xml_accessor :id, :from => 'Id', :as => Integer
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
+ xml_accessor :custom_fields, :from => 'CustomField', :as => [CustomField]
16
+ xml_accessor :private_note, :from => 'PrivateNote'
17
+
18
+ xml_accessor :linked_transactions, :from => 'LinkedTxn', :as => [LinkedTransaction]
19
+ xml_accessor :line_items, :from => 'Line', :as => [PurchaseLineItem]
20
+
21
+ xml_accessor :attachable_ref, :from => 'AttachableRef', :as => BaseReference
22
+ xml_accessor :vendor_ref, :from => 'VendorRef', :as => BaseReference
23
+ xml_accessor :ap_account_ref, :from => 'APAccountRef', :as => BaseReference
24
+ xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
25
+ xml_accessor :sales_term_ref, :from => 'SalesTermRef', :as => BaseReference
26
+
27
+ xml_accessor :total_amount, :from => 'TotalAmt', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
28
+ xml_accessor :due_date, :from => 'DueDate', :as => Date
29
+ xml_accessor :vendor_address, :from => 'VendorAddr', :as => PhysicalAddress
30
+ xml_accessor :ship_address, :from => 'ShipAddr', :as => PhysicalAddress
31
+ xml_accessor :ship_method_ref, :from => 'ShipMethodRef', :as => BaseReference
32
+ xml_accessor :po_status, :from => 'POStatus'
33
+ xml_accessor :txn_tax_detail, :from => 'TxnTaxDetail', :as => TransactionTaxDetail
34
+
35
+ reference_setters :attachable_ref, :vendor_ref, :ap_account_ref, :class_ref, :sales_term_ref, :ship_method_ref
36
+
37
+ end
38
+ end
39
+ end
@@ -13,4 +13,4 @@ module Quickbooks
13
13
  reference_setters :item_ref, :class_ref, :price_level_ref, :tax_code_ref
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -0,0 +1,15 @@
1
+ module Quickbooks
2
+ module Model
3
+ class TaxLine < BaseModel
4
+
5
+ xml_accessor :id, :from => 'Id', :as => Integer
6
+ xml_accessor :line_num, :from => 'LineNum', :as => Integer
7
+ xml_accessor :description, :from => 'Description'
8
+ xml_accessor :amount, :from => 'Amount', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
9
+ xml_accessor :detail_type, :from => 'DetailType'
10
+
11
+ xml_accessor :tax_line_detail, :from => 'TaxLineDetail', :as => TaxLineDetail
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Quickbooks
2
+ module Model
3
+ class TaxLineDetail < BaseModel
4
+
5
+ xml_accessor :percent_based, :from => 'PercentBased'
6
+ xml_accessor :net_amount_taxable, :from => 'NetAmountTaxable', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
7
+ xml_accessor :tax_inclusive_amount, :from => 'TaxInclusiveAmount', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
8
+ xml_accessor :override_delta_amount, :from => 'OverrideDeltaAmount', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
9
+ xml_accessor :tax_percent, :from => 'TaxPercent', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
10
+ xml_accessor :tax_rate_ref, :from => 'TaxRateRef', :as => BaseReference
11
+
12
+ reference_setters :tax_rate_ref
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ module Quickbooks
2
+ module Model
3
+ class Term < BaseModel
4
+ XML_COLLECTION_NODE = "Term"
5
+ XML_NODE = "Term"
6
+ REST_RESOURCE = 'term'
7
+
8
+ xml_accessor :id, :from => 'Id', :as => Integer
9
+ xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
10
+ xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
11
+ xml_accessor :name, :from => 'Name'
12
+ xml_accessor :active, :from => 'Active'
13
+ xml_accessor :type, :from => 'Type'
14
+ xml_accessor :discount_percent, :from => 'DiscountPercent', :as => BigDecimal
15
+ xml_accessor :due_days, :from => 'DueDays', :as => Integer
16
+ xml_accessor :discount_days, :from => 'DiscountDays', :as => Integer
17
+ xml_accessor :day_of_month_due, :from => 'DayOfMonthDue', :as => Integer
18
+ xml_accessor :due_next_month_days, :from => 'DueNextMonthDays', :as => Integer
19
+ xml_accessor :discount_day_of_month, :from => 'DiscountDayOfMonth', :as => Integer
20
+
21
+ validates_presence_of :name
22
+
23
+ def active?
24
+ active == "true"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ module Quickbooks
2
+ module Model
3
+ class TransactionTaxDetail < BaseModel
4
+
5
+ xml_accessor :txn_tax_code_ref, :from => 'TxnTaxCodeRef', :as => BaseReference
6
+ xml_accessor :total_tax, :from => 'Amount', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
7
+ xml_accessor :lines, :from => 'TaxLine', :as => [TaxLine]
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ # === Business Rules
2
+ # * The VendorRef attribute must be specified.
3
+ # * At lease one Line with Line.Amount must be specified.
4
+
5
+ module Quickbooks
6
+ module Model
7
+ class VendorCredit < BaseModel
8
+
9
+ #== Constants
10
+ REST_RESOURCE = 'vendor_credit'
11
+ XML_COLLECTION_NODE = "VendorCredit"
12
+ XML_NODE = "VendorCredit"
13
+
14
+ xml_accessor :id, :from => 'Id', :as => Integer
15
+ xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
16
+ xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
17
+ xml_accessor :doc_number, :from => 'DocNumber'
18
+ xml_accessor :txn_date, :from => 'TxnDate', :as => Date
19
+ xml_accessor :private_note, :from => 'PrivateNote'
20
+
21
+ xml_accessor :line_items, :from => 'Line', :as => [PurchaseLineItem]
22
+ xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
23
+ xml_accessor :ap_account_ref, :from => 'APAccountRef', :as => BaseReference
24
+ xml_accessor :vendor_ref, :from => 'VendorRef', :as => BaseReference
25
+ xml_accessor :total_amount, :from => 'TotalAmt', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
26
+
27
+ reference_setters :department_ref, :ap_account_ref, :vendor_ref
28
+
29
+ end
30
+ end
31
+ end
@@ -1,21 +1,3 @@
1
- #require 'rexml/document'
2
- require 'uri'
3
- require 'cgi'
4
-
5
- unless Quickbooks::Util::ClassUtil.defined?("InvalidModelException")
6
- class IntuitRequestException < StandardError
7
- attr_accessor :message, :code, :detail, :type
8
- def initialize(msg)
9
- self.message = msg
10
- super(msg)
11
- end
12
- end
13
- end
14
-
15
- unless Quickbooks::Util::ClassUtil.defined?("InvalidModelException")
16
- class AuthorizationFailure < StandardError; end
17
- end
18
-
19
1
  module Quickbooks
20
2
  module Service
21
3
  class BaseService
@@ -134,8 +116,7 @@ module Quickbooks
134
116
  end
135
117
  collection.entries = results
136
118
  rescue => ex
137
- #log("Error parsing XML: #{ex.message}")
138
- raise IntuitRequestException.new("Error parsing XML: #{ex.message}")
119
+ raise Quickbooks::IntuitRequestException.new("Error parsing XML: #{ex.message}")
139
120
  end
140
121
  collection
141
122
  else
@@ -181,9 +162,9 @@ module Quickbooks
181
162
  when 200
182
163
  result = Quickbooks::Model::RestResponse.from_xml(response.plain_body)
183
164
  when 401
184
- raise IntuitRequestException.new("Authorization failure: token timed out?")
165
+ raise Quickbooks::IntuitRequestException.new("Authorization failure: token timed out?")
185
166
  when 404
186
- raise IntuitRequestException.new("Resource Not Found: Check URL and try again")
167
+ raise Quickbooks::IntuitRequestException.new("Resource Not Found: Check URL and try again")
187
168
  end
188
169
  end
189
170
  result
@@ -212,10 +193,11 @@ module Quickbooks
212
193
  headers['Accept-Encoding'] = HTTP_ACCEPT_ENCODING
213
194
  end
214
195
 
215
- #log "METHOD = #{method}"
216
- #log "RESOURCE = #{url}"
217
- #log "BODY(#{body.class}) = #{body == nil ? "<NIL>" : body.inspect}"
218
- #log "HEADERS = #{headers.inspect}"
196
+ log "------ New Request ------"
197
+ log "METHOD = #{method}"
198
+ log "RESOURCE = #{url}"
199
+ log "BODY(#{body.class}) = #{body == nil ? "<NIL>" : body.inspect}"
200
+ log "HEADERS = #{headers.inspect}"
219
201
 
220
202
  response = case method
221
203
  when :get
@@ -223,7 +205,7 @@ module Quickbooks
223
205
  when :post
224
206
  @oauth.post(url, body, headers)
225
207
  else
226
- raise "Dont know how to perform that HTTP operation"
208
+ raise "Do not know how to perform that HTTP operation"
227
209
  end
228
210
  check_response(response)
229
211
  end
@@ -237,6 +219,8 @@ module Quickbooks
237
219
  end
238
220
 
239
221
  def check_response(response)
222
+ log "RESPONSE CODE = #{response.code}"
223
+ log "RESPONSE BODY = #{response.plain_body}"
240
224
  parse_xml(response.plain_body)
241
225
  status = response.code.to_i
242
226
  case status
@@ -250,7 +234,7 @@ module Quickbooks
250
234
  when 302
251
235
  raise "Unhandled HTTP Redirect"
252
236
  when 401
253
- raise AuthorizationFailure
237
+ raise Quickbooks::AuthorizationFailure
254
238
  when 400, 500
255
239
  parse_and_raise_exception
256
240
  else
@@ -260,7 +244,7 @@ module Quickbooks
260
244
 
261
245
  def parse_and_raise_exception
262
246
  err = parse_intuit_error
263
- ex = IntuitRequestException.new("#{err[:message]}:\n\t#{err[:detail]}")
247
+ ex = Quickbooks::IntuitRequestException.new("#{err[:message]}:\n\t#{err[:detail]}")
264
248
  ex.code = err[:code]
265
249
  ex.detail = err[:detail]
266
250
  ex.type = err[:type]
@@ -20,4 +20,4 @@ module Quickbooks
20
20
 
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -5,7 +5,7 @@ module Quickbooks
5
5
 
6
6
  # override update as sparse is not supported
7
7
  def update(entity, options = {})
8
- raise InvalidModelException.new('Employee sparse update is not supported by Intuit at this time') if options[:sparse] && options[:sparse] == true
8
+ raise Quickbooks::InvalidModelException.new('Employee sparse update is not supported by Intuit at this time') if options[:sparse] && options[:sparse] == true
9
9
  super(entity, options)
10
10
  end
11
11
 
@@ -0,0 +1,21 @@
1
+ module Quickbooks
2
+ module Service
3
+ class Estimate < BaseService
4
+ include ServiceCrud
5
+
6
+ def delete(estimate, options = {})
7
+ delete_by_query_string(estimate)
8
+ end
9
+
10
+ private
11
+
12
+ def default_model_query
13
+ "SELECT * FROM Estimate"
14
+ end
15
+
16
+ def model
17
+ Quickbooks::Model::Estimate
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Quickbooks
2
+ module Service
3
+ class Payment < BaseService
4
+ include ServiceCrud
5
+
6
+ def delete(payment)
7
+ delete_by_query_string(payment)
8
+ end
9
+
10
+ private
11
+
12
+ def default_model_query
13
+ "SELECT * FROM Payment"
14
+ end
15
+
16
+ def model
17
+ Quickbooks::Model::Payment
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module Quickbooks
2
+ module Service
3
+ class Purchase < BaseService
4
+ include ServiceCrud
5
+
6
+ def default_model_query
7
+ "SELECT * FROM Purchase"
8
+ end
9
+
10
+ def model
11
+ Quickbooks::Model::Purchase
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Quickbooks
2
+ module Service
3
+ class PurchaseOrder < BaseService
4
+ include ServiceCrud
5
+
6
+ def default_model_query
7
+ "SELECT * FROM PurchaseOrder"
8
+ end
9
+
10
+ def model
11
+ Quickbooks::Model::PurchaseOrder
12
+ end
13
+ end
14
+ end
15
+ end
@@ -12,7 +12,7 @@ module Quickbooks
12
12
  end
13
13
 
14
14
  def create(entity, options = {})
15
- raise InvalidModelException.new(entity.errors.full_messages.join(',')) unless entity.valid?
15
+ raise Quickbooks::InvalidModelException.new(entity.errors.full_messages.join(',')) unless entity.valid?
16
16
  xml = entity.to_xml_ns(options)
17
17
  response = do_http_post(url_for_resource(model.resource_for_singular), valid_xml_document(xml))
18
18
  if response.code.to_i == 200
@@ -40,7 +40,7 @@ module Quickbooks
40
40
 
41
41
  def update(entity, options = {})
42
42
  unless entity.valid?
43
- raise InvalidModelException.new(entity.errors.full_messages.join(','))
43
+ raise Quickbooks::InvalidModelException.new(entity.errors.full_messages.join(','))
44
44
  end
45
45
 
46
46
  xml = entity.to_xml_ns(options)
@@ -0,0 +1,22 @@
1
+ module Quickbooks
2
+ module Service
3
+ class Term < BaseService
4
+ include ServiceCrud
5
+
6
+ def delete(term)
7
+ term.active = false
8
+ update(term, :sparse => true)
9
+ end
10
+
11
+ private
12
+
13
+ def default_model_query
14
+ "SELECT * FROM Term"
15
+ end
16
+
17
+ def model
18
+ Quickbooks::Model::Term
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module Quickbooks
2
+ module Service
3
+ class VendorCredit < BaseService
4
+ include ServiceCrud
5
+
6
+ def default_model_query
7
+ "SELECT * FROM VendorCredit"
8
+ end
9
+
10
+ def model
11
+ Quickbooks::Model::VendorCredit
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  module Quickbooks
2
2
 
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
 
5
5
  end
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.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Caughlan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-24 00:00:00.000000000 Z
11
+ date: 2014-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
@@ -44,14 +44,20 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 1.5.9
47
+ version: '1.6'
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: 1.6.1
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
55
  - - ~>
53
56
  - !ruby/object:Gem::Version
54
- version: 1.5.9
57
+ version: '1.6'
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 1.6.1
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: activemodel
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -189,21 +195,34 @@ files:
189
195
  - lib/quickbooks/model/discount_override.rb
190
196
  - lib/quickbooks/model/email_address.rb
191
197
  - lib/quickbooks/model/employee.rb
198
+ - lib/quickbooks/model/estimate.rb
199
+ - lib/quickbooks/model/group_line_detail.rb
192
200
  - lib/quickbooks/model/invoice.rb
193
201
  - lib/quickbooks/model/invoice_line_item.rb
194
202
  - lib/quickbooks/model/item.rb
203
+ - lib/quickbooks/model/item_based_expense_line_detail.rb
195
204
  - lib/quickbooks/model/line.rb
196
205
  - lib/quickbooks/model/linked_transaction.rb
206
+ - lib/quickbooks/model/markup_info.rb
197
207
  - lib/quickbooks/model/meta_data.rb
198
208
  - lib/quickbooks/model/other_contact_info.rb
209
+ - lib/quickbooks/model/payment.rb
199
210
  - lib/quickbooks/model/payment_line_detail.rb
200
211
  - lib/quickbooks/model/payment_method.rb
201
212
  - lib/quickbooks/model/physical_address.rb
213
+ - lib/quickbooks/model/purchase.rb
214
+ - lib/quickbooks/model/purchase_line_item.rb
215
+ - lib/quickbooks/model/purchase_order.rb
202
216
  - lib/quickbooks/model/sales_item_line_detail.rb
203
217
  - lib/quickbooks/model/sales_receipt.rb
204
218
  - lib/quickbooks/model/sub_total_line_detail.rb
219
+ - lib/quickbooks/model/tax_line.rb
220
+ - lib/quickbooks/model/tax_line_detail.rb
205
221
  - lib/quickbooks/model/telephone_number.rb
222
+ - lib/quickbooks/model/term.rb
223
+ - lib/quickbooks/model/transaction_tax_detail.rb
206
224
  - lib/quickbooks/model/vendor.rb
225
+ - lib/quickbooks/model/vendor_credit.rb
207
226
  - lib/quickbooks/model/web_site_address.rb
208
227
  - lib/quickbooks/service/account.rb
209
228
  - lib/quickbooks/service/base_service.rb
@@ -213,13 +232,18 @@ files:
213
232
  - lib/quickbooks/service/credit_memo.rb
214
233
  - lib/quickbooks/service/customer.rb
215
234
  - lib/quickbooks/service/employee.rb
235
+ - lib/quickbooks/service/estimate.rb
216
236
  - lib/quickbooks/service/invoice.rb
217
237
  - lib/quickbooks/service/item.rb
238
+ - lib/quickbooks/service/payment.rb
218
239
  - lib/quickbooks/service/payment_method.rb
240
+ - lib/quickbooks/service/purchase.rb
241
+ - lib/quickbooks/service/purchase_order.rb
219
242
  - lib/quickbooks/service/sales_receipt.rb
220
243
  - lib/quickbooks/service/service_crud.rb
244
+ - lib/quickbooks/service/term.rb
221
245
  - lib/quickbooks/service/vendor.rb
222
- - lib/quickbooks/util/class_util.rb
246
+ - lib/quickbooks/service/vendor_credit.rb
223
247
  - lib/quickbooks/util/http_encoding_helper.rb
224
248
  - lib/quickbooks/util/logging.rb
225
249
  - lib/quickbooks/util/name_entity.rb
@@ -1,14 +0,0 @@
1
- module Quickbooks
2
- module Util
3
- class ClassUtil
4
- def self.defined?(class_name)
5
- begin
6
- klass = Module.const_get(class_name)
7
- return klass.is_a?(Class)
8
- rescue NameError
9
- return false
10
- end
11
- end
12
- end
13
- end
14
- end