quickeebooks 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/Gemfile.lock +19 -16
  2. data/README.md +29 -23
  3. data/coverage/assets/0.7.1/application.css +1110 -0
  4. data/coverage/assets/0.7.1/application.js +626 -0
  5. data/coverage/assets/0.7.1/fancybox/blank.gif +0 -0
  6. data/coverage/assets/0.7.1/fancybox/fancy_close.png +0 -0
  7. data/coverage/assets/0.7.1/fancybox/fancy_loading.png +0 -0
  8. data/coverage/assets/0.7.1/fancybox/fancy_nav_left.png +0 -0
  9. data/coverage/assets/0.7.1/fancybox/fancy_nav_right.png +0 -0
  10. data/coverage/assets/0.7.1/fancybox/fancy_shadow_e.png +0 -0
  11. data/coverage/assets/0.7.1/fancybox/fancy_shadow_n.png +0 -0
  12. data/coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png +0 -0
  13. data/coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png +0 -0
  14. data/coverage/assets/0.7.1/fancybox/fancy_shadow_s.png +0 -0
  15. data/coverage/assets/0.7.1/fancybox/fancy_shadow_se.png +0 -0
  16. data/coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png +0 -0
  17. data/coverage/assets/0.7.1/fancybox/fancy_shadow_w.png +0 -0
  18. data/coverage/assets/0.7.1/fancybox/fancy_title_left.png +0 -0
  19. data/coverage/assets/0.7.1/fancybox/fancy_title_main.png +0 -0
  20. data/coverage/assets/0.7.1/fancybox/fancy_title_over.png +0 -0
  21. data/coverage/assets/0.7.1/fancybox/fancy_title_right.png +0 -0
  22. data/coverage/assets/0.7.1/fancybox/fancybox-x.png +0 -0
  23. data/coverage/assets/0.7.1/fancybox/fancybox-y.png +0 -0
  24. data/coverage/assets/0.7.1/fancybox/fancybox.png +0 -0
  25. data/coverage/assets/0.7.1/favicon_green.png +0 -0
  26. data/coverage/assets/0.7.1/favicon_red.png +0 -0
  27. data/coverage/assets/0.7.1/favicon_yellow.png +0 -0
  28. data/coverage/assets/0.7.1/loading.gif +0 -0
  29. data/coverage/assets/0.7.1/magnify.png +0 -0
  30. data/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  31. data/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  32. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  33. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  34. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  35. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  36. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  37. data/coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  38. data/coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png +0 -0
  39. data/coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  40. data/coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png +0 -0
  41. data/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png +0 -0
  42. data/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  43. data/coverage/index.html +29154 -0
  44. data/lib/quickeebooks/common/online_line_item_model_methods.rb +43 -0
  45. data/lib/quickeebooks/common/service_crud.rb +56 -0
  46. data/lib/quickeebooks/online/model/bill.rb +26 -0
  47. data/lib/quickeebooks/online/model/bill_header.rb +21 -0
  48. data/lib/quickeebooks/online/model/bill_line_item.rb +22 -0
  49. data/lib/quickeebooks/online/model/bill_reimbursable.rb +11 -0
  50. data/lib/quickeebooks/online/model/invoice.rb +2 -31
  51. data/lib/quickeebooks/online/model/payment.rb +5 -33
  52. data/lib/quickeebooks/online/service/bill.rb +17 -0
  53. data/lib/quickeebooks/online/service/customer.rb +3 -47
  54. data/lib/quickeebooks/online/service/invoice.rb +1 -1
  55. data/lib/quickeebooks/online/service/payment.rb +3 -46
  56. data/lib/quickeebooks/online/service/service_base.rb +3 -2
  57. data/lib/quickeebooks/online/service/sort.rb +1 -12
  58. data/lib/quickeebooks/shared/service/filter.rb +19 -2
  59. data/lib/quickeebooks/shared/service/sort.rb +22 -0
  60. data/lib/quickeebooks/version.rb +1 -1
  61. data/lib/quickeebooks/windows/service/clazz.rb +1 -5
  62. data/lib/quickeebooks/windows/service/customer.rb +9 -13
  63. data/lib/quickeebooks/windows/service/item.rb +2 -5
  64. data/lib/quickeebooks/windows/service/service_base.rb +30 -15
  65. data/lib/quickeebooks/windows/service/sort.rb +8 -0
  66. data/lib/quickeebooks.rb +11 -5
  67. data/quickeebooks.gemspec +2 -2
  68. data/spec/quickeebooks/common/online_line_item_model_methods_spec.rb +41 -0
  69. data/spec/quickeebooks/common/service_crud_spec.rb +41 -0
  70. data/spec/quickeebooks/online/account_spec.rb +4 -8
  71. data/spec/quickeebooks/online/bill_spec.rb +17 -0
  72. data/spec/quickeebooks/online/company_meta_data_spec.rb +6 -9
  73. data/spec/quickeebooks/online/customer_spec.rb +10 -14
  74. data/spec/quickeebooks/online/invoice_spec.rb +3 -7
  75. data/spec/quickeebooks/online/payment_spec.rb +6 -10
  76. data/spec/quickeebooks/online/services/account_spec.rb +8 -13
  77. data/spec/quickeebooks/online/services/bill_spec.rb +61 -0
  78. data/spec/quickeebooks/online/services/company_meta_data_spec.rb +2 -7
  79. data/spec/quickeebooks/online/services/customer_spec.rb +15 -20
  80. data/spec/quickeebooks/online/services/filter_spec.rb +0 -5
  81. data/spec/quickeebooks/online/services/invoice_spec.rb +5 -10
  82. data/spec/quickeebooks/online/services/payment_spec.rb +63 -0
  83. data/spec/quickeebooks/online/services/service_base_spec.rb +62 -9
  84. data/spec/quickeebooks/shared/access_token_spec.rb +6 -11
  85. data/spec/quickeebooks/shared/filter_spec.rb +159 -0
  86. data/spec/quickeebooks/shared/sort_spec.rb +17 -0
  87. data/spec/quickeebooks/windows/customer_spec.rb +11 -15
  88. data/spec/quickeebooks/windows/services/class_spec.rb +2 -7
  89. data/spec/quickeebooks/windows/services/company_meta_data_spec.rb +2 -7
  90. data/spec/quickeebooks/windows/services/customer_spec.rb +16 -21
  91. data/spec/quickeebooks/windows/services/invoice_spec.rb +13 -19
  92. data/spec/quickeebooks/windows/services/payment_spec.rb +6 -12
  93. data/spec/quickeebooks/windows/services/sales_rep_spec.rb +6 -11
  94. data/spec/quickeebooks/windows/services/sales_taxes_spec.rb +5 -10
  95. data/spec/quickeebooks/windows/services/service_base_spec.rb +95 -0
  96. data/spec/quickeebooks/windows/services/ship_method_spec.rb +4 -9
  97. data/spec/quickeebooks_spec.rb +0 -3
  98. data/spec/spec_helper.rb +30 -1
  99. data/spec/support/oauth.rb +20 -0
  100. data/spec/xml/online/bill.xml +32 -0
  101. data/spec/xml/online/bill2.xml +32 -0
  102. data/spec/xml/online/bills.xml +33 -0
  103. data/spec/xml/online/payment.xml +1 -1
  104. data/spec/xml/online/payment2.xml +24 -0
  105. data/spec/xml/online/payments.xml +30 -0
  106. metadata +103 -40
  107. data/spec/quickeebooks/online/services/sort_spec.rb +0 -17
