qbo_api 1.6.2 → 1.6.5

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: a0ccc44f499b0c5078b99f8eea04d58ee52f8094
4
- data.tar.gz: 87980a9894552ed9bae5ffbe320d63f2ab2e96bd
3
+ metadata.gz: 3025022857f508d3f6522d3ab13c2d0237e6ac67
4
+ data.tar.gz: b264a7c95043b9337b94075b315c7fc74be3f72b
5
5
  SHA512:
6
- metadata.gz: e57bc51406e94051033b1d01baba6e70eb9c56ff96e9cfd7677adc5826f70d69fd48641e159fd7ba0f1094822eb44e0733c54fd9aee0f64d4a60a19315648345
7
- data.tar.gz: cea01f2127b4974417dffa7f95a4fdcf134d144b228642fa2c327e359f74df191114902ff8e78f5b880fdc772e3b24f70f83d70d1256c57469f87b92bff3b69d
6
+ metadata.gz: d9831b0aab6fd731849cb16dad761d5f4e1ef81f5494342af591edea5fa965133034d3b61b18d10e63df80100f08a72e7c3294887973dcd8d5adad4b426fc78c
7
+ data.tar.gz: 7ff2bba02f51e0cdce47086208a13e7d2f5a65e64cf9ed60ff24613fef0477f0dce092e12493522b1cbb2a2683a4597407045cfd52699d31d8ec19249fadf450
data/README.md CHANGED
@@ -156,17 +156,40 @@ QboApi.minor_version = 8
156
156
  p response['Active'] # => false
157
157
  ```
158
158
 
159
- ### Search with irregular characters
160
- ```ruby
161
- name = qbo_api.esc "Amy's Bird Sanctuary"
162
- response = qbo_api.query(%{SELECT * FROM Customer WHERE DisplayName = '#{name}'})
163
- ```
164
159
  ### Get an entity by its id
165
160
  ```ruby
166
161
  response = qbo_api.get(:customer, 5)
167
162
  p response['DisplayName'] # => "Dukes Basketball Camp"
168
163
  ```
169
164
 
165
+ ### Get an entity by one its Filter attributes
166
+ ```ruby
167
+ response = qbo_api.get(:customer, ["DisplayName", "Dukes Basketball Camp"])
168
+ p response['Id'] # => 5
169
+ ```
170
+
171
+ ### Get an entity by one its Filter attributes using a LIKE search
172
+ ```ruby
173
+ response = qbo_api.get(:customer, ["DisplayName", "LIKE", "Dukes%"])
174
+ p response['Id'] # => 5
175
+ ```
176
+
177
+ ### Get an entity by one its Filter attributes using a IN search
178
+ ```ruby
179
+ response = qbo_api.get(:vendor, ["DisplayName", "IN", "(true, false)"])
180
+ p response.size # => 28
181
+ ```
182
+
183
+ ### Search with irregular characters
184
+ ```ruby
185
+ # Use the .esc() method
186
+ name = qbo_api.esc "Amy's Bird Sanctuary"
187
+ response = qbo_api.query(%{SELECT * FROM Customer WHERE DisplayName = '#{name}'})
188
+ # OR USE .get() method, which will automatically escape
189
+ response = qbo_api.get(:customer, ["DisplayName", "Amy's Bird Sanctuary"])
190
+ p response['Id'] # => 1
191
+ ```
192
+
170
193
  ### Uploading an attachment
171
194
  ```ruby
