qbo_api 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -5
- data/example/app.rb +4 -3
- data/example/views/customer.erb +6 -6
- data/example/views/index.erb +21 -21
- data/example/views/oauth2.erb +17 -20
- data/lib/qbo_api.rb +21 -9
- data/lib/qbo_api/error.rb +2 -2
- data/lib/qbo_api/version.rb +1 -1
- metadata +2 -3
- data/example/qbo_oauth2.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 430743a894af002cc941bad7718061ad8e92318c
|
4
|
+
data.tar.gz: 261dfeb6da46efac3cc215faec85fca9c260898a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cc2bccce416c0ea0e141d8315951d91b8ee41c9ada35a5241ada1c397eeaf2b0c0cc7e3ace18ce1dfb5b852052d2930c0363152be85639dc8d652981071523b
|
7
|
+
data.tar.gz: 8cf4e6c599ed946addb07c85d333d39c20c0a1e18ab86513fe8164fc386501028bc3d2ee2468eb15028ebcf5cba9124fabbe5360c14e4da876214dc1cf449202
|
data/README.md
CHANGED
@@ -243,23 +243,23 @@ See [docs](https://developer.intuit.com/docs/0100_quickbooks_online/0100_essenti
|
|
243
243
|
### Import/retrieve all
|
244
244
|
```ruby
|
245
245
|
# retrieves all active customers
|
246
|
-
qbo_api.all(:customers) do |c|
|
246
|
+
qbo_api.all(:customers).each do |c|
|
247
247
|
p "#{c['Id']} #{c['DisplayName']}"
|
248
248
|
end
|
249
249
|
|
250
250
|
# retrieves all active or inactive employees
|
251
|
-
qbo_api.all(:employees, inactive: true) do |e|
|
251
|
+
qbo_api.all(:employees, inactive: true).each do |e|
|
252
252
|
p "#{e['Id']} #{e['DisplayName']}"
|
253
253
|
end
|
254
254
|
|
255
255
|
# retrieves all vendors by groups of 5
|
256
|
-
qbo_api.all(:vendor, max: 5) do |v|
|
256
|
+
qbo_api.all(:vendor, max: 5).each do |v|
|
257
257
|
p v['DisplayName']
|
258
258
|
end
|
259
259
|
|
260
260
|
# retrieves all customers by groups of 2 using a custom select query
|
261
261
|
where = "WHERE Id IN ('5', '6', '7', '8', '9', '10')"
|
262
|
-
qbo_api.all(:customer, max: 2, select: "SELECT * FROM Customer #{where}") do |c|
|
262
|
+
qbo_api.all(:customer, max: 2, select: "SELECT * FROM Customer #{where}").each do |c|
|
263
263
|
p c['DisplayName']
|
264
264
|
end
|
265
265
|
```
|
@@ -274,6 +274,7 @@ See [docs](https://developer.intuit.com/docs/0100_quickbooks_online/0100_essenti
|
|
274
274
|
```
|
275
275
|
## OAuth2: Spin up an example
|
276
276
|
### If you signed up for a Intuit developer account after July 17th, 2017 follow this example
|
277
|
+
- <a href="http://minimul.com/access-the-quickbooks-online-api-with-oauth2.html" target="_blank">Check out this article on spinning up the OAuth2 example</a>.
|
277
278
|
- `git clone git://github.com/minimul/qbo_api && cd qbo_api`
|
278
279
|
- `bundle`
|
279
280
|
- Create a `.env` file
|
@@ -283,7 +284,7 @@ See [docs](https://developer.intuit.com/docs/0100_quickbooks_online/0100_essenti
|
|
283
284
|
- Go to the `Development` tab and copy and paste the client id and client secret into the `.env` file.
|
284
285
|
```ruby
|
285
286
|
export QBO_API_CLIENT_ID=<Your QuickBooks Apps Client ID>
|
286
|
-
export
|
287
|
+
export QBO_API_CLIENT_SECRET=<Your QuickBooks Apps Client Secret>
|
287
288
|
```
|
288
289
|
- Note: the `.env` file will be automatically loaded after you run the next step.
|
289
290
|
- Start up the example app
|
@@ -350,6 +351,7 @@ export QBO_API_COMPANY_ID=12345
|
|
350
351
|
```
|
351
352
|
bin/console test
|
352
353
|
>> q = QboApi.new(creds.to_h)
|
354
|
+
>> q = QboApi.new(oauth2_creds.to_h) # FOR OAuth2
|
353
355
|
>> q.get :customer, 1
|
354
356
|
```
|
355
357
|
|
data/example/app.rb
CHANGED
@@ -63,9 +63,10 @@ get '/oauth2-redirect' do
|
|
63
63
|
client = oauth2_client
|
64
64
|
client.authorization_code = code
|
65
65
|
if resp = client.access_token!
|
66
|
+
session[:refresh_token] = resp.refresh_token
|
66
67
|
session[:access_token] = resp.access_token
|
67
68
|
session[:realm_id] = params[:realmId]
|
68
|
-
|
69
|
+
erb :oauth2_redirect
|
69
70
|
else
|
70
71
|
"Something went wrong. Try the process again"
|
71
72
|
end
|
@@ -110,8 +111,8 @@ end
|
|
110
111
|
|
111
112
|
get '/auth/quickbooks/callback' do
|
112
113
|
auth = env["omniauth.auth"][:credentials]
|
113
|
-
session[:token] = auth[:token]
|
114
|
-
session[:secret] = auth[:secret]
|
114
|
+
session[:token] = auth[:token]
|
115
|
+
session[:secret] = auth[:secret]
|
115
116
|
session[:realm_id] = params['realmId']
|
116
117
|
'<!DOCTYPE html><html lang="en"><head></head><body><script>window.opener.location.reload(); window.close();</script></body></html>'
|
117
118
|
end
|
data/example/views/customer.erb
CHANGED
data/example/views/index.erb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<title>QBO Connect</title>
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
</head>
|
18
|
-
<body>
|
19
|
-
|
20
|
-
|
21
|
-
|
7
|
+
<script type="text/javascript" src="<%= @app_center %>/Content/IA/intuit.ipp.anywhere-1.3.1.js"></script>
|
8
|
+
<script>
|
9
|
+
intuit.ipp.anywhere.setup({
|
10
|
+
grantUrl: "http://localhost:<%= @port %>/auth/quickbooks",
|
11
|
+
datasources: {
|
12
|
+
quickbooks : true,
|
13
|
+
payments : true
|
14
|
+
}
|
15
|
+
});
|
16
|
+
</script>
|
17
|
+
</head>
|
18
|
+
<body>
|
19
|
+
<% if session[:token] %>
|
20
|
+
<p><%= @auth_data %></p>
|
21
|
+
<% end %>
|
22
22
|
|
23
|
-
<ipp:connectToIntuit></ipp:connectToIntuit>
|
24
|
-
|
25
|
-
</body>
|
23
|
+
<ipp:connectToIntuit></ipp:connectToIntuit>
|
24
|
+
<p><a href="/oauth2">OAuth2 Connect Page</a></p>
|
25
|
+
</body>
|
26
26
|
</html>
|
data/example/views/oauth2.erb
CHANGED
@@ -1,25 +1,22 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<title>QBO Connect via OAuth2</title>
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
</head>
|
18
|
-
<body>
|
19
|
-
<% if session[:token] %>
|
20
|
-
<p><%= @auth_data %></p>
|
21
|
-
<% end %>
|
7
|
+
<script type="text/javascript" src="<%= QboApi::APP_CENTER_BASE %>/Content/IA/intuit.ipp.anywhere-1.3.1.js"></script>
|
8
|
+
<script>
|
9
|
+
intuit.ipp.anywhere.setup({
|
10
|
+
grantUrl: "<%= @client.authorization_uri(scope: 'com.intuit.quickbooks.accounting', state: session[:state]) %>",
|
11
|
+
datasources: {
|
12
|
+
quickbooks : true,
|
13
|
+
payments : true
|
14
|
+
}
|
15
|
+
});
|
16
|
+
</script>
|
17
|
+
</head>
|
18
|
+
<body>
|
22
19
|
|
23
|
-
<ipp:connectToIntuit></ipp:connectToIntuit>
|
24
|
-
</body>
|
20
|
+
<ipp:connectToIntuit></ipp:connectToIntuit>
|
21
|
+
</body>
|
25
22
|
</html>
|
data/lib/qbo_api.rb
CHANGED
@@ -105,15 +105,13 @@ class QboApi
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def all(entity, max: 1000, select: nil, inactive: false, &block)
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end if results
|
116
|
-
end while (results ? results.size == max : false)
|
108
|
+
enumerator = create_all_enumerator(entity, max: max, select: select, inactive: inactive)
|
109
|
+
|
110
|
+
if block_given?
|
111
|
+
enumerator.each(&block)
|
112
|
+
else
|
113
|
+
enumerator
|
114
|
+
end
|
117
115
|
end
|
118
116
|
|
119
117
|
def request(method, path:, entity: nil, payload: nil, params: nil)
|
@@ -144,6 +142,20 @@ class QboApi
|
|
144
142
|
|
145
143
|
private
|
146
144
|
|
145
|
+
def create_all_enumerator(entity, max: 1000, select: nil, inactive: false)
|
146
|
+
Enumerator.new do |enum_yielder|
|
147
|
+
select = build_all_query(entity, select: select, inactive: inactive)
|
148
|
+
pos = 0
|
149
|
+
begin
|
150
|
+
pos = pos == 0 ? pos + 1 : pos + max
|
151
|
+
results = query("#{select} MAXRESULTS #{max} STARTPOSITION #{pos}")
|
152
|
+
results.each do |entry|
|
153
|
+
enum_yielder.yield(entry)
|
154
|
+
end if results
|
155
|
+
end while (results ? results.size == max : false)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
147
159
|
def entity_response(data, entity)
|
148
160
|
if qr = data['QueryResponse']
|
149
161
|
qr.empty? ? nil : qr.fetch(singular(entity))
|
data/lib/qbo_api/error.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
|
-
#200 OK The request succeeded. However, the response body may contain a <Fault> element, indicating an error.
|
3
|
-
#400 Bad request Generally, the request cannot be fulfilled due to bad syntax. In some cases, this response code is returned for a request with bad authorization data.
|
2
|
+
#200 OK The request succeeded. However, the response body may contain a <Fault> element, indicating an error.
|
3
|
+
#400 Bad request Generally, the request cannot be fulfilled due to bad syntax. In some cases, this response code is returned for a request with bad authorization data.
|
4
4
|
#401 Unauthorized Authentication or authorization has failed.
|
5
5
|
#403 Forbidden The resource is forbidden.
|
6
6
|
#404 Not Found The resource is not found.
|
data/lib/qbo_api/version.rb
CHANGED
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: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Pelczarski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -264,7 +264,6 @@ files:
|
|
264
264
|
- bin/console
|
265
265
|
- bin/setup
|
266
266
|
- example/app.rb
|
267
|
-
- example/qbo_oauth2.rb
|
268
267
|
- example/views/customer.erb
|
269
268
|
- example/views/index.erb
|
270
269
|
- example/views/oauth2.erb
|
data/example/qbo_oauth2.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'omniauth-oauth2'
|
2
|
-
|
3
|
-
module OmniAuth
|
4
|
-
module Strategies
|
5
|
-
class QboOAuth2 < OmniAuth::Strategies::OAuth2
|
6
|
-
# Give your strategy a name.
|
7
|
-
option :name, "qbo"
|
8
|
-
|
9
|
-
# This is where you pass the options you would pass when
|
10
|
-
# initializing your consumer from the OAuth gem.
|
11
|
-
option :client_options, {:site => "https://appcenter.intuit.com/connect/oauth2"}
|
12
|
-
|
13
|
-
# These are called after authentication has succeeded. If
|
14
|
-
# possible, you should try to set the UID without making
|
15
|
-
# additional calls (if the user id is returned with the token
|
16
|
-
# or as a URI parameter). This may not be possible with all
|
17
|
-
# providers.
|
18
|
-
uid{ raw_info['id'] }
|
19
|
-
|
20
|
-
info do
|
21
|
-
{
|
22
|
-
:name => raw_info['name'],
|
23
|
-
:email => raw_info['email']
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
extra do
|
28
|
-
{
|
29
|
-
'raw_info' => raw_info
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
def raw_info
|
34
|
-
@raw_info ||= access_token.get('/me').parsed
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|