@@ -0,0 +1,43 @@
1
+ module OnlineLineItemModelMethods
2
+
3
+ def self.included base
4
+ base.send :include, InstanceMethods
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module InstanceMethods
9
+ def initialize
10
+ ensure_line_items_initialization
11
+ end
12
+
13
+ def valid_for_update?
14
+ errors.empty?
15
+ end
16
+
17
+ def to_xml_ns(options = {})
18
+ to_xml_inject_ns(self.class::XML_NODE, options)
19
+ end
20
+
21
+ def valid_for_deletion?
22
+ return false if(id.nil? || sync_token.nil?)
23
+ id.value.to_i > 0 && !sync_token.to_s.empty? && sync_token.to_i >= 0
24
+ end
25
+
26
+ private
27
+
28
+ def after_parse
29
+ end
30
+
31
+ def ensure_line_items_initialization
32
+ self.line_items ||= []
33
+ end
34
+ end
35
+
36
+ module ClassMethods
37
+ def resource_for_collection
38
+ "#{self::REST_RESOURCE}s"
39
+ end
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,56 @@
1
+ module ServiceCRUD
2
+
3
+ def create(object)
4
+ raise InvalidModelException unless object.valid?
5
+ xml = object.to_xml_ns
6
+ response = do_http_post(url_for_resource(model.resource_for_singular), valid_xml_document(xml))
7
+ if response.code.to_i == 200
8
+ model.from_xml(response.body)
9
+ else
10
+ nil
11
+ end
12
+ end
13
+
14
+ def fetch_by_id(id)
15
+ url = "#{url_for_resource(model.resource_for_singular)}/#{id}"
16
+ response = do_http_get(url)
17
+ if response && response.code.to_i == 200
18
+ model.from_xml(response.body)
19
+ else
20
+ nil
21
+ end
22
+ end
23
+
24
+ def update(object)
25
+ raise InvalidModelException.new("Missing required parameters for update") unless object.valid_for_update?
26
+ url = action_url(object)
27
+ xml = object.to_xml_ns
28
+ response = do_http_post(url, valid_xml_document(xml))
29
+ if response.code.to_i == 200
30
+ model.from_xml(response.body)
31
+ else
32
+ nil
33
+ end
34
+ end
35
+
36
+ def delete(object)
37
+ raise InvalidModelException.new("Missing required parameters for delete") unless object.valid_for_deletion?
38
+ xml = valid_xml_document(object.to_xml_ns(:fields => ['Id', 'SyncToken']))
39
+ url = action_url(object)
40
+ response = do_http_post(url, xml, {:methodx => "delete"})
41
+ response.code.to_i == 200
42
+ end
43
+
44
+ def list(filters = [], page = 1, per_page = 20, sort = nil, options = {})
45
+ fetch_collection(model, filters, page, per_page, sort, options)
46
+ end
47
+
48
+ def model
49
+ self.class.to_s.sub(/::Service::/,'::Model::').constantize
50
+ end
51
+
52
+ def action_url(object)
53
+ url = "#{url_for_resource(model.resource_for_singular)}/#{object.id.value}"
54
+ end
55
+
56
+ end
@@ -0,0 +1,26 @@
1
+ # http://docs.developer.intuit.com/0025_Intuit_Anywhere/0050_Data_Services/v2/0400_QuickBooks_Online/Bill
2
+ require 'quickeebooks/online/model/bill_header'
3
+ require 'quickeebooks/online/model/bill_line_item'
4
+ require 'quickeebooks/online/model/meta_data'
5
+ require 'quickeebooks/common/online_line_item_model_methods'
6
+
7
+ module Quickeebooks
8
+ module Online
9
+ module Model
10
+ class Bill < Quickeebooks::Online::Model::IntuitType
11
+ include ActiveModel::Validations
12
+ include OnlineLineItemModelMethods
13
+ XML_NODE = "Bill"
14
+ REST_RESOURCE = "bill"
15
+
16
+ xml_convention :camelcase
17
+ xml_accessor :id, :from => 'Id', :as => Quickeebooks::Online::Model::Id
18
+ xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
19
+ xml_accessor :meta_data, :from => 'MetaData', :as => Quickeebooks::Online::Model::MetaData
20
+ xml_accessor :header, :from => 'Header', :as => Quickeebooks::Online::Model::BillHeader
21
+ xml_accessor :line_items, :from => 'Line', :as => [Quickeebooks::Online::Model::BillLineItem]
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ require 'time'
2
+
3
+ module Quickeebooks
4
+ module Online
5
+ module Model
6
+ class BillHeader < Quickeebooks::Online::Model::IntuitType
7
+ xml_name 'Header'
8
+ xml_accessor :doc_number, :from => 'DocNumber'
9
+ xml_accessor :txn_date, :from => 'TxnDate', :as => Time
10
+ xml_accessor :msg, :from => 'Msg'
11
+ xml_accessor :note, :from => 'Note'
12
+ xml_accessor :status, :from => 'Status'
13
+ xml_accessor :vendor_id, :from => 'VendorId', :as => Quickeebooks::Online::Model::Id
14
+ xml_accessor :total_amount, :from => 'TotalAmt', :as => Float
15
+ xml_accessor :sales_term_id, :from => 'SalesTermId', :as => Quickeebooks::Online::Model::Id
16
+ xml_accessor :due_date, :from => 'DueDate', :as => Time
17
+ xml_accessor :balance, :from => 'Balance', :as => Float
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'quickeebooks/online/model/bill_reimbursable'
2
+
3
+ module Quickeebooks
4
+ module Online
5
+ module Model
6
+ class BillLineItem < Quickeebooks::Online::Model::IntuitType
7
+ xml_name 'Line'
8
+ xml_accessor :id, :from => 'Id', :as => Integer
9
+ xml_accessor :desc, :from => 'Desc'
10
+ xml_accessor :amount, :from => 'Amount', :as => Float
11
+ xml_accessor :class_id, :from => 'ClassId', :as => Quickeebooks::Online::Model::Id
12
+ xml_accessor :billable_status, :from => 'BillableStatus'
13
+ xml_accessor :item_id, :from => 'ItemId', :as => Quickeebooks::Online::Model::Id
14
+ xml_accessor :unit_price, :from => 'UnitPrice', :as => Float
15
+ xml_accessor :quantity, :from => 'Qty', :as => Float
16
+ xml_accessor :override_item_account_id, :from => 'OverrideItemAccountId', :as => Quickeebooks::Online::Model::Id
17
+ xml_accessor :account_id, :from => 'AccountId', :as => Quickeebooks::Online::Model::Id
18
+ xml_accessor :reimbursable, :from => 'ReimbursableInfo', :as => Quickeebooks::Online::Model::ReimbursableInfo
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module Quickeebooks
2
+ module Online
3
+ module Model
4
+ class ReimbursableInfo < Quickeebooks::Online::Model::IntuitType
5
+ xml_name 'ReimbursableInfo'
6
+ xml_accessor :customer_id, :from => 'CustomerId', :as => Quickeebooks::Online::Model::Id
7
+ xml_accessor :customer_name, :from => 'CustomerName'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -5,6 +5,7 @@ require 'quickeebooks/online/model/invoice_header'
5
5
  require 'quickeebooks/online/model/invoice_line_item'
