qbo_api 3.0.1 → 3.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9924b785fa2755f09e92bf26198280b198dee80d2621d8c86b4e4f2fdb1cc1d
4
- data.tar.gz: 26b76ad24f8760ebb5c39385e9798b3799645cbe6d3d69230a6d720ee9676514
3
+ metadata.gz: d091daea142ea8b5f0637e93068ebec256c6ed5027b03725b576e003fa1997b3
4
+ data.tar.gz: d44cdfc123b586c2ee4a228f06ffa0d6c602e8897c18cfb656fd68aa7a7401c3
5
5
  SHA512:
6
- metadata.gz: 827f3a675049aa20889d6e7e7cf9b8e2b05df79c0410b9bbef0c9bcd2c57eb81f77f88f5e5c2b9f161318bbd899ccb94bec9a9d2e199977b8545bd16cb8163e6
7
- data.tar.gz: e52c00f610340f0a0d13c711782629c56b80fcc6300b05e5f97705de63545c6cb59dbeba33fb15cbe2770628c38458c2535eabfd00e7e74a87223c267c5229e8
6
+ metadata.gz: 61177b17927c994c049cc7975f0673b9893f04c39d7f0b61ec5af4d2a15d13ad0cfbf0fac5302b33ffedeeda43f5af474d22112a8ca1b22d7cf5fa31097fbae8
7
+ data.tar.gz: de16113918a2d51488654197f585d60f480e40aa107d51e5de471ae418cabf7c01c0691a57d8acbe4bf732610d1f1b6c049317cb2c7a9d08ce09fa21ab876a81
@@ -0,0 +1,10 @@
1
+ # Set update schedule for GitHub Actions
2
+
3
+ version: 2
4
+ updates:
5
+
6
+ - package-ecosystem: "github-actions"
7
+ directory: "/"
8
+ schedule:
9
+ # Check for updates to GitHub Actions every weekday
10
+ interval: "daily"
@@ -0,0 +1,29 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [ master ]
7
+
8
+ jobs:
9
+ rspec:
10
+ runs-on: ubuntu-latest
11
+ env:
12
+ RUBYOPT: "-W:deprecated" # show warnings, deprecations only
13
+ FARADAY_VERSION: ${{ matrix.faraday }}
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ ruby: [ '2.7', '3.0', '3.1', '3.2' ]
18
+ faraday: [ '~> 1.0', '~> 2.0' ]
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Run RSpec
27
+ run: |
28
+ cp .env.test .env
29
+ bundle exec rspec spec/
data/.gitignore CHANGED
@@ -19,4 +19,4 @@ todo.txt
19
19
  spec/temp/spec_status.txt
20
20
  *.swp
21
21
  scrap.txt
22
- .tool-versions
22
+ .tool-versions
data/README.md CHANGED
@@ -81,7 +81,7 @@ QboApi.request_id = true
81
81
  resp = qbo_api.create(:bill, payload: bill_hash, params: { requestid: qbo_api.uuid })
82
82
  # Works with .get, .create, .update, .query methods
83
83
  ```
84
- - To run all requests with a [Minor version](https://developer.intuit.com/docs/0100_quickbooks_online/0200_dev_guides/accounting/minor_versions).
84
+ - By default, this client runs against the current "base" or major version of the QBO API. This client does not run against the latest QBO API [minor version](https://developer.intuit.com/app/developer/qbo/docs/learn/explore-the-quickbooks-online-api/minor-versions) by default. To run all requests with a specific minor version, you must specify it:
85
85
  ```ruby
86
86
  QboApi.minor_version = 8
87
87
  ```
@@ -132,6 +132,12 @@ QboApi.minor_version = 8
132
132
  p response['status'] # => "Deleted"
133
133
  ```
134
134
 
135
+ NOTE: If you are deleting a journal entry you have to use the following syntax with the underscore, even though this is inconsistent with how you create journal entries.
136
+ ```ruby
137
+ response = qbo_api.delete(:journal_entry, id: 145)
138
+ p response['status'] # => "Deleted"
139
+ ```
140
+
135
141
  ### Deactivate (only works for name list entities)
136
142
  ```ruby
137
143
  response = qbo_api.deactivate(:employee, id: 55)
@@ -329,29 +335,78 @@ See [docs](https://developer.intuit.com/docs/0100_quickbooks_online/0100_essenti
329
335
  p qbo_api.is_transaction_entity?(:customer) # => false
330
336
  p qbo_api.is_name_list_entity?(:vendors) # => true
331
337
  ```
332
- ## <a name='OAuth2-example'>Spin up an example</a>
338
+
339
+ ### Download Quickbooks PDF
340
+ A quickbooks supplied PDF can be downloaded for api endpoints which offer a PDF.
341
+ ```ruby
342
+ qbo_api.get_pdf(:invoice, 121) # produces a pdf stream.
343
+ ```
344
+ The PDF stream can then be saved using your preferred method.
345
+ ```ruby
346
+ # example using Ruby on Rails with ActiveStorage
347
+ class Invoice
348
+ has_one_attached :pdf_file
349
+ end
350
+ invoice_number = 121
351
+ pdf_data = qbo_api.get_pdf(:invoice, invoice_numer) # returns raw pdf stream
352
+ pdf_io = StringIO.new(pdf_data) # convert to a StringIO object
353
+ filename = "invoice_no_#{invoice_number}"
354
+
355
+ invoice.pdf_file.attach(
356
+ io: pdf_io,
357
+ filename: filename,
358
+ content_type: 'application/pdf'
359
+ )
360
+ ```
361
+
362
+ ```ruby
363
+ # plain ruby example
364
+ invoice_number = 121
365
+ pdf_data = qbo_api.get_pdf(:invoice, invoice_numer) # returns raw pdf stream
366
+ filename = "invoice_no_#{invoice_number}.pdf"
367
+
368
+ File.write(filename, pdf_data)
369
+ ```
370
+ ## Spin up an example
333
371
  - <a href="http://minimul.com/access-the-quickbooks-online-api-with-oauth2.html" target="_blank">Check out this article on spinning up the example</a>.