172
195
  payload = {"AttachableRef":
@@ -277,6 +300,7 @@ See [docs](https://developer.intuit.com/docs/0100_quickbooks_online/0100_essenti
277
300
  ```
278
301
 
279
302
  ### Import/retrieve all
303
+ *Note: There is some overlap with the `all` and the `get` methods. The `get` method is limited to 1000 results where the `all` method will return all the results no matter the number.*
280
304
  ```ruby
281
305
  # retrieves all active customers
282
306
  qbo_api.all(:customers).each do |c|
@@ -15,6 +15,8 @@ require_relative 'qbo_api/util'
15
15
  require_relative 'qbo_api/attachment'
16
16
  require_relative 'qbo_api/setter'
17
17
  require_relative 'qbo_api/builder'
18
+ require_relative 'qbo_api/finder'
19
+ require_relative 'qbo_api/all'
18
20
 
19
21
  class QboApi
20
22
  extend Configuration
@@ -24,6 +26,8 @@ class QboApi
24
26
  include Attachment
25
27
  include Setter
26
28
  include Builder
29
+ include Finder
30
+ include All
27
31
 
28
32
  attr_reader :realm_id
29
33
 
@@ -64,17 +68,6 @@ class QboApi
64
68
  end
65
69
  end
66
70
 
67
- def query(query, params: nil)
68
- path = "#{realm_id}/query?query=#{CGI.escape(query)}"
69
- entity = extract_entity_from_query(query, to_sym: true)
70
- request(:get, entity: entity, path: path, params: params)
71
- end
72
-
73
- def get(entity, id, params: nil)
74
- path = "#{entity_path(entity)}/#{id}"
75
- request(:get, entity: entity, path: path, params: params)
76
- end
77
-
78
71
  def create(entity, payload:, params: nil)
79
72
  request(:post, entity: entity, path: entity_path(entity), payload: payload, params: params)
80
73
  end
@@ -110,16 +103,6 @@ class QboApi
110
103
  request(:get, path: path)
111
104
  end
112
105
 
113
- def all(entity, max: 1000, select: nil, inactive: false, &block)
114
- enumerator = create_all_enumerator(entity, max: max, select: select, inactive: inactive)
115
-
116
- if block_given?
117
- enumerator.each(&block)
118
- else
119
- enumerator
120
- end
121
- end
122
-
123
106
  def request(method, path:, entity: nil, payload: nil, params: nil)
124
107
  raw_response = connection.send(method) do |req|
125
108
  path = finalize_path(path, method: method, params: params)
@@ -148,20 +131,6 @@ class QboApi
148
131
 
149
132
  private
150
133
 
151
- def create_all_enumerator(entity, max: 1000, select: nil, inactive: false)
152
- Enumerator.new do |enum_yielder|
153
- select = build_all_query(entity, select: select, inactive: inactive)
154
- pos = 0
155
- begin
156
- pos = pos == 0 ? pos + 1 : pos + max
157
- results = query("#{select} MAXRESULTS #{max} STARTPOSITION #{pos}")
158
- results.each do |entry|
159
- enum_yielder.yield(entry)
160
- end if results
161
- end while (results ? results.size == max : false)
162
- end
163
- end
164
-
165
134
  def entity_response(data, entity)
166
135
  if qr = data['QueryResponse']
167
136
  qr.empty? ? nil : qr.fetch(singular(entity))
@@ -0,0 +1,31 @@
1
+ class QboApi
2
+ module All
3
+
4
+ def all(entity, max: 1000, select: nil, inactive: false, &block)
5
+ enumerator = create_all_enumerator(entity, max: max, select: select, inactive: inactive)
6
+
7
+ if block_given?
8
+ enumerator.each(&block)
9
+ else
10
+ enumerator
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def create_all_enumerator(entity, max: 1000, select: nil, inactive: false)
17
+ Enumerator.new do |enum_yielder|
18
+ select = build_all_query(entity, select: select, inactive: inactive)
19
+ pos = 0
20
+ begin
21
+ pos = pos == 0 ? pos + 1 : pos + max
22
+ results = query("#{select} MAXRESULTS #{max} STARTPOSITION #{pos}")
23
+ results.each do |entry|
24
+ enum_yielder.yield(entry)
25
+ end if results
26
+ end while (results ? results.size == max : false)
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,47 @@
1
+ class QboApi
2
+ module Finder
3
+
4
+ def query(query, params: nil)
5
+ path = "#{realm_id}/query?query=#{CGI.escape(query)}"
6
+ entity = extract_entity_from_query(query, to_sym: true)
7
+ request(:get, entity: entity, path: path, params: params)
8
+ end
9
+
10
+ def get(entity, type, params: nil)
11
+ if type.is_a?(Array)
12
+ query_str = get_query_str(entity, type)
13
+ if resp = query(query_str, params: params)
14
+ resp.size == 1 ? resp[0] : resp
15
+ else
16
+ false
17
+ end
18
+ else
19
+ path = "#{entity_path(entity)}/#{type}"
20
+ request(:get, entity: entity, path: path, params: params)
21
+ end
22
+ end
23
+
24
+ def to_quote_or_not(str)
25
+ inside_parens_regex = '\(.*\)'
26
+ if str.match(/^(#{inside_parens_regex}|true|false|CURRENT_DATE)$/)
27
+ str
28
+ else
29
+ %{'#{esc(str)}'}
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def get_query_str(entity, type)
36
+ if type.size == 2
37
+ operator = '='
38
+ value = type[1]
39
+ else
40
+ operator = type[1]
41
+ value = type[2]
42
+ end
43
+ "SELECT * FROM #{singular(entity)} WHERE #{type[0]} #{operator} #{to_quote_or_not(value)}"
44
+ end
45
+
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  class QboApi
2
- VERSION = "1.6.2"
2
+ VERSION = "1.6.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qbo_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Pelczarski
@@ -269,11 +269,13 @@ files:
269
269
  - example/views/oauth2.erb
270
270
  - example/views/oauth2_redirect.erb
271
271
  - lib/qbo_api.rb
272
+ - lib/qbo_api/all.rb
272
273
  - lib/qbo_api/attachment.rb
273
274
  - lib/qbo_api/builder.rb
274
275
  - lib/qbo_api/configuration.rb
275
276
  - lib/qbo_api/entity.rb
276
277
  - lib/qbo_api/error.rb
278
+ - lib/qbo_api/finder.rb
277
279
  - lib/qbo_api/raise_http_exception.rb
278
280
  - lib/qbo_api/setter.rb
279
281
  - lib/qbo_api/supporting.rb