quickeebooks 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +52 -0
  3. data/MIT-LICENSE +9 -0
  4. data/README.md +306 -0
  5. data/Rakefile +17 -0
  6. data/lib/quickeebooks.rb +89 -0
  7. data/lib/quickeebooks/online/model/account.rb +47 -0
  8. data/lib/quickeebooks/online/model/account_detail_type.rb +233 -0
  9. data/lib/quickeebooks/online/model/account_reference.rb +17 -0
  10. data/lib/quickeebooks/online/model/address.rb +42 -0
  11. data/lib/quickeebooks/online/model/customer.rb +66 -0
  12. data/lib/quickeebooks/online/model/customer_custom_field.rb +51 -0
  13. data/lib/quickeebooks/online/model/email.rb +24 -0
  14. data/lib/quickeebooks/online/model/intuit_type.rb +25 -0
  15. data/lib/quickeebooks/online/model/invoice.rb +50 -0
  16. data/lib/quickeebooks/online/model/invoice_header.rb +29 -0
  17. data/lib/quickeebooks/online/model/invoice_line_item.rb +22 -0
  18. data/lib/quickeebooks/online/model/item.rb +47 -0
  19. data/lib/quickeebooks/online/model/meta_data.rb +27 -0
  20. data/lib/quickeebooks/online/model/note.rb +11 -0
  21. data/lib/quickeebooks/online/model/open_balance.rb +11 -0
  22. data/lib/quickeebooks/online/model/phone.rb +12 -0
  23. data/lib/quickeebooks/online/model/price.rb +18 -0
  24. data/lib/quickeebooks/online/model/purchase_cost.rb +11 -0
  25. data/lib/quickeebooks/online/model/unit_price.rb +11 -0
  26. data/lib/quickeebooks/online/model/web_site.rb +16 -0
  27. data/lib/quickeebooks/online/service/account.rb +52 -0
  28. data/lib/quickeebooks/online/service/customer.rb +57 -0
  29. data/lib/quickeebooks/online/service/entitlement.rb +15 -0
  30. data/lib/quickeebooks/online/service/filter.rb +96 -0
  31. data/lib/quickeebooks/online/service/invoice.rb +50 -0
  32. data/lib/quickeebooks/online/service/item.rb +52 -0
  33. data/lib/quickeebooks/online/service/pagination.rb +19 -0
  34. data/lib/quickeebooks/online/service/service_base.rb +202 -0
  35. data/lib/quickeebooks/online/service/sort.rb +19 -0
  36. data/lib/quickeebooks/version.rb +5 -0
  37. data/lib/quickeebooks/windows/model/account.rb +67 -0
  38. data/lib/quickeebooks/windows/model/account_detail_type.rb +233 -0
  39. data/lib/quickeebooks/windows/model/account_reference.rb +19 -0
  40. data/lib/quickeebooks/windows/model/address.rb +36 -0
  41. data/lib/quickeebooks/windows/model/custom_field.rb +13 -0
  42. data/lib/quickeebooks/windows/model/customer.rb +109 -0
  43. data/lib/quickeebooks/windows/model/email.rb +44 -0
  44. data/lib/quickeebooks/windows/model/intuit_type.rb +17 -0
  45. data/lib/quickeebooks/windows/model/invoice.rb +44 -0
  46. data/lib/quickeebooks/windows/model/invoice_header.rb +65 -0
  47. data/lib/quickeebooks/windows/model/invoice_line_item.rb +38 -0
  48. data/lib/quickeebooks/windows/model/item.rb +84 -0
  49. data/lib/quickeebooks/windows/model/meta_data.rb +31 -0
  50. data/lib/quickeebooks/windows/model/note.rb +19 -0
  51. data/lib/quickeebooks/windows/model/open_balance.rb +11 -0
  52. data/lib/quickeebooks/windows/model/phone.rb +20 -0
  53. data/lib/quickeebooks/windows/model/price.rb +18 -0
  54. data/lib/quickeebooks/windows/model/purchase_cost.rb +12 -0
  55. data/lib/quickeebooks/windows/model/tax_line.rb +18 -0
  56. data/lib/quickeebooks/windows/model/unit_price.rb +12 -0
  57. data/lib/quickeebooks/windows/model/vendor_reference.rb +13 -0
  58. data/lib/quickeebooks/windows/model/web_site.rb +19 -0
  59. data/lib/quickeebooks/windows/service/account.rb +16 -0
  60. data/lib/quickeebooks/windows/service/customer.rb +16 -0
  61. data/lib/quickeebooks/windows/service/invoice.rb +27 -0
  62. data/lib/quickeebooks/windows/service/item.rb +18 -0
  63. data/lib/quickeebooks/windows/service/service_base.rb +176 -0
  64. data/quickeebooks.gemspec +27 -0
  65. data/spec/mocks/oauth_consumer_mock.rb +2 -0
  66. data/spec/quickeebooks/online/account_spec.rb +41 -0
  67. data/spec/quickeebooks/online/customer_spec.rb +46 -0
  68. data/spec/quickeebooks/online/invoice_spec.rb +15 -0
  69. data/spec/quickeebooks/online/services/account_spec.rb +84 -0
  70. data/spec/quickeebooks/online/services/customer_spec.rb +107 -0
  71. data/spec/quickeebooks/online/services/filter_spec.rb +43 -0
  72. data/spec/quickeebooks/online/services/service_base_spec.rb +30 -0
  73. data/spec/quickeebooks/online/services/sort_spec.rb +17 -0
  74. data/spec/quickeebooks/windows/customer_spec.rb +49 -0
  75. data/spec/quickeebooks_spec.rb +11 -0
  76. data/spec/spec_helper.rb +20 -0
  77. data/spec/xml/online/account.xml +13 -0
  78. data/spec/xml/online/accounts.xml +108 -0
  79. data/spec/xml/online/customer.xml +63 -0
  80. data/spec/xml/online/customer2.xml +63 -0
  81. data/spec/xml/online/customers.xml +125 -0
  82. data/spec/xml/online/invoice.xml +33 -0
  83. data/spec/xml/online/user.xml +11 -0
  84. data/spec/xml/windows/customer.xml +56 -0
  85. data/spec/xml/windows/customers.xml +137 -0
  86. data/spec/xml/windows/http_401.xml +8 -0
  87. metadata +229 -0
