reso_api 0.4.7 → 0.5.0

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
  SHA256:
3
- metadata.gz: 9b02d03482a2216a50877b15d2f8ff6951294625470fb09d9fa1753ece52e4f6
4
- data.tar.gz: 3a7d7c7b2dc6af22e9af6575e2556a35b117af5e0839edf004d8f04d7f68ceb5
3
+ metadata.gz: 9c500fe2a36c880879b75b0d1f4784adee06e84efadaaf815659945c69d92110
4
+ data.tar.gz: 6cc7a76f597ca6533a1e9ab46f23047b89b1e2b85d11abfb6aa236271791a859
5
5
  SHA512:
6
- metadata.gz: db880d0367a2a249bb80bca2fddde68fd6aa70a8ab7a54d636a3629c88f2a1538b7adc0c89b9750af68154837c0b5782c1eeb839e2152c9915532ad52b80c70c
7
- data.tar.gz: 2451fdda3931aad5aa2e25d2af334d262988ad1aaef0484fe8f96c368a5e39bb6cb0f1a37ae9a38b5dc93c5e369f0b61e86be23b7716befcf65f622a597308ee
6
+ metadata.gz: ea3db268bf30fda781e07616489b8295f43473103a291b8cd0d8da76586968810f10beaa9ed185f7772de9b5f0f879672c5ce33e98465c1560e1a689988eb85b
7
+ data.tar.gz: fdcdee6fb6c92f2f71f27510a654ed7938166b876cd610c3f09c168f8572c87861250eb6c243e8a2d3b6341cfe37ce64a620b56d726cd4b41d0707cc01e4004e
data/README.md CHANGED
@@ -145,7 +145,7 @@ client.properties(expand: "Media")
145
145
 
146
146
  #### Automatically iterate over all results
147
147
 
148
- By passing a block to Media, Member, Office, and Property resource calls, subsequent paginated calls will automatically be made until the whole result set has been traversed. The block provided is executed for each returned object hash.
148
+ By passing a block to Media, Member, Office, and Property resource calls, subsequent paginated calls will automatically be made until the whole result set has been traversed. The block provided is executed for each returned object hash. The `batch` option can be used to return the full array of results.
149
149
 
150
150
  Here are a couple of examples of how that can be used:
151
151
 
@@ -157,6 +157,10 @@ end
157
157
  client.properties(filter: "StandardStatus eq 'Active'") do |hash|
158
158
  Listing.create(listing_key: hash['ListingKey'], data: hash)
159
159
  end
160
+
161
+ client.properties(filter: "StandardStatus eq 'Active'", batch: true) do |results|
162
+ Listing.insert_all(results) # Perform some batch operation
163
+ end
160
164
  ```
161
165
 
162
166
 
@@ -51,6 +51,7 @@ module RESO
51
51
  hash = args.first.is_a?(Hash) ? args.first : {}
52
52
  endpoint = FILTERABLE_ENDPOINTS[method_name]
53
53
  response = {}
54
+ threads = []
54
55
  params = {
55
56
  "$select": hash[:select],
56
57
  "$filter": hash[:filter],
@@ -62,14 +63,29 @@ module RESO
62
63
  "$count": hash[:count].to_s.presence,
63
64
  "$debug": hash[:debug]
64
65
  }.compact
65
- File.open("timespans", 'a') { |file| file.write("Timestamp\tDuration\tCode\tMessage\tPath\n") }
66
66
  if !block.nil?
67
67
  response = perform_call(endpoint, params)
68
- response["value"].each{|hash| block.call(hash)} if response["value"].class.eql?(Array)
68
+
69
+ if response["value"].class.eql?(Array)
70
+ threads << Thread.new do
71
+ hash[:batch] ? block.call(response["value"]) : response["value"].each{|hash| block.call(hash)}
72
+ end
73
+ end
74
+
69
75
  while (next_link = response["@odata.nextLink"]).present?
70
- response = perform_call(next_link, nil)
71
- response["value"].each{|hash| block.call(hash)} if response["value"].class.eql?(Array)
76
+ threads << Thread.new do
77
+ response = perform_call(next_link, nil)
78
+ end
79
+
80
+ threads.each(&:join)
81
+
82
+ if response["value"].class.eql?(Array)
83
+ threads << Thread.new do
84
+ hash[:batch] ? block.call(response["value"]) : response["value"].each{|hash| block.call(hash)}
85
+ end
86
+ end
72
87
  end
88
+ threads.each(&:join)
73
89
  else
74
90
  return perform_call(endpoint, params)
75
91
  end
@@ -169,6 +185,8 @@ module RESO
169
185
  if (retries += 1) <= 5
170
186
  sleep 10
171
187
  retry
188
+ else
189
+ raise
172
190
  end
173
191
  end
174
192
  return response
@@ -1,3 +1,3 @@
1
1
  module ResoApi
2
- VERSION = "0.4.7"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reso_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Edlund
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-07 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler