qbo_api 3.0.2 → 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 +4 -4
- data/.gitignore +1 -1
- data/README.md +32 -0
- data/lib/qbo_api/api_methods.rb +5 -0
- data/lib/qbo_api/connection.rb +8 -2
- data/lib/qbo_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d091daea142ea8b5f0637e93068ebec256c6ed5027b03725b576e003fa1997b3
|
|
4
|
+
data.tar.gz: d44cdfc123b586c2ee4a228f06ffa0d6c602e8897c18cfb656fd68aa7a7401c3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61177b17927c994c049cc7975f0673b9893f04c39d7f0b61ec5af4d2a15d13ad0cfbf0fac5302b33ffedeeda43f5af474d22112a8ca1b22d7cf5fa31097fbae8
|
|
7
|
+
data.tar.gz: de16113918a2d51488654197f585d60f480e40aa107d51e5de471ae418cabf7c01c0691a57d8acbe4bf732610d1f1b6c049317cb2c7a9d08ce09fa21ab876a81
|
data/.gitignore
CHANGED
data/README.md
CHANGED
|
@@ -335,6 +335,38 @@ See [docs](https://developer.intuit.com/docs/0100_quickbooks_online/0100_essenti
|
|
|
335
335
|
p qbo_api.is_transaction_entity?(:customer) # => false
|
|
336
336
|
p qbo_api.is_name_list_entity?(:vendors) # => true
|
|
337
337
|
```
|
|
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
|
+
```
|
|
338
370
|
## Spin up an example
|
|
339
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>.
|
|
340
372
|
|
data/lib/qbo_api/api_methods.rb
CHANGED
|
@@ -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
|
data/lib/qbo_api/connection.rb
CHANGED
|
@@ -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/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: 3.0.
|
|
4
|
+
version: 3.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Christian Pelczarski
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-07-
|
|
11
|
+
date: 2024-07-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|