quickbooks-ruby 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29ef312218c64559e66c1e6809607a401580e890
4
- data.tar.gz: 0289d2568a1693c609eac8180be21f1b89bd605b
3
+ metadata.gz: 6f4883102897a891ec4461cf30ea0e193aeae3e0
4
+ data.tar.gz: 060b71166e7cf0c1d44c9fef3f6f6d776863cdb5
5
5
  SHA512:
6
- metadata.gz: 0bef7a00293d97267adad435239a57c0f477ec5985c291c8251c8084e5776ce9179e490f54cc0d6d84f4488ff0ee8b83973dc26133709ad1c0289aaa299584c9
7
- data.tar.gz: 687fb9ba0c4d6ec042f644864430ab5987b9ef07e60df23715326e43202e71d3e0bff606717c871a79dd9a3be43fc65c9b7c6f80645c775aa75096f52d915330
6
+ metadata.gz: f563e31ee5eb5614a823409262cc380876c8f3f61527eac6c4110ae1514d49aba5d1ee09b20ca58064d52db0bb39c6a4f3659fd8f4240d83dcc97e0bc992ec3f
7
+ data.tar.gz: e710072fff70fad89c32496dddc544945e51fc4c26c7de0f151d656a96763567e0cb8825ebe2e47c0b238a924a65bb9815ae71957d78802b2ec4bdd811af4c2f
@@ -10,6 +10,7 @@ require 'oauth'
10
10
  require 'quickbooks/util/logging'
11
11
  require 'quickbooks/util/class_util'
12
12
  require 'quickbooks/util/http_encoding_helper'
13
+ require 'quickbooks/util/name_entity'
13
14
 
14
15
  #== Models
15
16
  require 'quickbooks/model/base_model'
@@ -26,8 +27,8 @@ require 'quickbooks/model/item'
26
27
  require 'quickbooks/model/account'
27
28
  require 'quickbooks/model/check_payment'
28
29
  require 'quickbooks/model/credit_card_payment'
29
-
30
30
  require 'quickbooks/model/telephone_number'
31
+ require 'quickbooks/model/other_contact_info'
31
32
  require 'quickbooks/model/email_address'
32
33
  require 'quickbooks/model/web_site_address'
33
34
  require 'quickbooks/model/physical_address'
@@ -45,6 +46,8 @@ require 'quickbooks/model/bill_payment_line_item'
45
46
  require 'quickbooks/model/bill_payment_check'
46
47
  require 'quickbooks/model/bill_payment_credit_card'
47
48
  require 'quickbooks/model/bill_payment'
49
+ require 'quickbooks/model/vendor'
50
+ require 'quickbooks/model/employee'
48
51
 
49
52
  #== Services
50
53
  require 'quickbooks/service/base_service'
@@ -59,6 +62,8 @@ require 'quickbooks/service/payment_method'
59
62
  require 'quickbooks/service/credit_memo'
60
63
  require 'quickbooks/service/bill'
61
64
  require 'quickbooks/service/bill_payment'
65
+ require 'quickbooks/service/vendor'
66
+ require 'quickbooks/service/employee'
62
67
 
63
68
  unless Quickbooks::Util::ClassUtil.defined?("InvalidModelException")
64
69
  class InvalidModelException < StandardError; end
@@ -45,7 +45,6 @@ module Quickbooks
45
45
  #== Validations
46
46
  validates_inclusion_of :classification, :in => ACCOUNT_CLASSIFICATION
47
47
  validates_length_of :name, :minimum => 1, :maximum => 100
48
- validates_length_of :description, :minimum => 1, :maximum => 100
49
48
  validate :name_cannot_contain_invalid_characters
50
49
 
51
50
  def name_cannot_contain_invalid_characters
@@ -13,6 +13,8 @@ module Quickbooks
13
13
  XML_COLLECTION_NODE = "Customer"
14
14
  XML_NODE = "Customer"
15
15
  REST_RESOURCE = 'customer'
16
+ include NameEntity::Quality
17
+ include NameEntity::PermitAlterations
16
18
 
17
19
  xml_name XML_NODE
18
20
  xml_accessor :id, :from => 'Id', :as => Integer
@@ -56,10 +58,6 @@ module Quickbooks
56
58
 
57
59
  reference_setters :parent_ref, :sales_term_ref, :payment_method_ref
58
60
 
59
- def active?
60
- active.to_s == 'true'
61
- end
62
-
63
61
  def job?
64
62
  job.to_s == 'true'
65
63
  end
@@ -71,51 +69,6 @@ module Quickbooks
71
69
  def taxable?
72
70
  taxable.to_s == 'true'
73
71
  end
