qbo_api 1.5.5 → 1.6.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 +34 -1
- data/lib/qbo_api.rb +28 -2
- data/lib/qbo_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dff9404c6a83b4e8f6fc33fd52af54b5ab006b55
|
4
|
+
data.tar.gz: 59f355486c69b4ac7c1455983eda7d7569452de3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc49185da33d9cbede625b6cb90983e934d6bc3610204e95cd88403edea686ad27673dc4e243004ac391021e8eb4690ef9071d1983344806e933c66e3bee6f07
|
7
|
+
data.tar.gz: 2ff9700fcdfd87be23955fd5dd4d4ac970e62f9b1758dc1af3f26f74111789f56abeed92904aa0601e40fd87989dc73950ab5adcad1411cf0949b3ed31e5f7b1
|
data/README.md
CHANGED
@@ -167,9 +167,42 @@ QboApi.minor_version = 8
|
|
167
167
|
p response['DisplayName'] # => "Dukes Basketball Camp"
|
168
168
|
```
|
169
169
|
|
170
|
+
### Uploading an attachment
|
171
|
+
```ruby
|
172
|
+
payload = {"AttachableRef":
|
173
|
+
[
|
174
|
+
{"EntityRef":
|
175
|
+
{
|
176
|
+
"type": "Invoice",
|
177
|
+
"value": "111"
|
178
|
+
}
|
179
|
+
}
|
180
|
+
],
|
181
|
+
"FileName": "test.txt",
|
182
|
+
"ContentType": "text/plain"
|
183
|
+
}
|
184
|
+
# `attachment` can be either an IO stream or string path to a local file
|
185
|
+
response = qbo_api.upload_attachment(payload: payload, attachment: '/tmp/test.txt')
|
186
|
+
p response['Id'] # => 5000000000000091308
|
187
|
+
```
|
188
|
+
|
189
|
+
Be aware that any errors will not raise a `QboApi::Error`, but will be returned in the following format:
|
190
|
+
```ruby
|
191
|
+
{"AttachableResponse"=>
|
192
|
+
[{"Fault"=>
|
193
|
+
{"Error"=>
|
194
|
+
[{"Message"=>"Object Not Found",
|
195
|
+
"Detail"=>
|
196
|
+
"Object Not Found : Something you're trying to use has been made inactive. Check the fields with accounts, customers, items, vendors or employees.",
|
197
|
+
"code"=>"610",
|
198
|
+
"element"=>""}],
|
199
|
+
"type"=>"ValidationFault"}}],
|
200
|
+
"time"=>"2018-01-03T13:06:31.406-08:00"}
|
201
|
+
```
|
202
|
+
|
170
203
|
### Change data capture (CDC) query
|
171
204
|
```ruby
|
172
|
-
response =
|
205
|
+
response = qbo_api.cdc(entities: 'estimate', changed_since: '2011-10-10T09:00:00-07:00')
|
173
206
|
# You can also send in a Time object e.g. changed_since: Time.now
|
174
207
|
expect(response['CDCResponse'].size).to eq 1
|
175
208
|
ids = response['CDCResponse'][0]['QueryResponse'][0]['Estimate'].collect{ |e| e['Id'] }
|
data/lib/qbo_api.rb
CHANGED
@@ -42,13 +42,13 @@ class QboApi
|
|
42
42
|
def connection(url: get_endpoint)
|
43
43
|
@connection ||= Faraday.new(url: url) do |faraday|
|
44
44
|
faraday.headers['Content-Type'] = 'application/json;charset=UTF-8'
|
45
|
-
faraday.headers['Accept'] =
|
45
|
+
faraday.headers['Accept'] = 'application/json'
|
46
46
|
if @token != nil
|
47
47
|
faraday.request :oauth, oauth_data
|
48
48
|
elsif @access_token != nil
|
49
49
|
faraday.request :oauth2, @access_token, token_type: 'bearer'
|
50
50
|
else
|
51
|
-
raise QboApi::Error.new error_body:
|
51
|
+
raise QboApi::Error.new error_body: 'Must set either the token or access_token'
|
52
52
|
end
|
53
53
|
faraday.request :url_encoded
|
54
54
|
faraday.use FaradayMiddleware::RaiseHttpException
|
@@ -140,8 +140,32 @@ class QboApi
|
|
140
140
|
data
|
141
141
|
end
|
142
142
|
|
143
|
+
def upload_attachment(payload:, attachment:)
|
144
|
+
content_type = payload['ContentType'] || payload[:ContentType]
|
145
|
+
file_name = payload['FileName'] || payload[:FileName]
|
146
|
+
raw_response = attachment_connection.post do |request|
|
147
|
+
request.url "#{realm_id}/upload"
|
148
|
+
request.body = {
|
149
|
+
'file_metadata_01':
|
150
|
+
Faraday::UploadIO.new(StringIO.new(JSON.generate(payload)), 'application/json', 'attachment.json'),
|
151
|
+
'file_content_01':
|
152
|
+
Faraday::UploadIO.new(attachment, content_type, file_name)
|
153
|
+
}
|
154
|
+
end
|
155
|
+
response(raw_response, entity: :attachable)
|
156
|
+
end
|
157
|
+
|
143
158
|
private
|
144
159
|
|
160
|
+
def attachment_connection
|
161
|
+
return @attachment_connection if @attachment_connection
|
162
|
+
multipart_connection = connection.dup
|
163
|
+
multipart_connection.headers['Content-Type'] = 'multipart/form-data'
|
164
|
+
multipart_middleware_index = multipart_connection.builder.handlers.index(Faraday::Request::UrlEncoded) || 1
|
165
|
+
multipart_connection.builder.insert(multipart_middleware_index, Faraday::Request::Multipart)
|
166
|
+
@attachment_connection = multipart_connection
|
167
|
+
end
|
168
|
+
|
145
169
|
def create_all_enumerator(entity, max: 1000, select: nil, inactive: false)
|
146
170
|
Enumerator.new do |enum_yielder|
|
147
171
|
select = build_all_query(entity, select: select, inactive: inactive)
|
@@ -159,6 +183,8 @@ class QboApi
|
|
159
183
|
def entity_response(data, entity)
|
160
184
|
if qr = data['QueryResponse']
|
161
185
|
qr.empty? ? nil : qr.fetch(singular(entity))
|
186
|
+
elsif ar = data['AttachableResponse']
|
187
|
+
ar.first.fetch(singular(entity))
|
162
188
|
else
|
163
189
|
data.fetch(singular(entity))
|
164
190
|
end
|
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.
|
4
|
+
version: 1.6.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: 2018-01-
|
11
|
+
date: 2018-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|