quickbooks-ruby 1.0.6 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c912118ddd84fcffd9348f9c80986c5acd65645f3f1df65175ff091c13a3478b
4
- data.tar.gz: '0739b9834c0ac6f1a46c8741acf6742970b490a7c6648f40c20361036fd9bb0c'
3
+ metadata.gz: 59f6b50352335b6f8142b4b2e6ab4f3057104998119ff634f436bbf64e5009d4
4
+ data.tar.gz: c6b0639561b040957fcef550fc6e117d0f3327f522c3ec8fc87edb622ef23523
5
5
  SHA512:
6
- metadata.gz: 9aeb39c90d47fa2e2319b0a66ed44b2e61627642a6302c585206483ee6a5ced61fad94170a9c2b7f8ccfcf66b4f9940a4fcb5000f5eb1c513719ff9639712159
7
- data.tar.gz: de3b723c54f1371baa1e8b0b7f20ef4c8a70cdfbd4687d2ff437bb6501337b9f20c2627329ba22d73707af99d686848c84ea14315d034116449eec0eb5dba1cb
6
+ metadata.gz: e27ca054b8ad9281542eebcfa83fdcc6ec7a3855b7afc54fe2bb62d0981de4b1ef840b6e77ba11c164f6092263d6aa3e752b7fe0e3fc79baa747cc559a0e07cc
7
+ data.tar.gz: 0b354dd455d03cf7625f9ac0fd8cae75e928aa52bc3e5edaf2ca5a4bea5b148cef9ef0122430c360bc1e14b6130cc57e30b84caaac7c13dd2293bac8fa0ba23d
@@ -75,6 +75,7 @@ require 'quickbooks/model/invoice_line_item'
75
75
  require 'quickbooks/model/invoice_group_line_detail'
76
76
  require 'quickbooks/model/company_info'
77
77
  require 'quickbooks/model/company_currency'
78
+ require 'quickbooks/model/customer_type'
78
79
  require 'quickbooks/model/customer'
79
80
  require 'quickbooks/model/delivery_info'
80
81
  require 'quickbooks/model/sales_receipt'
@@ -137,6 +138,8 @@ require 'quickbooks/service/class'
137
138
  require 'quickbooks/service/attachable'
138
139
  require 'quickbooks/service/company_info'
139
140
  require 'quickbooks/service/company_currency'
141
+ require 'quickbooks/service/customer_type'
142
+ require 'quickbooks/service/custom_field'
140
143
  require 'quickbooks/service/customer'
141
144
  require 'quickbooks/service/department'
142
145
  require 'quickbooks/service/invoice'
@@ -188,6 +191,7 @@ Faraday::Middleware.register_middleware :gzip => lambda { Gzip }
188
191
  module Quickbooks
189
192
  @@sandbox_mode = false
190
193
  @@logger = nil
194
+ @@minorversion = 47
191
195
 
192
196
  class << self
193
197
  def sandbox_mode
@@ -198,6 +202,14 @@ module Quickbooks
198
202
  @@sandbox_mode = sandbox_mode
199
203
  end
200
204
 
205
+ def minorversion=(v)
206
+ @@minorversion = v
207
+ end
208
+
209
+ def minorversion
210
+ @@minorversion
211
+ end
212
+
201
213
  def logger
202
214
  @@logger ||= ::Logger.new($stdout) # TODO: replace with a real log file
203
215
  end
@@ -246,6 +258,7 @@ module Quickbooks
246
258
  class TooManyRequests < Error; end
247
259
  class ServiceUnavailable < Error; end
248
260
  class MissingRealmError < Error; end
261
+ class UnsupportedOperation < Error; end
249
262
 
250
263
  class IntuitRequestException < Error
251
264
  attr_accessor :message, :code, :detail, :type, :intuit_tid, :request_xml, :request_json
@@ -23,6 +23,8 @@ class Gzip < Faraday::Middleware
23
23
  def call(env)