6
6
  require 'quickeebooks/online/model/address'
7
7
  require 'quickeebooks/online/model/meta_data'
8
+ require 'quickeebooks/common/online_line_item_model_methods'
8
9
 
9
10
 
10
11
  module Quickeebooks
@@ -12,6 +13,7 @@ module Quickeebooks
12
13
  module Model
13
14
  class Invoice < Quickeebooks::Online::Model::IntuitType
14
15
  include ActiveModel::Validations
16
+ include OnlineLineItemModelMethods
15
17
 
16
18
  XML_NODE = "Invoice"
17
19
  REST_RESOURCE = "invoice"
@@ -34,37 +36,6 @@ module Quickeebooks
34
36
 
35
37
  validates_length_of :line_items, :minimum => 1
36
38
 
37
- def initialize
38
- ensure_line_items_initialization
39
- end
40
-
41
- def valid_for_update?
42
- errors.empty?
43
- end
44
-
45
- def valid_for_deletion?
46
- return false if(id.nil? || sync_token.nil?)
47
- id.to_i > 0 && !sync_token.to_s.empty? && sync_token.to_i >= 0
48
- end
49
-
50
- def to_xml_ns(options = {})
51
- to_xml_inject_ns(XML_NODE, options)
52
- end
53
-
54
- #== Class methods
55
- def self.resource_for_collection
56
- "#{self::REST_RESOURCE}s"
57
- end
58
-
59
- private
60
-
61
- def after_parse
62
- end
63
-
64
- def ensure_line_items_initialization
65
- self.line_items ||= []
66
- end
67
-
68
39
  end
69
40
  end
70
41
  end
@@ -5,15 +5,18 @@ require 'quickeebooks/online/model/credit_card'
5
5
  require 'quickeebooks/online/model/credit_charge_info'
6
6
  require 'quickeebooks/online/model/credit_charge_response'
7
7
  require 'quickeebooks/online/model/meta_data'
8
+ require 'quickeebooks/common/online_line_item_model_methods'
8
9
 
9
10
  module Quickeebooks
10
11
  module Online
11
12
  module Model
12
13
  class Payment < Quickeebooks::Online::Model::IntuitType
14
+ include ActiveModel::Validations
15
+ include OnlineLineItemModelMethods
16
+
13
17
  XML_NODE = "Payment"
14
18
  REST_RESOURCE = "payment"
15
19
 
16
- include ActiveModel::Validations
17
20
  xml_convention :camelcase
18
21
  xml_accessor :id, :from => 'Id', :as => Quickeebooks::Online::Model::Id
19
22
  xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
@@ -21,38 +24,7 @@ module Quickeebooks
21
24
  xml_accessor :header, :from => 'Header', :as => Quickeebooks::Online::Model::PaymentHeader
22
25
  xml_accessor :line_items, :from => 'Line', :as => [Quickeebooks::Online::Model::PaymentLineItem]