@@ -0,0 +1,24 @@
1
+ require "quickeebooks"
2
+
3
+ module Quickeebooks
4
+
5
+ module Online
6
+ module Model
7
+ class Email < Quickeebooks::Online::Model::IntuitType
8
+ xml_accessor :address, :from => 'Address'
9
+
10
+ def to_xml(options = {})
11
+ return "" if address.to_s.empty?
12
+ super
13
+ end
14
+
15
+ def initialize(email_address = nil)
16
+ unless email_address.nil?
17
+ self.address = email_address
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ module Quickeebooks
2
+ module Online
3
+ module Model
4
+ class IntuitType
5
+ include ROXML
6
+
7
+ private
8
+
9
+ # ROXML doesnt insert the namespaces into generated XML so we need to do it ourselves
10
+ # insert the static namespaces in the first opening tag that matches the +model_name+
11
+ def to_xml_inject_ns(model_name, options = {})
12
+ s = StringIO.new
13
+ xml = to_xml(options).write_to(s, :indent => 0, :indent_text => '')
14
+ s.string.sub("<#{model_name}>", "<#{model_name} #{Quickeebooks::Online::Service::ServiceBase::XML_NS}>")
15
+ end
16
+
17
+ def log(msg)
18
+ Quickeebooks.logger.info(msg)
19
+ Quickeebooks.logger.flush if Quickeebooks.logger.respond_to?(:flush)
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,50 @@
1
+ # https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0400_QuickBooks_Online/Invoice
2
+
3
+ require 'quickeebooks/online/model/invoice_header'
4
+ require 'quickeebooks/online/model/invoice_line_item'
5
+ require 'quickeebooks/online/model/address'
6
+ require 'quickeebooks/online/model/meta_data'
7
+
8
+
9
+ module Quickeebooks
10
+ module Online
11
+ module Model
12
+ class Invoice < Quickeebooks::Online::Model::IntuitType
13
+ include ActiveModel::Validations
14
+ xml_convention :camelcase
15
+ xml_accessor :id, :from => 'Id', :as => Integer
16
+ xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
17
+ xml_accessor :meta_data, :from => 'MetaData', :as => Quickeebooks::Online::Model::MetaData
18
+ xml_accessor :header, :from => 'Header', :as => Quickeebooks::Online::Model::InvoiceHeader
19
+ xml_accessor :bill_address, :from => 'BillAddr', :as => Quickeebooks::Online::Model::Address
20
+ xml_accessor :ship_address, :from => 'ShipAddr', :as => Quickeebooks::Online::Model::Address
21
+ xml_accessor :bill_email, :from => 'BillEmail'
22
+ xml_accessor :ship_method_id, :from => 'ShipMethodId'
23
+ xml_accessor :ship_method_name, :from => 'ShipMethodName'
24
+ xml_accessor :balance, :from => 'Balance', :as => Float
25
+ xml_accessor :discount_amount, :from => 'DiscountAmt', :as => Float
26
+ xml_accessor :discount_rate, :from => 'DiscountRate', :as => Float
27
+ xml_accessor :discount_taxable, :from => 'DiscountTaxable'
28
+ xml_accessor :txn_id, :from => 'TxnId'
29
+ xml_accessor :line_items, :from => 'Line', :as => [Quickeebooks::Online::Model::InvoiceLineItem]
30
+
31
+ validates_length_of :line_items, :minimum => 1
32
+
33
+ def initialize
34
+ ensure_line_items_initialization
35
+ end
36
+
37
+ private
38
+
39
+ def after_parse
40
+ end
41
+
42
+ def ensure_line_items_initialization
43
+ self.line_items ||= []
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,29 @@
1
+ require 'time'
2
+
3
+ module Quickeebooks
4
+ module Online
5
+ module Model
6
+ class InvoiceHeader < Quickeebooks::Online::Model::IntuitType
7
+
8
+ IS_TAXABLE = "IS_TAXABLE"
9
+
10
+ xml_name 'Header'
11
+ xml_accessor :doc_number, :from => 'DocNumber'
12
+ xml_accessor :txn_date, :from => 'TxnDate', :as => Time
13
+ xml_accessor :msg, :from => 'Msg'
14
+ xml_accessor :customer_id, :from => 'CustomerId'
15
+ xml_accessor :sales_tax_code_id, :from => 'SalesTaxCodeId'
16
+ xml_accessor :sales_tax_code_name, :from => 'SalesTaxCodeName'
17
+ xml_accessor :sub_total_amount, :from => 'SubTotalAmt', :as => Float
18
+ xml_accessor :tax_rate, :from => 'TaxRate', :as => Float
19
+ xml_accessor :total_amount, :from => 'TotalAmt', :as => Float
20
+ xml_accessor :due_date, :from => 'DueDate', :as => Time
21
+ xml_accessor :bill_email, :from => 'BillEmail'
22
+ xml_accessor :discount_amount, :from => 'DiscountAmt', :as => Float
23
+ xml_accessor :status, :from => 'Status'
24
+ xml_accessor :ship_date, :from => 'ShipDate', :as => Time
25
+ end
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,22 @@
1
+ module Quickeebooks
2
+
3
+ module Online
4
+ module Model
5
+ class InvoiceLineItem < Quickeebooks::Online::Model::IntuitType
6
+ xml_name 'Line'
7
+ xml_accessor :id, :from => 'Id'
8
+ xml_accessor :desc, :from => 'Desc'
9
+ xml_accessor :amount, :from => 'Amount', :as => Float
10
+ xml_accessor :class_id, :from => 'ClassId'
11
+ xml_accessor :taxable, :from => 'Taxable'
12
+ xml_accessor :item_id, :from => 'ItemId'
13
+ xml_accessor :unit_price, :from => 'UnitPrice', :as => Float
14
+ xml_accessor :quantity, :from => 'Qty', :as => Float
15
+ xml_accessor :override_item_account_id, :from => 'OverrideItemAccountId'
16
+ xml_accessor :sales_tax_code_id, :from => 'SalesTaxCodeId'
17
+ xml_accessor :sales_tax_code_name, :from => 'SalesTaxCodeName'
18
+ xml_accessor :service_date, :from => 'ServiceDate', :as => Time
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,47 @@
1
+ require 'time'
2
+ require 'quickeebooks/online/model/price'
3
+ require 'quickeebooks/online/model/meta_data'
4
+ require 'quickeebooks/online/model/account_reference'
5
+
6
+ module Quickeebooks
7
+
8
+ module Online
9
+ module Model
10
+ class Item < Quickeebooks::Online::Model::IntuitType
11
+ include ActiveModel::Validations
12
+
13
+ xml_name 'Item'
14
+ xml_accessor :id, :from => 'Id'
15
+ xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
16
+ xml_accessor :meta_data, :from => 'MetaData', :as => Quickeebooks::Online::Model::MetaData
17
+ xml_accessor :item_parent_id, :from => 'ItemParentId'
18
+ xml_accessor :item_parent_name, :from => 'ItemParentName'
19
+ xml_accessor :name, :from => 'Name'
20
+ xml_accessor :desc, :from => 'Desc'
21
+ xml_accessor :taxable, :from => 'Taxable'
22
+ xml_accessor :unit_price, :from => 'UnitPrice', :as => Quickeebooks::Online::Model::Price
23
+ xml_accessor :account_reference, :from => 'IncomeAccountRef', :as => Quickeebooks::Online::Model::AccountReference
24
+ xml_accessor :purchase_desc, :from => 'PurchaseDesc'
25
+ xml_accessor :purchase_cost, :from => 'PurchaseCost', :as => Quickeebooks::Online::Model::Price
26
+ xml_accessor :expense_account_reference, :from => 'ExpenseAccountRef', :as => Quickeebooks::Online::Model::AccountReference
27
+
28
+ validates_presence_of :account_reference
29
+
30
+ def to_xml_ns(options = {})
31
+ to_xml_inject_ns('Item', options)
32
+ end
33
+
34
+ # To delete a record Intuit requires we provide Id and SyncToken fields
35
+ def valid_for_deletion?
36
+ return false if(id.nil? || sync_token.nil?)
37
+ id.to_i > 0 && !sync_token.to_s.empty? && sync_token.to_i >= 0
38
+ end
39
+
40
+ def taxable?
41
+ taxable == "true"
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,27 @@
1
+ require 'quickeebooks'
2
+ require 'time'
3
+
4
+ module Quickeebooks
5
+ module Online
6
+ module Model
7
+ class MetaData < Quickeebooks::Online::Model::IntuitType
8
+ xml_accessor :create_time, :from => 'CreateTime', :as => Time
9
+ xml_accessor :last_updated_time, :from => 'LastUpdatedTime', :as => Time
10
+
11
+ def to_xml(options = {})
12
+ xml = %Q{<MetaData>}
13
+ xml = "#{xml}<CreateTime>#{formatted_date(create_time)}</CreateTime>"
14
+ xml = "#{xml}<LastUpdatedTime>#{formatted_date(last_updated_time)}</LastUpdatedTime></MetaData>"
15
+ xml
16
+ end
17
+
18
+ private
19
+
20
+ def formatted_date(datetime)
21
+ datetime.strftime('%Y-%m-%dT%H:%M:%S%z')
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ require 'quickeebooks'
2
+
3
+ module Quickeebooks
4
+ module Online
5
+ module Model
6
+ class Note < Quickeebooks::Online::Model::IntuitType
7
+ xml_accessor :content, :from => 'Content'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "quickeebooks"
2
+
3
+ module Quickeebooks
4
+ module Online
5
+ module Model
6
+ class OpenBalance < Quickeebooks::Online::Model::IntuitType
7
+ xml_accessor :amount, :from => 'Amount', :as => Float
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require "quickeebooks"
2
+
3
+ module Quickeebooks
4
+ module Online
5
+ module Model
6
+ class Phone < Quickeebooks::Online::Model::IntuitType
7
+ xml_accessor :device_type, :from => 'DeviceType'
8
+ xml_accessor :free_form_number, :from => 'FreeFormNumber'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ require "quickeebooks"
2
+
3
+ module Quickeebooks
4
+ module Online
5
+ module Model
6
+ class Price < Quickeebooks::Online::Model::IntuitType
7
+ xml_accessor :amount, :from => 'Amount', :as => Float
8
+
9
+ def initialize(amount = nil)
10
+ if amount
11
+ self.amount = amount
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ require "quickeebooks"
2
+
3
+ module Quickeebooks
4
+ module Online
5
+ module Model
6
+ class PurchaseCost < Quickeebooks::Online::Model::IntuitType
7
+ xml_accessor :amount, :from => 'Amount', :as => Float
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "quickeebooks"
2
+
3
+ module Quickeebooks
4
+ module Online
5
+ module Model
6
+ class UnitPrice < Quickeebooks::Online::Model::IntuitType
7
+ xml_accessor :amount, :from => 'Amount', :as => Float
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require "quickeebooks"
2
+
3
+ module Quickeebooks
4
+ module Online
5
+ module Model
6
+ class WebSite < Quickeebooks::Online::Model::IntuitType
7
+ xml_accessor :uri, :from => 'URI'
8
+
9
+ def to_xml(options = {})
10
+ return "" if uri.to_s.empty?
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,52 @@
1
+ require 'quickeebooks/online/model/account'
2
+ require 'quickeebooks/online/service/service_base'
3
+
4
+ module Quickeebooks
5
+ module Online
6
+ module Service
7
+ class Account < ServiceBase
8
+
9
+ def list(filters = [], page = 1, per_page = 20, sort = nil, options = {})
10
+ fetch_collection("accounts", "Account", Quickeebooks::Online::Model::Account, filters, page, per_page, sort, options)
11
+ end
12
+
13
+ def create(account)
14
+ raise InvalidModelException unless account.valid?
15
+ xml = account.to_xml_ns
16
+ response = do_http_post(url_for_resource("account"), valid_xml_document(xml))
17
+ if response && response.code.to_i == 200
18
+ Quickeebooks::Online::Model::Account.from_xml(response.body)
19
+ else
20
+ nil
21
+ end
22
+ end
23
+
24
+ def update(account)
25
+ raise InvalidModelException unless account.valid_for_update?
26
+ xml = account.to_xml_ns
27
+ url = "#{url_for_resource("account")}/#{account.id}"
28
+ response = do_http_post(url, valid_xml_document(xml))
29
+ if response && response.code.to_i == 200
30
+ Quickeebooks::Online::Model::Account.from_xml(response.body)
31
+ else
32
+ nil
33
+ end
34
+ end
35
+
36
+ def fetch_by_id(account_id)
37
+ response = do_http_get("#{url_for_resource("account")}/#{account_id}")
38
+ Quickeebooks::Online::Model::Account.from_xml(response.body)
39
+ end
40
+
41
+ def delete(account)
42
+ raise InvalidModelException.new("Missing required parameters for delete") unless account.valid_for_deletion?
43
+ xml = valid_xml_document(account.to_xml_ns(:fields => ['Id', 'SyncToken']))
44
+ url = "#{url_for_resource("account")}/#{account.id}"
45
+ response = do_http_post(url, xml, {:methodx => "delete"})
46
+ response.code.to_i == 200
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,57 @@
1
+ require 'quickeebooks/online/service/service_base'
2
+ require 'nokogiri'
3
+
4
+ module Quickeebooks
5
+ module Online
6
+ module Service
7
+ class Customer < ServiceBase
8
+
9
+ def create(customer)
10
+ raise InvalidModelException unless customer.valid?
11
+ xml = customer.to_xml_ns
12
+ response = do_http_post(url_for_resource("customer"), valid_xml_document(xml))
13
+ if response.code.to_i == 200
14
+ Quickeebooks::Online::Model::Customer.from_xml(response.body)
15
+ else
16
+ nil
17
+ end
18
+ end
19
+
20
+ def fetch_by_id(id)
21
+ url = "#{url_for_resource("customer")}/#{id}"
22
+ response = do_http_get(url)
23
+ if response && response.code.to_i == 200
24
+ Quickeebooks::Online::Model::Customer.from_xml(response.body)
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ def update(customer)
31
+ raise InvalidModelException.new("Missing required parameters for update") unless customer.valid_for_update?
32
+ url = "#{url_for_resource("customer")}/#{customer.id}"
33
+ xml = customer.to_xml_ns
34
+ response = do_http_post(url, valid_xml_document(xml))
35
+ if response.code.to_i == 200
36
+ Quickeebooks::Online::Model::Customer.from_xml(response.body)
37
+ else
38
+ nil
39
+ end
40
+ end
41
+
42
+ def delete(customer)
43
+ raise InvalidModelException.new("Missing required parameters for delete") unless customer.valid_for_deletion?
44
+ xml = valid_xml_document(customer.to_xml_ns(:fields => ['Id', 'SyncToken']))
45
+ url = "#{url_for_resource("customer")}/#{customer.id}"
46
+ response = do_http_post(url, xml, {:methodx => "delete"})
47
+ response.code.to_i == 200
48
+ end
49
+
50
+ def list(filters = [], page = 1, per_page = 20, sort = nil, options = {})
51
+ fetch_collection("customers", "Customer", Quickeebooks::Online::Model::Customer, filters, page, per_page, sort, options)
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end