24
24
  env[:request_headers][ACCEPT_ENCODING] ||= SUPPORTED_ENCODINGS
25
25
  @app.call(env).on_complete do |response_env|
26
+ break if response_env[:response_headers].nil?
27
+
26
28
  case response_env[:response_headers][CONTENT_ENCODING]
27
29
  when 'gzip'
28
30
  reset_body(response_env, &method(:uncompress_gzip))
@@ -4,7 +4,6 @@ module Quickbooks
4
4
  XML_COLLECTION_NODE = "Account"
5
5
  XML_NODE = "Account"
6
6
  REST_RESOURCE = 'account'
7
- MINORVERSION = 13
8
7
 
9
8
  ASSET = 'Asset'
10
9
  EQUITY = 'Equity'
@@ -16,6 +16,7 @@ module Quickbooks
16
16
  xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
17
17
 
18
18
  xml_accessor :line_items, :from => 'Line', :as => [BillLineItem]
19
+ xml_accessor :txn_tax_detail, :from => 'TxnTaxDetail', :as => TransactionTaxDetail
19
20
 
20
21
  xml_accessor :private_note, :from => 'PrivateNote'
21
22
 
@@ -16,8 +16,6 @@ module Quickbooks
16
16
  include NameEntity::Quality
17
17
  include NameEntity::PermitAlterations
18
18
 
19
- MINORVERSION = 33
20
-
21
19
  xml_name XML_NODE
22
20
  xml_accessor :id, :from => 'Id'
23
21
  xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
@@ -56,12 +54,15 @@ module Quickbooks
56
54
  xml_accessor :notes, :from => 'Notes'
57
55
  xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
58
56
  xml_accessor :tax_exemption_reason_id, :from => 'TaxExemptionReasonId'
57
+ xml_accessor :primary_tax_identifier, :from => 'PrimaryTaxIdentifier'
58
+ xml_accessor :customer_type_ref, :from => 'CustomerTypeRef', :as => BaseReference
59
59
 
60
60
  #== Validations
61
61
  validate :names_cannot_contain_invalid_characters
62
62
  validate :email_address_is_valid
63
63
 
64
- reference_setters :parent_ref, :sales_term_ref, :payment_method_ref, :default_tax_code_ref, :currency_ref
64
+ reference_setters :parent_ref, :sales_term_ref, :payment_method_ref, :default_tax_code_ref, :currency_ref,
65
+ :customer_type_ref
65
66
 
66
67
  def job?
67
68
  job.to_s == 'true'
@@ -0,0 +1,15 @@
1
+ module Quickbooks
2
+ module Model
3
+ class CustomerType < BaseModel
4
+ XML_COLLECTION_NODE = "CustomerType"
5
+ XML_NODE = "CustomerType"
6
+ REST_RESOURCE = 'customertype'
7
+
8
+ xml_accessor :id, :from => 'Id'
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
+ end
14
+ end
15
+ end
@@ -17,7 +17,6 @@ module Quickbooks
17
17
  XML_COLLECTION_NODE = "Invoice"
18
18
  XML_NODE = "Invoice"
19
19
  EMAIL_STATUS_NEED_TO_SEND = 'NeedToSend'
20
- MINORVERSION = 37
21
20
 
22
21
  xml_accessor :id, :from => 'Id'
23
22
  xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
@@ -10,7 +10,6 @@ module Quickbooks
10
10
  XML_COLLECTION_NODE = "Item"
11
11
  XML_NODE = "Item"
12
12
  REST_RESOURCE = 'item'
13
- MINORVERSION = 33
14
13
 
15
14
  INVENTORY_TYPE = 'Inventory'
16
15
  NON_INVENTORY_TYPE = 'NonInventory'
@@ -31,6 +30,7 @@ module Quickbooks
31
30
  xml_accessor :level, :from => 'Level', :as => Integer