23
26
 
24
- def initialize
25
- ensure_line_items_initialization
26
- end
27
-
28
- def valid_for_update?
29
- errors.empty?
30
- end
31
-
32
- def to_xml_ns(options = {})
33
- to_xml_inject_ns(XML_NODE, options)
34
- end
35
-
36
- def valid_for_deletion?
37
- return false if(id.nil? || sync_token.nil?)
38
- id.to_i > 0 && !sync_token.to_s.empty? && sync_token.to_i >= 0
39
- end
40
-
41
- #== Class methods
42
- def self.resource_for_collection
43
- "#{self::REST_RESOURCE}s"
44
- end
45
-
46
- private
47
-
48
- def after_parse
49
- end
50
-
51
- def ensure_line_items_initialization
52
- self.line_items ||= []
53
- end
54
-
55
27
  end
56
28
  end
57
29
  end
58
- end
30
+ end
@@ -0,0 +1,17 @@
1
+ require 'quickeebooks/online/service/service_base'
2
+ require 'quickeebooks/online/model/bill'
3
+ require 'quickeebooks/online/model/bill_header'
4
+ require 'quickeebooks/online/model/bill_line_item'
5
+ require 'quickeebooks/common/service_crud'
6
+ require 'nokogiri'
7
+
8
+ module Quickeebooks
9
+ module Online
10
+ module Service
11
+ class Bill < ServiceBase
12
+ include ServiceCRUD
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -1,57 +1,13 @@
1
1
  require 'quickeebooks/online/service/service_base'
2
+ require 'quickeebooks/common/service_crud'
2
3
  require 'nokogiri'
3
4
 
4
5
  module Quickeebooks
5
6
  module Online
6
7
  module Service
