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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 602ff37e3feee0e447a15566efe439d1f9beb61b
4
- data.tar.gz: c709006d7f4bd704e9a1011824da9812b0edb6da
3
+ metadata.gz: 430743a894af002cc941bad7718061ad8e92318c
4
+ data.tar.gz: 261dfeb6da46efac3cc215faec85fca9c260898a
5
5
  SHA512:
6
- metadata.gz: 5511399b404ad719752fc1a5fd6359e8be2386fdcc9d2e99e792abebeca3fd1e470cf838d6a6c4ecb5e9fd9a29bf25175f892a0d4fca872b1da6f39af18cd440
7
- data.tar.gz: 32dcda594b2f9a63395a67d5e38cf76eee7dbbf00e85f6184d6fd690becbbe3c371cf47514a8269909b775cd55777b709c816fd77aafa2d11ddb99d4dbe51f58
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 QBO_API_CONSUMER_SECRET=<Your QuickBooks Apps Client Secret>
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
 
@@ -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
- "<p>Success! Here is your access_token => #{resp.access_token}</p><p><a href='/oauth2/customer/5'>Click here</a> to make an API call</p>"
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
@@ -1,10 +1,10 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title></title>
6
- </head>
7
- <body>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title></title>
6
+ </head>
7
+ <body>
8
8
  <h1><%= @resp['DisplayName'] %></h1>
9
- </body>
9
+ </body>
10
10
  </html>
@@ -1,26 +1,26 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>QBO Connect</title>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>QBO Connect</title>
6
6
 
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 %>
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
- <p><a href="/oauth2">OAuth2 Connect Page</a></p>
25
- </body>
23
+ <ipp:connectToIntuit></ipp:connectToIntuit>
24
+ <p><a href="/oauth2">OAuth2 Connect Page</a></p>
25
+ </body>
26
26
  </html>
@@ -1,25 +1,22 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>QBO Connect via OAuth2</title>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>QBO Connect via OAuth2</title>
6
6
 
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>
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>
@@ -105,15 +105,13 @@ class QboApi
105
105
  end
106
106
 
107
107
  def all(entity, max: 1000, select: nil, inactive: false, &block)
108
- select = build_all_query(entity, select: select, inactive: inactive)
109
- pos = 0
110
- begin
111
- pos = pos == 0 ? pos + 1 : pos + max
112
- results = query("#{select} MAXRESULTS #{max} STARTPOSITION #{pos}")
113
- results.each do |entry|
114
- yield(entry)
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))
@@ -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.
@@ -1,3 +1,3 @@
1
1
  class QboApi
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  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: 1.5.0
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-07-29 00:00:00.000000000 Z
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
@@ -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