32
31
  xml_accessor :pref_vendor_ref, :from => 'PrefVendorRef', :as => BaseReference
33
32
  xml_accessor :tax_classification_ref, :from => 'TaxClassificationRef', :as => BaseReference
33
+ xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
34
34
 
35
35
  # read-only
36
36
  xml_accessor :fully_qualified_name, :from => 'FullyQualifiedName'
@@ -52,13 +52,11 @@ module Quickbooks
52
52
  xml_accessor :inv_start_date, :from => 'InvStartDate', :as => Date
53
53
  xml_accessor :custom_fields, :from => "CustomField", as: [CustomField]
54
54
  xml_accessor :print_grouped_items?, :from => 'PrintGroupedItems'
55
-
56
-
57
55
  xml_accessor :item_group_details, :from => 'ItemGroupDetail', :as => ItemGroupDetail
58
56
 
59
57
  reference_setters :parent_ref, :income_account_ref, :expense_account_ref
60
58
  reference_setters :asset_account_ref, :sales_tax_code_ref, :purchase_tax_code_ref
61
- reference_setters :pref_vendor_ref, :tax_classification_ref
59
+ reference_setters :pref_vendor_ref, :tax_classification_ref, :class_ref
62
60
 
63
61
  #== Validations
64
62
  validates_length_of :name, :minimum => 1
@@ -4,7 +4,6 @@ module Quickbooks
4
4
  XML_COLLECTION_NODE = "Preferences"
5
5
  XML_NODE = "Preferences"
6
6
  REST_RESOURCE = 'preferences'
7
- MINORVERSION = 32
8
7
 
9
8
  xml_name XML_NODE
10
9
 
@@ -8,7 +8,6 @@ module Quickbooks
8
8
  REST_RESOURCE = 'purchaseorder'
9
9
  XML_COLLECTION_NODE = "PurchaseOrder"
10
10
  XML_NODE = "PurchaseOrder"
11
- MINORVERSION = 45
12
11
 
13
12
  xml_accessor :id, :from => 'Id'
14
13
  xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
@@ -38,7 +38,7 @@ module Quickbooks
38
38
  value = el.attr('value')
39
39
 
40
40
  next nil if value.blank?
41
- next value if value.to_s.match(/^\d+$|^\d+.\d+$|^-\d+|^-\d+.\d+$|^.\d+$/).nil?
41
+ next value if value.to_s.match(/^\d+$|^\d+\.\d+$|^-\d+|^-\d+\.\d+$|^\.\d+$/).nil?
42
42
  BigDecimal(value)
43
43
  end
44
44
  end
@@ -23,7 +23,8 @@ module Quickbooks
23
23
  def disconnect
24
24
  conn = Faraday.new
25
25
  conn.basic_auth oauth.client.id, oauth.client.secret
26
- response = conn.post(DISCONNECT_URL, token: oauth.refresh_token || oauth.token)
26
+ url = "#{DISCONNECT_URL}?minorversion=#{Quickbooks.minorversion}"
27
+ response = conn.post(url, token: oauth.refresh_token || oauth.token)
27
28
 
28
29
  if response.success?
29
30
  Quickbooks::Model::AccessTokenResponse.new(error_code: "0")
@@ -7,11 +7,6 @@ module Quickbooks
7
7
  update(account, :sparse => true)
8
8
  end
9
9
 
10
- def url_for_query(query = nil, start_position = 1, max_results = 20, options = {})
11
- url = super(query, start_position, max_results, options)
12
- "#{url}&minorversion=#{Quickbooks::Model::Account::MINORVERSION}"
13
- end
14
-
15
10
  private
16
11
 
17
12
  def model
@@ -9,6 +9,9 @@ module Quickbooks
9
9
  attr_reader :base_uri
10
10
  attr_reader :last_response_xml
11
11
  attr_reader :last_response_intuit_tid
