qbo_api 2.1.0 → 3.0.0
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 +4 -4
- data/README.md +4 -4
- data/example/base.rb +1 -0
- data/lib/qbo_api/api_methods.rb +8 -0
- data/lib/qbo_api/connection.rb +12 -13
- data/lib/qbo_api/entity.rb +13 -0
- data/lib/qbo_api/raise_http_exception.rb +43 -31
- data/lib/qbo_api/version.rb +1 -1
- data/qbo_api.gemspec +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccab347179fd3c5d7ec6ae6ab5099be4c7732418f220f30f6dd593e2b670b3e8
|
4
|
+
data.tar.gz: 461041430eaaf924ce437df17173137fe3975cd6849cac73caf7270a66e84885
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c78fdb98214a4a0c0eaee625ee7fb2215396bc296cabf2788414716b15137bf2aef79fd213328ddd9e9dfb249aa38ab04c962737126c9667d2ed4cbfcc1c82f
|
7
|
+
data.tar.gz: 4a9bc0e915eff633eeaa89d6fea2ea45c979ad162e8188ebb0458380e9b146668b74af24dc0cbcd44e72b203794c87e82e2116761d9e3919015a5aa6481f2ac1
|
data/README.md
CHANGED
@@ -372,8 +372,8 @@ for how to install ngrok and what it is.
|
|
372
372
|
Add the token to your .env as QBO_API_VERIFIER_TOKEN
|
373
373
|
|
374
374
|
- In another tab, create a customer via the API:
|
375
|
-
`bundle exec ruby -rqbo_api -rdotenv -e 'Dotenv.load; p QboApi.new(access_token: ENV.fetch("
|
376
|
-
(You'll also need to have added the QBO_API_COMPANY_ID and
|
375
|
+
`bundle exec ruby -rqbo_api -rdotenv -e 'Dotenv.load; p QboApi.new(access_token: ENV.fetch("QBO_API_ACCESS_TOKEN"), realm_id: ENV.fetch("QBO_API_COMPANY_ID")).create(:customer, payload: { DisplayName: "TestCustomer" })'`
|
376
|
+
(You'll also need to have added the QBO_API_COMPANY_ID and QBO_API_ACCESS_TOKEN to your .env)
|
377
377
|
|
378
378
|
There could be a delay of up to a minute before the webhook fires.
|
379
379
|
|
@@ -391,8 +391,8 @@ for how to install ngrok and what it is.
|
|
391
391
|
connection = build_connection('https://oauth.platform.intuit.com', headers: { 'Accept' => 'application/json' }) do |conn|
|
392
392
|
conn.basic_auth(client_id, client_secret)
|
393
393
|
conn.request :url_encoded # application/x-www-form-urlencoded
|
394
|
-
conn.
|
395
|
-
conn.use
|
394
|
+
conn.response :json
|
395
|
+
conn.use QboApi::RaiseHttpException
|
396
396
|
end
|
397
397
|
|
398
398
|
raw_response = connection.post do |req|
|
data/example/base.rb
CHANGED
data/lib/qbo_api/api_methods.rb
CHANGED
@@ -58,6 +58,14 @@ class QboApi
|
|
58
58
|
request(:post, entity: entity, path: entity_path(entity), payload: payload)
|
59
59
|
end
|
60
60
|
|
61
|
+
def void(entity, id:)
|
62
|
+
err_msg = "Void is only for voidable transaction entities. Use .delete or .deactivate instead"
|
63
|
+
raise QboApi::NotImplementedError.new, err_msg unless is_voidable_transaction_entity?(entity)
|
64
|
+
path = add_params_to_path(path: entity_path(entity), params: { operation: :void })
|
65
|
+
payload = set_update(entity, id)
|
66
|
+
request(:post, entity: entity, path: path, payload: payload)
|
67
|
+
end
|
68
|
+
|
61
69
|
private
|
62
70
|
|
63
71
|
def get_query_str(entity, query_filter_args)
|
data/lib/qbo_api/connection.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require '
|
2
|
+
require 'faraday/response/json'
|
3
|
+
require 'qbo_api/raise_http_exception'
|
3
4
|
require 'faraday/detailed_logger'
|
5
|
+
require 'faraday/multipart'
|
4
6
|
|
5
7
|
class QboApi
|
6
8
|
module Connection
|
@@ -9,9 +11,10 @@ class QboApi
|
|
9
11
|
headers['Accept'] ||= 'application/json'
|
10
12
|
headers['Content-Type'] ||= 'application/json;charset=UTF-8'
|
11
13
|
build_connection(url, headers: headers) do |conn|
|
14
|
+
conn.response :json
|
12
15
|
add_authorization_middleware(conn)
|
13
|
-
add_exception_middleware(conn)
|
14
16
|
conn.request :url_encoded
|
17
|
+
add_exception_middleware(conn)
|
15
18
|
add_connection_adapter(conn)
|
16
19
|
end
|
17
20
|
end
|
@@ -22,6 +25,7 @@ class QboApi
|
|
22
25
|
'Accept' => 'application/json'
|
23
26
|
}
|
24
27
|
build_connection(url, headers: headers) do |conn|
|
28
|
+
conn.response :json
|
25
29
|
add_authorization_middleware(conn)
|
26
30
|
add_exception_middleware(conn)
|
27
31
|
conn.request :multipart
|
@@ -60,21 +64,13 @@ class QboApi
|
|
60
64
|
end
|
61
65
|
|
62
66
|
def response(resp, entity: nil)
|
63
|
-
data =
|
67
|
+
data = resp.body
|
64
68
|
entity ? entity_response(data, entity) : data
|
65
69
|
rescue => e
|
66
70
|
QboApi.logger.debug { "#{LOG_TAG} response parsing error: entity=#{entity.inspect} body=#{resp.body.inspect} exception=#{e.inspect}" }
|
67
71
|
data
|
68
72
|
end
|
69
73
|
|
70
|
-
def parse_response_body(resp)
|
71
|
-
body = resp.body
|
72
|
-
case resp.headers['Content-Type']
|
73
|
-
when /json/ then JSON.parse(body)
|
74
|
-
else body
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
74
|
private
|
79
75
|
|
80
76
|
def entity_response(data, entity)
|
@@ -101,11 +97,14 @@ class QboApi
|
|
101
97
|
end
|
102
98
|
|
103
99
|
def add_exception_middleware(conn)
|
104
|
-
conn.use
|
100
|
+
conn.use QboApi::RaiseHttpException
|
105
101
|
end
|
106
102
|
|
103
|
+
# Faraday 2 deprecated the FaradayMiddleware gem. Middleware is
|
104
|
+
# now part of Faraday itself, and :authorization can be used to pass
|
105
|
+
# the Bearer token.
|
107
106
|
def add_authorization_middleware(conn)
|
108
|
-
conn.request :
|
107
|
+
conn.request :authorization, access_token, token_type: 'bearer'
|
109
108
|
end
|
110
109
|
|
111
110
|
def entity_name(entity)
|
data/lib/qbo_api/entity.rb
CHANGED
@@ -20,6 +20,19 @@ class QboApi
|
|
20
20
|
sym.to_s.split('_').collect(&:capitalize).join
|
21
21
|
end
|
22
22
|
|
23
|
+
def is_voidable_transaction_entity?(entity)
|
24
|
+
voidable_transaction_entities.include?(singular(entity))
|
25
|
+
end
|
26
|
+
|
27
|
+
def voidable_transaction_entities
|
28
|
+
%w{
|
29
|
+
BillPayment
|
30
|
+
Invoice
|
31
|
+
Payment
|
32
|
+
SalesReceipt
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
23
36
|
def is_transaction_entity?(entity)
|
24
37
|
transaction_entities.include?(singular(entity))
|
25
38
|
end
|
@@ -1,32 +1,44 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'faraday/response'
|
2
3
|
require 'nokogiri'
|
3
4
|
# @private
|
4
|
-
|
5
|
+
class QboApi
|
5
6
|
# @private
|
6
|
-
class RaiseHttpException < Faraday::
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
7
|
+
class RaiseHttpException < Faraday::Response::RaiseError
|
8
|
+
def on_complete(env)
|
9
|
+
case env[:status]
|
10
|
+
when 400
|
11
|
+
raise QboApi::BadRequest.new(error_message(env))
|
12
|
+
when 401
|
13
|
+
raise QboApi::Unauthorized.new(error_message(env))
|
14
|
+
when 403
|
15
|
+
raise QboApi::Forbidden.new(error_message(env))
|
16
|
+
when 404
|
17
|
+
raise QboApi::NotFound.new(error_message(env))
|
18
|
+
when 407
|
19
|
+
# mimic the behavior that we get with proxy requests with HTTPS
|
20
|
+
msg = %(407 "Proxy Authentication Required")
|
21
|
+
raise Faraday::ProxyAuthError.new(msg, response_values(env))
|
22
|
+
when 409
|
23
|
+
raise Faraday::ConflictError, response_values(env)
|
24
|
+
when 422
|
25
|
+
raise Faraday::UnprocessableEntityError, response_values(env)
|
26
|
+
when 429
|
27
|
+
raise QboApi::TooManyRequests.new(error_message(env))
|
28
|
+
when 500
|
29
|
+
raise QboApi::InternalServerError.new(error_message(env))
|
30
|
+
when 502
|
31
|
+
raise QboApi::BadGateway.new({ error_body: env.reason_phrase })
|
32
|
+
when 503
|
33
|
+
raise QboApi::ServiceUnavailable.new(error_message(env))
|
34
|
+
when 504
|
35
|
+
raise QboApi::GatewayTimeout.new(error_message(env))
|
36
|
+
when ClientErrorStatuses
|
37
|
+
raise Faraday::ClientError, response_values(env)
|
38
|
+
when ServerErrorStatuses
|
39
|
+
raise Faraday::ServerError, response_values(env)
|
40
|
+
when nil
|
41
|
+
raise Faraday::NilStatusError, response_values(env)
|
30
42
|
end
|
31
43
|
end
|
32
44
|
|
@@ -36,13 +48,13 @@ module FaradayMiddleware
|
|
36
48
|
|
37
49
|
private
|
38
50
|
|
39
|
-
def error_message(
|
51
|
+
def error_message(env)
|
40
52
|
{
|
41
|
-
method:
|
42
|
-
url:
|
43
|
-
status:
|
44
|
-
error_body: error_body(
|
45
|
-
intuit_tid:
|
53
|
+
method: env.method,
|
54
|
+
url: env.url,
|
55
|
+
status: env.status,
|
56
|
+
error_body: error_body(env.body),
|
57
|
+
intuit_tid: env[:response_headers]['intuit_tid']
|
46
58
|
}
|
47
59
|
end
|
48
60
|
|
data/lib/qbo_api/version.rb
CHANGED
data/qbo_api.gemspec
CHANGED
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'dotenv'
|
26
26
|
spec.add_development_dependency 'vcr'
|
27
27
|
spec.add_development_dependency 'amazing_print'
|
28
|
-
spec.add_runtime_dependency 'faraday', '
|
29
|
-
spec.add_runtime_dependency 'faraday_middleware'
|
28
|
+
spec.add_runtime_dependency 'faraday', '>= 1.10.0'
|
30
29
|
spec.add_runtime_dependency 'faraday-detailed_logger'
|
30
|
+
spec.add_runtime_dependency 'faraday-multipart'
|
31
31
|
spec.add_runtime_dependency 'nokogiri'
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qbo_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Pelczarski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,18 +112,18 @@ dependencies:
|
|
112
112
|
name: faraday
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: 1.10.0
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 1.10.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: faraday-detailed_logger
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name: faraday-
|
140
|
+
name: faraday-multipart
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|