7
8
  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(Quickeebooks::Online::Model::Customer.resource_for_singular), 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(Quickeebooks::Online::Model::Customer.resource_for_singular)}/#{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(Quickeebooks::Online::Model::Customer.resource_for_singular)}/#{customer.id.value}"
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(Quickeebooks::Online::Model::Customer.resource_for_singular)}/#{customer.id.value}"
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(Quickeebooks::Online::Model::Customer, filters, page, per_page, sort, options)
52
- end
53
-
9
+ include ServiceCRUD
54
10
  end
55
11
  end
56
12
  end
57
- end
13
+ end
@@ -29,7 +29,7 @@ module Quickeebooks
29
29
 
30
30
  def update(invoice)
31
31
  raise InvalidModelException.new("Missing required parameters for update") unless invoice.valid_for_update?
32
- url = "#{url_for_resource(Quickeebooks::Online::Model::Invoice.resource_for_singular)}/#{invoice.id}"
32
+ url = "#{url_for_resource(Quickeebooks::Online::Model::Invoice.resource_for_singular)}/#{invoice.id.value}"
33
33
  xml = invoice.to_xml_ns
34
34
  response = do_http_post(url, valid_xml_document(xml))
35
35
  if response.code.to_i == 200
@@ -6,58 +6,15 @@ require 'quickeebooks/online/model/payment_detail'
6
6
  require 'quickeebooks/online/model/credit_card'
7
7
  require 'quickeebooks/online/model/credit_charge_info'
8
8
  require 'quickeebooks/online/model/credit_charge_response'
9
+ require 'quickeebooks/common/service_crud'
9
10
  require 'nokogiri'
10
11
 
11
12
  module Quickeebooks
12
13
  module Online
13
14
  module Service
14
15
  class Payment < ServiceBase
15
-
16
- def create(payment)
17
- raise InvalidModelException unless payment.valid?
18
- xml = payment.to_xml_ns
19
- response = do_http_post(url_for_resource(Quickeebooks::Online::Model::Payment.resource_for_singular), valid_xml_document(xml))
20
- if response.code.to_i == 200
21
- Quickeebooks::Online::Model::Payment.from_xml(response.body)
22
- else
23
- nil
24
- end
25
- end
26
-
27
- def fetch_by_id(id)
28
- url = "#{url_for_resource(Quickeebooks::Online::Model::Payment.resource_for_singular)}/#{id}"
29
- response = do_http_get(url)
30
- if response && response.code.to_i == 200
31
- Quickeebooks::Online::Model::Payment.from_xml(response.body)
32
- else
33
- nil
34
- end
35
- end
36
-
37
- def update(payment)
38
- raise InvalidModelException.new("Missing required parameters for update") unless payment.valid_for_update?
39
- url = "#{url_for_resource(Quickeebooks::Online::Model::Payment.resource_for_singular)}/#{payment.id}"
40
- xml = payment.to_xml_ns
41
- response = do_http_post(url, valid_xml_document(xml))
42
- if response.code.to_i == 200
43
- Quickeebooks::Online::Model::Payment.from_xml(response.body)
44
- else
45
- nil
46
- end
47
- end
48
-
49
- def list(filters = [], page = 1, per_page = 20, sort = nil, options = {})
50
- fetch_collection(Quickeebooks::Online::Model::Payment, filters, page, per_page, sort, options)
51
- end
52
-
53
- def delete(payment)
54
- raise InvalidModelException.new("Missing required parameters for delete") unless payment.valid_for_deletion?
55
- xml = valid_xml_document(payment.to_xml_ns(:fields => ['Id', 'SyncToken']))
56
- url = "#{url_for_resource(Quickeebooks::Online::Model::Payment.resource_for_singular)}/#{payment.id}"
57
- response = do_http_post(url, xml, {:methodx => "delete"})
58
- response.code.to_i == 200
59
- end
16
+ include ServiceCRUD
60
17
  end
61
18
  end
62
19
  end
63
- end
20
+ end
@@ -134,9 +134,10 @@ module Quickeebooks
134
134
  headers.merge!({'Content-Type' => 'application/xml'})