12
+ attr_accessor :before_request
13
+ attr_accessor :around_request
14
+ attr_accessor :after_request
12
15
 
13
16
  XML_NS = %{xmlns="http://schema.intuit.com/finance/v3"}
14
17
  HTTP_CONTENT_TYPE = 'application/xml'
@@ -17,6 +20,8 @@ module Quickbooks
17
20
  BASE_DOMAIN = 'quickbooks.api.intuit.com'
18
21
  SANDBOX_DOMAIN = 'sandbox-quickbooks.api.intuit.com'
19
22
 
23
+ RequestInfo = Struct.new(:url, :headers, :body, :method)
24
+
20
25
  def initialize(attributes = {})
21
26
  domain = Quickbooks.sandbox_mode ? SANDBOX_DOMAIN : BASE_DOMAIN
22
27
  @base_uri = "https://#{domain}/v3/company"
@@ -224,6 +229,8 @@ module Quickbooks
224
229
  body['file_metadata_0'] = param_part
225
230
  end
226
231
 
232
+ url = add_query_string_to_url(url, {})
233
+
227
234
  do_http(:upload, url, body, headers)
228
235
  end
229
236
 
@@ -247,17 +254,24 @@ module Quickbooks
247
254
  log_request_body(body)
248
255
  log "REQUEST HEADERS = #{headers.inspect}"
249
256
 
250
- raw_response = case method
251
- when :get
252
- oauth_get(url, headers)
253
- when :post
254
- oauth_post(url, body, headers)
255
- when :upload
256
- oauth_post_with_multipart(url, body, headers)
257
- else
258
- raise "Do not know how to perform that HTTP operation"
257
+ request_info = RequestInfo.new(url, headers, body, method)
258
+ before_request.call(request_info) if before_request
259
+
260
+ raw_response = with_around_request(request_info) do
261
+ case method
262
+ when :get
263
+ oauth_get(url, headers)
264
+ when :post
265
+ oauth_post(url, body, headers)
266
+ when :upload
267
+ oauth_post_with_multipart(url, body, headers)
268
+ else
269
+ raise "Do not know how to perform that HTTP operation"
270
+ end
259
271
  end
260
272
 
273
+ after_request.call(request_info, raw_response.body) if after_request
274
+
261
275
  response = Quickbooks::Service::Responses::OAuthHttpResponse.wrap(raw_response)
262
276
  log "------ QUICKBOOKS-RUBY RESPONSE ------"
263
277
  log "RESPONSE CODE = #{response.code}"
@@ -280,7 +294,9 @@ module Quickbooks
280
294
  @oauth.post_with_multipart(url, headers: headers, body: body, raise_errors: false)
281
295
  end
282
296
 
283
- def add_query_string_to_url(url, params)
297
+ def add_query_string_to_url(url, params = {})
298
+ params ||= {}
299
+ params['minorversion'] = Quickbooks.minorversion
284
300
  if params.is_a?(Hash) && !params.empty?
285
301
  keyvalues = params.collect { |k| "#{k.first}=#{k.last}" }.join("&")
286
302
  delim = url.index("?") != nil ? "&" : "?"
@@ -429,6 +445,13 @@ module Quickbooks
429
445
  error
430
446
  end
431
447
 
448
+ def with_around_request(request_info, &block)
449
+ if around_request
450
+ around_request.call(request_info, &block)
451
+ else
452
+ block.call
453
+ end
454
+ end
432
455
  end
433
456
  end
434
457
  end
@@ -0,0 +1,20 @@
1
+ module Quickbooks
2
+ module Service
3
+ class CustomField < BaseService
4
+
5
+ def delete(customer_type)
6
+ raise Quickbooks::UnsupportedOperation.new('Deleting CustomerType is not supported by Intuit')
7
+ end
8
+
9
+ def create(customer_type)
10
+ raise Quickbooks::UnsupportedOperation.new('Creating/updating CustomerType is not supported by Intuit')
11
+ end
12
+
13
+ private
14
+
15
+ def model
16
+ Quickbooks::Model::CustomField
17
+ end
18
+ end
19
+ end
20
+ end
@@ -7,21 +7,11 @@ module Quickbooks
7
7
  update(customer, :sparse => true)