334
- - `git clone git://github.com/minimul/qbo_api && cd qbo_api`
335
- - `bundle`
372
+
373
+ - Create a Intuit developer account at [https://developer.intuit.com](https://developer.intuit.com)
374
+ - Create an app in the intuit developer backend
375
+ - Go to [myapps](https://developer.intuit.com/app/developer/myapps)
376
+ - Create an app with both the `Accounting` & `Payments` selected.
377
+
378
+ - Setup the app and gather credentials
379
+ - Go to the [Development Dashboard](https://developer.intuit.com/app/developer/dashboard)
380
+ - Click on your App name
381
+ - Click "Keys & credentials" under Development Settings in left menu
382
+ - Copy the 'Client ID' and the 'Client Secret'
383
+ - Add a Redirect URI: `http://localhost:9393/oauth2-redirect` (or whatever PORT= is in your .env)
384
+ - Create a new Sandbox Company by clicking on "View Sandbox companies"
385
+ Don't use it for anything else besides testing this app.
386
+ - Copy the 'Company ID' for use later
387
+ 1. Within 'Sandbox Company_US_1' click on the COG -> Additional info
388
+ 2. Copy the 'Company ID'
389
+
390
+ - Setup qbo_api
391
+ - `git clone git://github.com/minimul/qbo_api && cd qbo_api`
392
+ - `bundle`
393
+
336
394
  - Create a `.env` file
337
395
  - `cp .env.example_app.oauth2 .env`
338
- - If needed create an account at [https://developer.intuit.com](https://developer.intuit.com)
339
- - Click `Get started coding`
340
- - Create an app with both the `Accounting` & `Payments` selected.
341
- - Go to the [`Development` tab](https://developer.intuit.com/v2/ui#/app/dashboard)
342
- and copy the 'Client ID' and the 'Client 'Secret' to your .env
343
- as QBO_API_CLIENT_ID and QBO_API_CLIENT_SECRET respectively
344
- - Add a Redirect URI: `http://localhost:9393/oauth2-redirect` (or whatever PORT= is in your .env)
345
- - Create a new Company ([from the manage sandboxes page](https://developer.intuit.com/v2/ui#/sandbox))
346
- Don't use it for anything else besides testing this app.
347
- -. Copy the 'Company ID' to your .env as QBO_API_COMPANY_ID
348
- - Start up the example app
396
+ - Edit your .env and enter the following
397
+ ```
398
+ export QBO_API_CLIENT_ID=[YOUR CLIENT ID]
399
+ export QBO_API_CLIENT_SECRET=[YOUR CLIENT SECRET]
400
+ export QBO_API_COMPANY_ID=[YOUR COMPANY ID]
401
+ ```
402
+
403
+ - Start up the example app and test
349
404
  - `ruby example/oauth2.rb`
350
- - Go to `http://localhost:9393/oauth2`
351
- - Use the `Connect to QuickBooks` button to connect to your QuickBooks sandbox, which you receive when signing up at [https://developer.intuit.com](https://developer.intuit.com).
352
- - After successfully connecting to your sandbox go to :
353
- - `http://localhost:9393/oauth2/customer/5`
405
+ - Go to `http://localhost:9393/oauth2`
406
+ - Use the `Connect to QuickBooks` button to connect to your QuickBooks sandbox, which you receive when signing up at [https://developer.intuit.com](https://developer.intuit.com).
407
+ - After successfully connecting to your sandbox go to `http://localhost:9393/oauth2/customer/5`
354
408
  - You should see "Dukes Basketball Camp" displayed
409
+
355
410
  - Checkout [`example/oauth2.rb`](https://github.com/minimul/qbo_api/blob/master/example/oauth2.rb)
356
411
  to see what is going on under the hood.
357
412
 
@@ -34,6 +34,11 @@ class QboApi
34
34
  end
35
35
  end
36
36
 
37
+ def get_pdf(entity, id)
38
+ path = "#{entity_path(entity)}/#{id}/pdf"
39
+ request(:get, entity: entity, path: path, headers: { 'Accept' => 'application/pdf' })
40
+ end
41
+
37
42
  def create(entity, payload:, params: nil)
38
43
  request(:post, entity: entity, path: entity_path(entity), payload: payload, params: params)
39
44
  end
@@ -43,7 +43,7 @@ class QboApi
43
43
 
44
44
  def request(method, path:, entity: nil, payload: nil, params: nil, headers: nil)
45
45
  raw_response = raw_request(method, conn: connection, path: path, params: params, payload: payload, headers: headers)
46
- response(raw_response, entity: entity)
46
+ response(raw_response, entity: entity, headers: headers)
47
47
  end
48
48
 
49
49
  def raw_request(method, conn:, path:, payload: nil, params: nil, headers: nil)
@@ -63,8 +63,14 @@ class QboApi
63
63
  end
64
64
  end
65
65
 
66
- def response(resp, entity: nil)
66
+ def response(resp, entity: nil, headers: false)
67
67
  data = resp.body
68
+
69
+ if headers
70
+ content_type = headers['Accept'] || headers['Content-Type']
71
+ return data if content_type&.include?('application/pdf')
72
+ end
73
+
68
74
  entity ? entity_response(data, entity) : data
69
75
  rescue => e
70
76
  QboApi.logger.debug { "#{LOG_TAG} response parsing error: entity=#{entity.inspect} body=#{resp.body.inspect} exception=#{e.inspect}" }
data/lib/qbo_api/error.rb CHANGED
@@ -13,11 +13,25 @@ class QboApi
13
13
  class Error < StandardError
14
14
  attr_reader :fault
15
15
 
16
- def initialize(errors = nil)
17
- if errors
18
- @fault = errors
19
- super(errors[:error_body])
20
- end
16
+ def initialize(errors = {})
17
+ @fault = errors
18
+ super(errors[:error_body])
19
+ end
20
+
21
+ def fault_type
22
+ fault.dig(:error_body, 0, :fault_type)
23
+ end
24
+
25
+ def error_code
26
+ fault.dig(:error_body, 0, :error_code)
27
+ end
28
+
29
+ def error_message
30
+ fault.dig(:error_body, 0, :error_message)
31
+ end
32
+
33
+ def error_detail
34
+ fault.dig(:error_body, 0, :error_detail)
21
35
  end
22
36
  end
23
37
 
@@ -1,3 +1,3 @@
1
1
  class QboApi
2
- VERSION = "3.0.1"
2
+ VERSION = "3.0.3"
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: 3.0.1
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Pelczarski
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-04 00:00:00.000000000 Z
11
+ date: 2024-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -164,7 +164,7 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- description:
167
+ description:
168
168
  email:
169
169
  - christian@minimul.com
170
170
  executables: []
@@ -173,6 +173,8 @@ extra_rdoc_files: []
173
173
  files:
174
174
  - ".env.example_app.oauth2"
175
175
  - ".env.test"
176
+ - ".github/dependabot.yml"
177
+ - ".github/workflows/ci.yaml"
176
178
  - ".gitignore"
177
179
  - ".travis.yml"
178
180
  - Gemfile
@@ -204,7 +206,7 @@ homepage: https://github.com/minimul/qbo_api
204
206
  licenses:
205
207
  - MIT
206
208
  metadata: {}
207
- post_install_message:
209
+ post_install_message:
208
210
  rdoc_options: []
209
211
  require_paths:
210
212
  - lib
@@ -219,8 +221,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
221
  - !ruby/object:Gem::Version
220
222
  version: '0'
221
223
  requirements: []
222
- rubygems_version: 3.2.22
223
- signing_key:
224
+ rubygems_version: 3.3.26
225
+ signing_key:
224
226
  specification_version: 4
225
227
  summary: Ruby JSON-only client for QuickBooks Online API v3. Built on top of the Faraday
226
228
  gem.