74
-
75
- def valid_for_update?
76
- if sync_token.nil?
77
- errors.add(:sync_token, "Missing required attribute SyncToken for update")
78
- end
79
- errors.empty?
80
- end
81
-
82
- def valid_for_create?
83
- valid?
84
- errors.empty?
85
- end
86
-
87
- def email_address=(email_address)
88
- self.primary_email_address = EmailAddress.new(email_address)
89
- end
90
-
91
- def email_address
92
- primary_email_address
93
- end
94
-
95
- # To delete an account Intuit requires we provide Id and SyncToken fields
96
- def valid_for_deletion?
97
- return false if(id.nil? || sync_token.nil?)
98
- id.to_i > 0 && !sync_token.to_s.empty? && sync_token.to_i >= 0
99
- end
100
-
101
- def names_cannot_contain_invalid_characters
102
- [:display_name, :given_name, :middle_name, :family_name, :print_on_check_name].each do |property|
103
- value = send(property).to_s
104
- if value.index(':')
105
- errors.add(property, ":#{property} cannot contain a colon (:).")
106
- end
107
- end
108
- end
109
-
110
- def email_address_is_valid
111
- if primary_email_address
112
- address = primary_email_address.address
113
- unless address.index('@') && address.index('.')
114
- errors.add(:primary_email_address, "Email address must contain @ and . (dot)")
115
- end
116
- end
117
- end
118
-
119
72
  end
120
73
  end
121
- end
74
+ end
@@ -0,0 +1,47 @@
1
+ # == Business Rules
2
+ # * DisplayName, GivenName, MiddleName, FamilyName, and PrintOnCheckName must not contain a colon (":")
3
+ # * DisplayName must be unique across all other customers, employees, vendors, and other names.
4
+
5
+ module Quickbooks
6
+ module Model
7
+ class Employee < BaseModel
8
+ XML_COLLECTION_NODE = "Employee"
9
+ XML_NODE = "Employee"
10
+ REST_RESOURCE = 'employee'
11
+ include NameEntity::Quality
12
+ include NameEntity::PermitAlterations
13
+
14
+ xml_name XML_NODE
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 => MetaData
18
+ xml_accessor :organization?, :from => 'Organization'
19
+ xml_accessor :title, :from => 'Title'
20
+ xml_accessor :given_name, :from => 'GivenName'
21
+ xml_accessor :middle_name, :from => 'MiddleName'
22
+ xml_accessor :family_name, :from => 'FamilyName'
23
+ xml_accessor :suffix, :from => 'Suffix'
24
+ xml_accessor :display_name, :from => 'DisplayName'
25
+ xml_accessor :print_on_check_name, :from => 'PrintOnCheckName'
26
+ xml_accessor :active, :from => 'Active'
27
+ xml_accessor :primary_phone, :from => 'PrimaryPhone', :as => TelephoneNumber
28
+ xml_accessor :mobile_phone, :from => 'Mobile', :as => TelephoneNumber
29
+ xml_accessor :primary_email_address, :from => 'PrimaryEmailAddr', :as => EmailAddress
30
+ xml_accessor :number, :from => 'EmployeeNumber', :as => Integer
31
+ xml_accessor :ssn, :from => 'SSN'
32
+ xml_accessor :address, :from => 'PrimaryAddr', :as => PhysicalAddress
33
+ xml_accessor :billable?, :from => 'BillableTime'
34
+ xml_accessor :billable_rate, :from => 'BillRate', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
35
+ xml_accessor :birth_date, :from => 'BirthDate', :as => Date
36
+ xml_accessor :gender, :from => 'Gender'
37
+ xml_accessor :hired_date, :from => 'HiredDate', :as => Date
38
+ xml_accessor :released_date, :from => 'ReleasedDate', :as => Date
39
+
40
+ #== Validations
41
+ validate :names_cannot_contain_invalid_characters
42
+ validate :email_address_is_valid
43
+
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,8 @@
1
+ module Quickbooks
2
+ module Model
3
+ class OtherContactInfo < BaseModel
4
+ xml_accessor :type, :from => 'Type'
5
+ xml_accessor :telephone, :from => 'Telephone', :as => TelephoneNumber
6
+ end
7
+ end
8
+ end
@@ -28,6 +28,9 @@ module Quickbooks
28
28
 
29
29
  xml_accessor :deposit_to_account_ref, :from => 'DepositToAccountRef', :as => BaseReference
30
30
 
31
+ xml_accessor :customer_memo, :from => 'CustomerMemo'
32
+ xml_accessor :private_note, :from => 'PrivateNote'
33
+
31
34
  # readonly
32
35
  xml_accessor :total, :from => 'TotalAmt', :as => BigDecimal