8
8
  end
9
9
 
10
- def url_for_resource(resource)
11
- url = super(resource)
12
- "#{url}?minorversion=#{Quickbooks::Model::Customer::MINORVERSION}"
13
- end
14
-
15
10
  def fetch_by_id(id, params = {})
16
- url = "#{url_for_base}/customer/#{id}?minorversion=#{Quickbooks::Model::Customer::MINORVERSION}"
11
+ url = "#{url_for_base}/customer/#{id}"
17
12
  fetch_object(model, url, params)
18
13
  end
19
14
 
20
- def url_for_query(query = nil, start_position = 1, max_results = 20, options = {})
21
- url = super(query, start_position, max_results, options)
22
- "#{url}&minorversion=#{Quickbooks::Model::Customer::MINORVERSION}"
23
- end
24
-
25
15
  private
26
16
 
27
17
  def model
@@ -0,0 +1,20 @@
1
+ module Quickbooks
2
+ module Service
3
+ class CustomerType < BaseService
4
+
5
+ def delete(customer_type)
6
+ raise Quickbooks::UnsupportedOperation.new('Deleting CustomerType is not supported by Intuit')
7
+ end
8
+
9
+ def create(customer_type)
10
+ raise Quickbooks::UnsupportedOperation.new('Creating/updating CustomerType is not supported by Intuit')
11
+ end
12
+
13
+ private
14
+
15
+ def model
16
+ Quickbooks::Model::CustomerType
17
+ end
18
+ end
19
+ end
20
+ end
@@ -6,20 +6,11 @@ module Quickbooks
6
6
  delete_by_query_string(invoice)
7
7
  end
8
8
 
9
- def url_for_resource(resource)
10
- url = super(resource)
11
- end
12
-
13
9
  def fetch_by_id(id, params = {})
14
- url = "#{url_for_base}/invoice/#{id}?minorversion=#{Quickbooks::Model::Invoice::MINORVERSION}"
10
+ url = "#{url_for_base}/invoice/#{id}"
15
11
  fetch_object(model, url, params)
16
12
  end
17
13
 
18
- def url_for_query(query = nil, start_position = 1, max_results = 20, options = {})
19
- url = super(query, start_position, max_results, options)
20
- "#{url}&minorversion=#{Quickbooks::Model::Invoice::MINORVERSION}"
21
- end
22
-
23
14
  def send(invoice, email_address=nil)
24
15
  query = email_address.present? ? "?sendTo=#{email_address}" : ""
25
16
  url = "#{url_for_resource(model::REST_RESOURCE)}/#{invoice.id}/send#{query}"
@@ -7,21 +7,11 @@ module Quickbooks
7
7
  update(item, :sparse => true)
8
8
  end
9
9
 
10
- def url_for_resource(resource)
11
- url = super(resource)
12
- "#{url}?minorversion=#{Quickbooks::Model::Item::MINORVERSION}"
13
- end
14
-
15
10
  def fetch_by_id(id, params = {})
16
- url = "#{url_for_base}/item/#{id}?minorversion=#{Quickbooks::Model::Item::MINORVERSION}"
11
+ url = "#{url_for_base}/item/#{id}"
17
12
  fetch_object(model, url, params)
18
13
  end
19
14
 
20
- def url_for_query(query = nil, start_position = 1, max_results = 20, options = {})
21
- url = super(query, start_position, max_results, options)
22
- "#{url}&minorversion=#{Quickbooks::Model::Item::MINORVERSION}"
23
- end
24
-
25
15
  private
26
16
 
27
17
  def model
@@ -2,11 +2,6 @@ module Quickbooks
2
2
  module Service