135
135
  end
136
136
  # puts "METHOD = #{method}"
137
- # puts "URL = #{url}"
138
- # puts "BODY = #{body == nil ? "<NIL>" : body}"
137
+ # puts "RESOURCE = #{resource}"
138
+ # puts "BODY(#{body.class}) = #{body == nil ? "<NIL>" : body.inspect}"
139
139
  # puts "HEADERS = #{headers.inspect}"
140
+
140
141
  response = @oauth.request(method, resource, body, headers)
141
142
  check_response(response)
142
143
  end
@@ -1,18 +1,7 @@
1
1
  module Quickeebooks
2
2
  module Online
3
3
  module Service
4
- class Sort
5
- attr_accessor :field, :how
6
-
7
- def initialize(field, how)
8
- @field = field
9
- @how = how
10
- end
11
-
12
- def to_s
13
- "#{field} #{how}"
14
- end
15
-
4
+ class Sort < Quickeebooks::Shared::Service::Sort
16
5
  end
17
6
  end
18
7
  end
@@ -39,6 +39,17 @@ module Quickeebooks
39
39
  end
40
40
  end
41
41
 
42
+ def to_xml
43
+ case @type.to_sym
44
+ when :text
45
+ text_to_xml
46
+ when :boolean
47
+ boolean_to_xml
48
+ else
49
+ raise ArgumentError, "Don't know how to generate a Filter for type #{@type}"
50
+ end
51
+ end
52
+
42
53
  private
43
54
 
44
55
  def number_to_s
@@ -77,10 +88,18 @@ module Quickeebooks
77
88
  "#{@field} :EQUALS: #{@value}"
78
89
  end
79
90
 
91
+ def text_to_xml
92
+ "<#{@field}>#{CGI::escapeHTML(@value.to_s)}</#{@field}>"
93
+ end
94
+
80
95
  def boolean_to_s
81
96
  "#{@field} :EQUALS: #{@value}"
82
97
  end
83
98
 
99
+ def boolean_to_xml
100
+ "<#{@field}>#{CGI::escapeHTML(@value.to_s)}</#{@field}>"
101
+ end
102
+
84
103
  def formatted_time(time)
85
104
  if time.is_a?(Date)
86
105
  time.strftime(DATE_FORMAT)
@@ -88,8 +107,6 @@ module Quickeebooks
88
107
  time.strftime(DATE_TIME_FORMAT)
89
108
  end
90
109
  end
91
-
92
-
93
110
  end
94
111
  end
95
112
  end
@@ -0,0 +1,22 @@
1
+ module Quickeebooks
2
+ module Shared
3
+ module Service
4
+ class Sort
5
+ attr_accessor :field, :how
6
+
7
+ def initialize(field, how)
8
+ @field = field
9
+ @how = how
10
+ end
11
+
12
+ def to_s
13
+ "#{field} #{how}"
14
+ end
15
+
16
+ def to_xml
17
+ "<SortByColumn sortOrder=\"#{how}\">#{field}</SortByColumn>"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  module Quickeebooks
2
2
 
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
 
5
5
  end
@@ -7,11 +7,7 @@ module Quickeebooks
7
7
  class Clazz < Quickeebooks::Windows::Service::ServiceBase
8
8
 
9
9
  def list(filters = [], page = 1, per_page = 20, sort = nil, options = {})
10
- custom_field_query = '<?xml version="1.0" encoding="utf-8"?>'
11
- custom_field_query += '<ClassQuery xmlns="http://www.intuit.com/sb/cdm/v2">'
12
- custom_field_query += "<StartPage>#{page}</StartPage><ChunkSize>#{per_page}</ChunkSize>"
13
- custom_field_query += '</ClassQuery>'
14
- fetch_collection(Quickeebooks::Windows::Model::Clazz, custom_field_query.strip, filters, page, per_page, sort, options)
10
+ fetch_collection(Quickeebooks::Windows::Model::Clazz, nil, filters, page, per_page, sort, options)
15
11
  end