33
36
 
@@ -0,0 +1,52 @@
1
+ # == Business Rules
2
+ # * The DisplayName, GivenName, MiddleName, FamilyName, and PrintOnCheckName attributes must not contain a colon,":".
3
+ # * The DisplayName attribute must be unique across all other customers, employees, vendors, and other names.
4
+ # * The PrimaryEmailAddress attribute must contain an at sign, "@," and dot, ".".
5
+ # * Either the DisplayName attribute or at least one of Title, GivenName, MiddleName, FamilyName, Suffix, or FullyQualifiedName attributes are required during create.
6
+
7
+ module Quickbooks
8
+ module Model
9
+ class Vendor < BaseModel
10
+ XML_COLLECTION_NODE = "Vendor"
11
+ XML_NODE = "Vendor"
12
+ REST_RESOURCE = 'vendor'
13
+ include NameEntity::Quality
14
+ include NameEntity::PermitAlterations
15
+
16
+ xml_name XML_NODE
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 :title, :from => 'Title'
21
+ xml_accessor :given_name, :from => 'GivenName'
22
+ xml_accessor :middle_name, :from => 'MiddleName'
23
+ xml_accessor :family_name, :from => 'FamilyName'
24
+ xml_accessor :suffix, :from => 'Suffix'
25
+ xml_accessor :company_name, :from => 'CompanyName'
26
+ xml_accessor :display_name, :from => 'DisplayName'
27
+ xml_accessor :print_on_check_name, :from => 'PrintOnCheckName'
28
+ xml_accessor :active, :from => 'Active'
29
+ xml_accessor :primary_phone, :from => 'PrimaryPhone', :as => TelephoneNumber
30
+ xml_accessor :alternate_phone, :from => 'AlternatePhone', :as => TelephoneNumber
31
+ xml_accessor :mobile_phone, :from => 'Mobile', :as => TelephoneNumber
32
+ xml_accessor :fax_phone, :from => 'Fax', :as => TelephoneNumber
33
+ xml_accessor :primary_email_address, :from => 'PrimaryEmailAddr', :as => EmailAddress
34
+ xml_accessor :web_site, :from => 'WebAddr', :as => WebSiteAddress
35
+ xml_accessor :billing_address, :from => 'BillAddr', :as => PhysicalAddress
36
+ xml_accessor :other_contact_info, :from => 'OtherContactInfo', :as => OtherContactInfo
37
+ xml_accessor :tax_identifier, :from => 'TaxIdentifier'
38
+ xml_accessor :term_ref, :from => 'TermRef', :as => BaseReference
39
+ xml_accessor :balance, :from => 'Balance', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
40
+ xml_accessor :account_number, :from => 'AcctNum'
41
+ xml_accessor :is_1099?, :from => 'Vendor1099'
42
+ xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
43
+
44
+ #== Validations
45
+ validate :names_cannot_contain_invalid_characters
46
+ validate :email_address_is_valid
47
+
48
+ reference_setters :term_ref
49
+
50
+ end
51
+ end
52
+ end
@@ -91,13 +91,8 @@ module Quickbooks
91
91
  page = options.fetch(:page, 1)
92
92
  per_page = options.fetch(:per_page, 20)
93
93
 
94
- if page == 1
95
- start_position = 1
96
- else
97
- start_position = (page * per_page) + 1 # page=2, per_page=10 then we want to start at 11
98
- end
99
-
100
- max_results = (page * per_page)
94
+ start_position = ((page - 1) * per_page) + 1 # page=2, per_page=10 then we want to start at 11
95
+ max_results = per_page
101
96
  response = do_http_get(url_for_query(query, start_position, max_results))
102
97
 
103
98
  parse_collection(response, model)