3
3
  class Preferences < BaseService
4
4
 
5
- def url_for_query(query = nil, start_position = 1, max_results = 20, options = {})
6
- url = super(query, start_position, max_results, options)
7
- "#{url}&minorversion=#{Quickbooks::Model::Preferences::MINORVERSION}"
8
- end
9
-
10
5
  private
11
6
 
12
7
  def model
@@ -8,7 +8,7 @@ module Quickbooks
8
8
 
9
9
  def create(entity, options = {})
10
10
  raise Quickbooks::InvalidModelException.new(entity.errors.full_messages.join(',')) unless entity.valid?
11
- response = do_http(:post, url_for_resource(model.resource_for_singular), entity.to_json, options)
11
+ response = do_http_post(url_for_resource(model.resource_for_singular), entity.to_json, options)
12
12
  if response.code.to_i == 200
13
13
  JSON.parse(response.plain_body)
14
14
  else
@@ -10,26 +10,27 @@ module Quickbooks
10
10
  end
11
11
 
12
12
  def clause(field, operator, value)
13
+ # replace with an escaped backslash
14
+ escape_single_quotes = -> field { field.to_s.gsub("'", "\\\\'") }
15
+
13
16
  value = case value
14
17
  when DateTime, Time
15
18
  value.iso8601
16
19
  when Date
17
20
  value.strftime('%Y-%m-%d')
18
21
  when Array
19
- value = value.map{|v| v.to_s.gsub("'", "\\\\'") }
22
+ value = value.map(&escape_single_quotes)
20
23
  else
21
- # escape single quotes with an escaped backslash
22
- value = value.gsub("'", "\\\\'")
24
+ value = escape_single_quotes.call(value)
23
25
  end
24
26
 
25
27
  if operator.downcase == 'in' && value.is_a?(Array)
26
- value = value.map{|v| "#{VALUE_QUOTE}#{v}#{VALUE_QUOTE}"}
28
+ value = value.map { |v| "#{VALUE_QUOTE}#{v}#{VALUE_QUOTE}" }
27
29
  "#{field} #{operator} (#{value.join(', ')})"
28
30
  else
29
31
  "#{field} #{operator} #{VALUE_QUOTE}#{value}#{VALUE_QUOTE}"
30
32
  end
31
33
  end
32
-
33
34
  end
34
35
  end
35
36
  end
@@ -1,5 +1,5 @@
1
1
  module Quickbooks
2
2
 
3
- VERSION = "1.0.6"
3
+ VERSION = "1.0.11"
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: 1.0.6
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Caughlan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-10 00:00:00.000000000 Z
11
+ date: 2020-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: roxml
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 4.0.0
33
+ version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 4.0.0
40
+ version: '4.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activemodel
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -202,6 +202,7 @@ files:
202
202
  - lib/quickbooks/model/custom_field.rb
203
203
  - lib/quickbooks/model/customer.rb
204
204
  - lib/quickbooks/model/customer_change.rb
205
+ - lib/quickbooks/model/customer_type.rb
205
206
  - lib/quickbooks/model/definition.rb
206
207
  - lib/quickbooks/model/delivery_info.rb
207
208
  - lib/quickbooks/model/department.rb
@@ -293,8 +294,10 @@ files:
293
294
  - lib/quickbooks/service/company_info.rb
294
295
  - lib/quickbooks/service/credit_memo.rb
295
296
  - lib/quickbooks/service/credit_memo_change.rb
297
+ - lib/quickbooks/service/custom_field.rb
296
298
  - lib/quickbooks/service/customer.rb
297
299
  - lib/quickbooks/service/customer_change.rb
300
+ - lib/quickbooks/service/customer_type.rb
298
301
  - lib/quickbooks/service/department.rb
299
302
  - lib/quickbooks/service/deposit.rb
300
303
  - lib/quickbooks/service/employee.rb