quickbooks-ruby 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quickbooks-ruby.rb +11 -10
- data/lib/quickbooks/model/preferences.rb +23 -4
- data/lib/quickbooks/service/base_service.rb +28 -40
- data/lib/quickbooks/service/responses/oauth_http_response.rb +1 -5
- data/lib/quickbooks/util/multipart.rb +0 -72
- data/lib/quickbooks/version.rb +1 -1
- metadata +30 -31
- data/lib/quickbooks/service/responses/oauth1_http_response.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: feb87ae00b9c17019bf64bc3ff8dd6bda994365b1d036a4cdca5ea5a31a8b44e
|
4
|
+
data.tar.gz: 40ddda6954c1a88faa24c496eec92d7f535ae8ef70a4911990417f657dda24de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 550937bea11b0743baf7ebb1cbbb30bf198754459f97ec0e71585da2014b293c310492f977477d24491adefa794f9265f0068560c54a1fad811169aa259776cb
|
7
|
+
data.tar.gz: 4fc10dcd803293bd761a48e6ee560f87006f7563040d1496b7ac4a96fc8b639b136928ab4d4e6207c5a4147371a2cd31172efd96cce7b25e846f0b0e773a855d
|
data/lib/quickbooks-ruby.rb
CHANGED
@@ -6,7 +6,6 @@ require 'cgi'
|
|
6
6
|
require 'uri'
|
7
7
|
require 'date'
|
8
8
|
require 'forwardable'
|
9
|
-
require 'oauth'
|
10
9
|
require 'oauth2'
|
11
10
|
require 'net/http/post/multipart'
|
12
11
|
require 'quickbooks/util/collection'
|
@@ -19,7 +18,6 @@ require 'quickbooks/faraday/middleware/gzip'
|
|
19
18
|
#== OAuth Responses
|
20
19
|
require 'quickbooks/service/responses/oauth_http_response'
|
21
20
|
require 'quickbooks/service/responses/methods'
|
22
|
-
require 'quickbooks/service/responses/oauth1_http_response'
|
23
21
|
require 'quickbooks/service/responses/oauth2_http_response'
|
24
22
|
|
25
23
|
#== Models
|
@@ -231,7 +229,16 @@ module Quickbooks
|
|
231
229
|
|
232
230
|
class Error < StandardError; end
|
233
231
|
class InvalidModelException < Error; end
|
234
|
-
class AuthorizationFailure < Error
|
232
|
+
class AuthorizationFailure < Error
|
233
|
+
attr_accessor :code, :detail, :type
|
234
|
+
|
235
|
+
def initialize(error_hash = {})
|
236
|
+
@code = error_hash[:code]
|
237
|
+
@detail = error_hash[:detail]
|
238
|
+
@type = error_hash[:type]
|
239
|
+
super(error_hash[:message])
|
240
|
+
end
|
241
|
+
end
|
235
242
|
class Forbidden < Error; end
|
236
243
|
class NotFound < Error; end
|
237
244
|
class RequestTooLarge < Error; end
|
@@ -241,7 +248,7 @@ module Quickbooks
|
|
241
248
|
class MissingRealmError < Error; end
|
242
249
|
|
243
250
|
class IntuitRequestException < Error
|
244
|
-
attr_accessor :message, :code, :detail, :type, :request_xml, :request_json
|
251
|
+
attr_accessor :message, :code, :detail, :type, :intuit_tid, :request_xml, :request_json
|
245
252
|
|
246
253
|
def initialize(msg)
|
247
254
|
self.message = msg
|
@@ -249,10 +256,4 @@ module Quickbooks
|
|
249
256
|
end
|
250
257
|
end
|
251
258
|
|
252
|
-
class InvalidOauthAccessTokenObject < StandardError
|
253
|
-
def initialize(access_token)
|
254
|
-
super("Expected access token to be an instance of OAuth::AccessToken or OAuth2::AccessToken, got #{access_token.class}.")
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
259
|
end
|
@@ -4,7 +4,7 @@ module Quickbooks
|
|
4
4
|
XML_COLLECTION_NODE = "Preferences"
|
5
5
|
XML_NODE = "Preferences"
|
6
6
|
REST_RESOURCE = 'preferences'
|
7
|
-
MINORVERSION =
|
7
|
+
MINORVERSION = 32
|
8
8
|
|
9
9
|
xml_name XML_NODE
|
10
10
|
|
@@ -28,9 +28,28 @@ module Quickbooks
|
|
28
28
|
}
|
29
29
|
|
30
30
|
xml_reader :sales_forms, :from => "SalesFormsPrefs", :as => create_preference_class(*%w(
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
AllowDeposit?
|
32
|
+
AllowDiscount?
|
33
|
+
AllowEstimates?
|
34
|
+
AllowServiceDate?
|
35
|
+
AllowShipping?
|
36
|
+
AutoApplyCredit?
|
37
|
+
CustomField?
|
38
|
+
CustomTxnNumbers?
|
39
|
+
DefaultCustomerMessage
|
40
|
+
DefaultDiscountAccount?
|
41
|
+
DefaultShippingAccount?
|
42
|
+
DefaultTerms
|
43
|
+
EmailCopyToCompany?
|
44
|
+
EstimateMessage
|
45
|
+
ETransactionAttachPDF?
|
46
|
+
ETransactionEnabledStatus
|
47
|
+
ETransactionPaymentEnabled?
|
48
|
+
IPNSupportEnabled?
|
49
|
+
SalesEmailBcc
|
50
|
+
SalesEmailCc
|
51
|
+
UsingPriceLevels?
|
52
|
+
UsingProgressInvoicing?
|
34
53
|
)) {
|
35
54
|
xml_reader :custom_fields, :as => [CustomField], :from => 'CustomField', in: 'CustomField'
|
36
55
|
}
|
@@ -7,8 +7,8 @@ module Quickbooks
|
|
7
7
|
attr_accessor :company_id
|
8
8
|
attr_accessor :oauth
|
9
9
|
attr_reader :base_uri
|
10
|
-
attr_reader :last_response_body
|
11
10
|
attr_reader :last_response_xml
|
11
|
+
attr_reader :last_response_intuit_tid
|
12
12
|
|
13
13
|
XML_NS = %{xmlns="http://schema.intuit.com/finance/v3"}
|
14
14
|
HTTP_CONTENT_TYPE = 'application/xml'
|
@@ -37,18 +37,13 @@ module Quickbooks
|
|
37
37
|
@company_id = company_id
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
def oauth_v2?
|
45
|
-
@oauth.is_a? OAuth2::AccessToken
|
46
|
-
end
|
40
|
+
# def oauth_v2?
|
41
|
+
# @oauth.is_a? OAuth2::AccessToken
|
42
|
+
# end
|
47
43
|
|
48
44
|
# [OAuth2] The default Faraday connection does not have gzip or multipart support.
|
49
45
|
# We need to reset the existing connection and build a new one.
|
50
46
|
def rebuild_connection!
|
51
|
-
return unless oauth_v2?
|
52
47
|
@oauth.client.connection = nil
|
53
48
|
@oauth.client.connection.build do |builder|
|
54
49
|
builder.use :gzip
|
@@ -264,37 +259,25 @@ module Quickbooks
|
|
264
259
|
end
|
265
260
|
|
266
261
|
response = Quickbooks::Service::Responses::OAuthHttpResponse.wrap(raw_response)
|
262
|
+
log "------ QUICKBOOKS-RUBY RESPONSE ------"
|
263
|
+
log "RESPONSE CODE = #{response.code}"
|
264
|
+
log_response_body(response)
|
265
|
+
if response.respond_to?(:headers)
|
266
|
+
log "RESPONSE HEADERS = #{response.headers}"
|
267
|
+
end
|
267
268
|
check_response(response, request: body)
|
268
269
|
end
|
269
270
|
|
270
271
|
def oauth_get(url, headers)
|
271
|
-
|
272
|
-
@oauth.get(url, headers)
|
273
|
-
elsif oauth_v2?
|
274
|
-
@oauth.get(url, headers: headers, raise_errors: false)
|
275
|
-
else
|
276
|
-
raise InvalidOauthAccessTokenObject.new(@oauth)
|
277
|
-
end
|
272
|
+
@oauth.get(url, headers: headers, raise_errors: false)
|
278
273
|
end
|
279
274
|
|
280
275
|
def oauth_post(url, body, headers)
|
281
|
-
|
282
|
-
@oauth.post(url, body, headers)
|
283
|
-
elsif oauth_v2?
|
284
|
-
@oauth.post(url, headers: headers, body: body, raise_errors: false)
|
285
|
-
else
|
286
|
-
raise InvalidOauthAccessTokenObject.new(@oauth)
|
287
|
-
end
|
276
|
+
@oauth.post(url, headers: headers, body: body, raise_errors: false)
|
288
277
|
end
|
289
278
|
|
290
279
|
def oauth_post_with_multipart(url, body, headers)
|
291
|
-
|
292
|
-
@oauth.post_with_multipart(url, body, headers)
|
293
|
-
elsif oauth_v2?
|
294
|
-
@oauth.post_with_multipart(url, headers: headers, body: body, raise_errors: false)
|
295
|
-
else
|
296
|
-
raise InvalidOauthAccessTokenObject.new(@oauth)
|
297
|
-
end
|
280
|
+
@oauth.post_with_multipart(url, headers: headers, body: body, raise_errors: false)
|
298
281
|
end
|
299
282
|
|
300
283
|
def add_query_string_to_url(url, params)
|
@@ -308,12 +291,18 @@ module Quickbooks
|
|
308
291
|
end
|
309
292
|
|
310
293
|
def check_response(response, options = {})
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
294
|
+
if is_json?
|
295
|
+
parse_json(response.plain_body)
|
296
|
+
elsif !is_pdf?
|
297
|
+
parse_xml(response.plain_body)
|
315
298
|
end
|
316
|
-
|
299
|
+
|
300
|
+
@last_response_intuit_tid = if response.respond_to?(:headers) && response.headers
|
301
|
+
response.headers['intuit_tid']
|
302
|
+
else
|
303
|
+
nil
|
304
|
+
end
|
305
|
+
|
317
306
|
status = response.code.to_i
|
318
307
|
case status
|
319
308
|
when 200
|
@@ -326,7 +315,7 @@ module Quickbooks
|
|
326
315
|
when 302
|
327
316
|
raise "Unhandled HTTP Redirect"
|
328
317
|
when 401
|
329
|
-
raise Quickbooks::AuthorizationFailure
|
318
|
+
raise Quickbooks::AuthorizationFailure, parse_intuit_error
|
330
319
|
when 403
|
331
320
|
message = parse_intuit_error[:message]
|
332
321
|
if message.include?('ThrottleExceeded')
|
@@ -353,12 +342,10 @@ module Quickbooks
|
|
353
342
|
log "RESPONSE BODY:"
|
354
343
|
if is_json?
|
355
344
|
log ">>>>#{response.plain_body.inspect}"
|
356
|
-
parse_json(response.plain_body)
|
357
345
|
elsif is_pdf?
|
358
346
|
log("BODY is a PDF : not dumping")
|
359
347
|
else
|
360
348
|
log(log_xml(response.plain_body))
|
361
|
-
parse_xml(response.plain_body)
|
362
349
|
end
|
363
350
|
end
|
364
351
|
|
@@ -400,6 +387,7 @@ module Quickbooks
|
|
400
387
|
else
|
401
388
|
ex.request_xml = options[:request]
|
402
389
|
end
|
390
|
+
ex.intuit_tid = err[:intuit_tid]
|
403
391
|
raise ex
|
404
392
|
end
|
405
393
|
|
@@ -414,7 +402,7 @@ module Quickbooks
|
|
414
402
|
end
|
415
403
|
|
416
404
|
def parse_intuit_error
|
417
|
-
error = {:message => "", :detail => "", :type => nil, :code => 0}
|
405
|
+
error = {:message => "", :detail => "", :type => nil, :code => 0, :intuit_tid => @last_response_intuit_tid}
|
418
406
|
fault = @last_response_xml.xpath("//xmlns:IntuitResponse/xmlns:Fault")[0]
|
419
407
|
if fault
|
420
408
|
error[:type] = fault.attributes['type'].value
|
@@ -426,7 +414,7 @@ module Quickbooks
|
|
426
414
|
error[:code] = code_attr.value
|
427
415
|
end
|
428
416
|
element_attr = error_element.attributes['element']
|
429
|
-
if
|
417
|
+
if element_attr
|
430
418
|
error[:element] = code_attr.value
|
431
419
|
end
|
432
420
|
error[:message] = error_element.xpath("//xmlns:Message").text
|
@@ -7,11 +7,7 @@ module Quickbooks
|
|
7
7
|
class OAuthHttpResponse
|
8
8
|
|
9
9
|
def self.wrap(response)
|
10
|
-
|
11
|
-
Quickbooks::Service::Responses::OAuth2HttpResponse.new(response)
|
12
|
-
else
|
13
|
-
Quickbooks::Service::Responses::OAuth1HttpResponse.new(response)
|
14
|
-
end
|
10
|
+
Quickbooks::Service::Responses::OAuth2HttpResponse.new(response)
|
15
11
|
end
|
16
12
|
|
17
13
|
end
|
@@ -1,78 +1,6 @@
|
|
1
1
|
module OauthMultipart
|
2
2
|
end
|
3
3
|
|
4
|
-
require "oauth"
|
5
|
-
|
6
|
-
OAuth::Consumer.class_eval do
|
7
|
-
def create_http_request(http_method, path, *arguments)
|
8
|
-
http_method = http_method.to_sym
|
9
|
-
|
10
|
-
if [:post, :put].include?(http_method)
|
11
|
-
data = arguments.shift
|
12
|
-
end
|
13
|
-
|
14
|
-
# if the base site contains a path, add it now
|
15
|
-
uri = URI.parse(site)
|
16
|
-
path = uri.path + path if uri.path
|
17
|
-
|
18
|
-
headers = arguments.first.is_a?(Hash) ? arguments.shift : {}
|
19
|
-
|
20
|
-
case http_method
|
21
|
-
when :post
|
22
|
-
request = Net::HTTP::Post.new(path,headers)
|
23
|
-
request["Content-Length"] = '0' # Default to 0
|
24
|
-
when :put
|
25
|
-
request = Net::HTTP::Put.new(path,headers)
|
26
|
-
request["Content-Length"] = '0' # Default to 0
|
27
|
-
when :get
|
28
|
-
request = Net::HTTP::Get.new(path,headers)
|
29
|
-
when :delete
|
30
|
-
request = Net::HTTP::Delete.new(path,headers)
|
31
|
-
|
32
|
-
when :head
|
33
|
-
request = Net::HTTP::Head.new(path,headers)
|
34
|
-
when :multipart_post
|
35
|
-
request = Net::HTTP::Post::Multipart.new(path, headers)
|
36
|
-
else
|
37
|
-
raise ArgumentError, "Don't know how to handle http_method: :#{http_method.to_s}"
|
38
|
-
end
|
39
|
-
|
40
|
-
if data.is_a?(Hash)
|
41
|
-
form_data = {}
|
42
|
-
data.each {|k,v| form_data[k.to_s] = v if !v.nil?}
|
43
|
-
request.set_form_data(form_data)
|
44
|
-
elsif data
|
45
|
-
if data.respond_to?(:read)
|
46
|
-
request.body_stream = data
|
47
|
-
if data.respond_to?(:length)
|
48
|
-
request["Content-Length"] = data.length.to_s
|
49
|
-
elsif data.respond_to?(:stat) && data.stat.respond_to?(:size)
|
50
|
-
request["Content-Length"] = data.stat.size.to_s
|
51
|
-
else
|
52
|
-
raise ArgumentError, "Don't know how to send a body_stream that doesn't respond to .length or .stat.size"
|
53
|
-
end
|
54
|
-
else
|
55
|
-
request.body = data.to_s
|
56
|
-
request["Content-Length"] = request.body.length.to_s
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
request
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
OAuth::AccessToken.class_eval do
|
66
|
-
|
67
|
-
def post_with_multipart(*args)
|
68
|
-
multipart_post *args
|
69
|
-
end
|
70
|
-
|
71
|
-
def multipart_post(*args)
|
72
|
-
request(:multipart_post, *args)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
4
|
OAuth2::AccessToken.class_eval do
|
77
5
|
|
78
6
|
def post_with_multipart(*args)
|
data/lib/quickbooks/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickbooks-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Caughlan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: oauth
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.4.7
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.4.7
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: oauth2
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,21 +39,21 @@ dependencies:
|
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: 4.0.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
42
|
+
name: activemodel
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - "
|
45
|
+
- - ">"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
47
|
+
version: '4.0'
|
62
48
|
type: :runtime
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - "
|
52
|
+
- - ">"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
54
|
+
version: '4.0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
56
|
+
name: nokogiri
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - ">="
|
@@ -98,16 +84,16 @@ dependencies:
|
|
98
84
|
name: rake
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- -
|
87
|
+
- - ">="
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
89
|
+
version: '0'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- -
|
94
|
+
- - ">="
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
96
|
+
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: simplecov
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,16 +126,30 @@ dependencies:
|
|
140
126
|
name: rspec
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
|
-
- -
|
129
|
+
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
131
|
+
version: '3.9'
|
146
132
|
type: :development
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
|
-
- -
|
136
|
+
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
138
|
+
version: '3.9'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec-its
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: webmock
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -329,7 +329,6 @@ files:
|
|
329
329
|
- lib/quickbooks/service/refund_receipt_change.rb
|
330
330
|
- lib/quickbooks/service/reports.rb
|
331
331
|
- lib/quickbooks/service/responses/methods.rb
|
332
|
-
- lib/quickbooks/service/responses/oauth1_http_response.rb
|
333
332
|
- lib/quickbooks/service/responses/oauth2_http_response.rb
|
334
333
|
- lib/quickbooks/service/responses/oauth_http_response.rb
|
335
334
|
- lib/quickbooks/service/sales_receipt.rb
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module Quickbooks
|
2
|
-
module Service
|
3
|
-
module Responses
|
4
|
-
|
5
|
-
class OAuth1HttpResponse < OAuthHttpResponse
|
6
|
-
|
7
|
-
attr_accessor :real_response
|
8
|
-
|
9
|
-
# net/http response
|
10
|
-
def initialize(response)
|
11
|
-
@real_response = response
|
12
|
-
end
|
13
|
-
|
14
|
-
def version
|
15
|
-
1
|
16
|
-
end
|
17
|
-
|
18
|
-
def code
|
19
|
-
@real_response.code.to_i
|
20
|
-
end
|
21
|
-
|
22
|
-
def plain_body
|
23
|
-
if @real_response.respond_to?(:plain_body)
|
24
|
-
@real_response.plain_body
|
25
|
-
else
|
26
|
-
nil
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def headers
|
31
|
-
if @real_response.respond_to?(:headers)
|
32
|
-
@real_response.headers
|
33
|
-
else
|
34
|
-
nil
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|