@@ -0,0 +1,29 @@
1
+ module Quickbooks
2
+ module Service
3
+ class Employee < BaseService
4
+ include ServiceCrud
5
+
6
+ # override update as sparse is not supported
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
9
+ super(entity, options)
10
+ end
11
+
12
+ def delete(employee)
13
+ employee.active = false
14
+ update(employee, :sparse => false)
15
+ end
16
+
17
+ private
18
+
19
+ def default_model_query
20
+ "SELECT * FROM EMPLOYEE"
21
+ end
22
+
23
+ def model
24
+ Quickbooks::Model::Employee
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module Quickbooks
2
+ module Service
3
+ class Vendor < BaseService
4
+ include ServiceCrud
5
+
6
+ # override update as sparse is not supported
7
+ def update(entity, options = {})
8
+ raise InvalidModelException.new('Vendor sparse update is not supported by Intuit at this time') if options[:sparse] && options[:sparse] == true
9
+ super(entity, options)
10
+ end
11
+
12
+ def delete(vendor)
13
+ vendor.active = false
14
+ update(vendor, :sparse => false)
15
+ end
16
+
17
+ private
18
+
19
+ def default_model_query
20
+ "SELECT * FROM VENDOR"
21
+ end
22
+
23
+ def model
24
+ Quickbooks::Model::Vendor
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,54 @@
1
+ module NameEntity
2
+
3
+ module Quality
4
+ def email_address=(email_address)
5
+ self.primary_email_address = Quickbooks::Model::EmailAddress.new(email_address)
6
+ end
7
+
8
+ def email_address
9
+ primary_email_address
10
+ end
11
+
12
+ def names_cannot_contain_invalid_characters
13
+ [:display_name, :given_name, :middle_name, :family_name, :print_on_check_name].each do |property|
14
+ value = send(property).to_s
15
+ if value.index(':')
16
+ errors.add(property, ":#{property} cannot contain a colon (:).")
17
+ end
18
+ end
19
+ end
20
+
21
+ def email_address_is_valid
22
+ if primary_email_address
23
+ address = primary_email_address.address
24
+ unless address.index('@') && address.index('.')
25
+ errors.add(:primary_email_address, "Email address must contain @ and . (dot)")
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ module PermitAlterations
32
+ def active?
33
+ active.to_s == 'true'
34
+ end
35
+
36
+ def valid_for_update?
37
+ if sync_token.nil?
38
+ errors.add(:sync_token, "Missing required attribute SyncToken for update")
39
+ end
40
+ errors.empty?
41
+ end
42
+
43
+ def valid_for_create?
44
+ valid?
45
+ errors.empty?
46
+ end
47
+
48
+ # To delete an account Intuit requires we provide Id and SyncToken fields
49
+ def valid_for_deletion?
50
+ return false if(id.nil? || sync_token.nil?)
51
+ id.to_i > 0 && !sync_token.to_s.empty? && sync_token.to_i >= 0
52
+ end
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  module Quickbooks
2
2
 
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
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.4
4
+ version: 0.0.5
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-15 00:00:00.000000000 Z
11
+ date: 2014-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
@@ -188,12 +188,14 @@ files:
188
188
  - lib/quickbooks/model/customer.rb
189
189
  - lib/quickbooks/model/discount_override.rb
190
190
  - lib/quickbooks/model/email_address.rb
191
+ - lib/quickbooks/model/employee.rb
191
192
  - lib/quickbooks/model/invoice.rb
192
193
  - lib/quickbooks/model/invoice_line_item.rb
193
194
  - lib/quickbooks/model/item.rb
194
195
  - lib/quickbooks/model/line.rb
195
196
  - lib/quickbooks/model/linked_transaction.rb
196
197
  - lib/quickbooks/model/meta_data.rb
198
+ - lib/quickbooks/model/other_contact_info.rb
197
199
  - lib/quickbooks/model/payment_line_detail.rb
198
200
  - lib/quickbooks/model/payment_method.rb
199
201
  - lib/quickbooks/model/physical_address.rb
@@ -201,6 +203,7 @@ files:
201
203
  - lib/quickbooks/model/sales_receipt.rb
202
204
  - lib/quickbooks/model/sub_total_line_detail.rb
203
205
  - lib/quickbooks/model/telephone_number.rb
206
+ - lib/quickbooks/model/vendor.rb
204
207
  - lib/quickbooks/model/web_site_address.rb
205
208
  - lib/quickbooks/service/account.rb
206
209
  - lib/quickbooks/service/base_service.rb
@@ -209,14 +212,17 @@ files:
209
212
  - lib/quickbooks/service/company_info.rb
210
213
  - lib/quickbooks/service/credit_memo.rb
211
214
  - lib/quickbooks/service/customer.rb
215
+ - lib/quickbooks/service/employee.rb
212
216
  - lib/quickbooks/service/invoice.rb
213
217
  - lib/quickbooks/service/item.rb
214
218
  - lib/quickbooks/service/payment_method.rb
215
219
  - lib/quickbooks/service/sales_receipt.rb
216
220
  - lib/quickbooks/service/service_crud.rb
221
+ - lib/quickbooks/service/vendor.rb
217
222
  - lib/quickbooks/util/class_util.rb
218
223
  - lib/quickbooks/util/http_encoding_helper.rb
219
224
  - lib/quickbooks/util/logging.rb
225
+ - lib/quickbooks/util/name_entity.rb
220
226
  - lib/quickbooks/version.rb
221
227
  - lib/quickbooks-ruby.rb
222
228
  homepage: http://github.com/ruckus/quickbooks-ruby