16
12
 
17
13
  end
@@ -6,21 +6,17 @@ module Quickeebooks
6
6
  class Customer < Quickeebooks::Windows::Service::ServiceBase
7
7
 
8
8
  def list(filters = [], page = 1, per_page = 20, sort = nil, options = {})
9
- custom_field_query = '<?xml version="1.0" encoding="utf-8"?>'
10
- custom_field_query += '<CustomerQuery xmlns="http://www.intuit.com/sb/cdm/v2">'
11
- custom_field_query += "<StartPage>#{page}</StartPage><ChunkSize>#{per_page}</ChunkSize>"
12
- custom_field_query += '</CustomerQuery>'
13
- fetch_collection(Quickeebooks::Windows::Model::Customer, custom_field_query.strip, filters, page, per_page, sort, options)
9
+ fetch_collection(Quickeebooks::Windows::Model::Customer, nil, filters, page, per_page, sort, options)
14
10
  end
15
-
11
+
16
12
  def fetch_by_id(id, idDomain = 'QB', options = {})
17
13
  url = "#{url_for_resource(Quickeebooks::Windows::Model::Customer::REST_RESOURCE)}/#{id}"
18
14
  fetch_object(Quickeebooks::Windows::Model::Customer, url, {:idDomain => idDomain})
19
15
  end
20
-
16
+
21
17
  def create(customer)
22
18
  raise InvalidModelException unless customer.valid_for_create?
23
-
19
+
24
20
  # XML is a wrapped 'object' where the type is specified as an attribute
25
21
  # <Object xsi:type="Invoice">
26
22
  xml_node = customer.to_xml(:name => 'Object')
@@ -33,11 +29,11 @@ module Quickeebooks
33
29
  XML
34
30
  perform_write(Quickeebooks::Windows::Model::Customer, xml)
35
31
  end
36
-
32
+
37
33
  def update(customer)
38
34
  # XML is a wrapped 'object' where the type is specified as an attribute
39
35
  # <Object xsi:type="Invoice">
40
-
36
+
41
37
  # Intuit requires that some fields are unset / do not exist.
42
38
  customer.meta_data = nil
43
39
  customer.external_key = nil
@@ -49,15 +45,15 @@ module Quickeebooks
49
45
  if customer.email
50
46
  customer.email.id = nil
51
47
  end
52
-
48
+
53
49
  if customer.phones
54
50
  customer.phones.each {|phone| phone.id = nil }
55
51
  end
56
-
52
+
57
53
  if customer.web_site
58
54
  customer.web_site.id = nil
59
55
  end
60
-
56
+
61
57
  xml_node = customer.to_xml(:name => 'Object')
62
58
  xml_node.set_attribute('xsi:type', 'Customer')
63
59
  xml = <<-XML
@@ -7,10 +7,7 @@ module Quickeebooks
7
7
  class Item < Quickeebooks::Windows::Service::ServiceBase
8
8
 
9
9
  def list(filters = [], page = 1, per_page = 20, sort = nil, options = {})
10
- custom_field_query = '<?xml version="1.0" encoding="utf-8"?>'
11
- custom_field_query += '<ItemQuery xmlns="http://www.intuit.com/sb/cdm/v2">'
12
- custom_field_query += "<StartPage>#{page}</StartPage><ChunkSize>#{per_page}</ChunkSize>"
13
- custom_field_query += '<CustomFieldEnable>true</CustomFieldEnable></ItemQuery>'
10
+ custom_field_query = '<CustomFieldEnable>true</CustomFieldEnable>'
14
11
  fetch_collection(Quickeebooks::Windows::Model::Item, custom_field_query.strip, filters, page, per_page, sort, options)
15
12
  end
16
13
 
@@ -30,6 +27,6 @@ module Quickeebooks
30
27
 
31
28
  end
32
29
  end
33
-
30
+
34
31
  end
35
32
  end