reso_api 0.3.1 → 0.4.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: d4a950c58781ec5c74884efd37ceb091855cdc061e491c83a206d47e8121a4a7
4
- data.tar.gz: a05ad1c1835d3d097e828462028132cd1b508bc1eee4a475bee94c112dfbe38c
3
+ metadata.gz: df418de7906726ce76a9ef70d0b28bb65f21fe04b5264a6e8f2f6eaeb5a67853
4
+ data.tar.gz: 1b193a3d83c5c6449def7557e098f70f1079b01217768587c542fd763f020710
5
5
  SHA512:
6
- metadata.gz: 8076aca2231e877bd54c27a64595dfa6f58ee8e5078ba6d5f4d289b7e642387ad28407485e7203ffb4e1416f8ebc813be3906393a60ba726494ca9ca4af4789a
7
- data.tar.gz: 54b68fdbcdde0c9332db35b862c83497ffd0df1f19e676fe390a3bd6bf1246f3cf15723214bbb75f9867df0a0ab7ad6252ec6f7123071041d500bb87b76cd4d0
6
+ metadata.gz: 94f88f67b6a5e455d0be9964e57941e7546add7f731ec066399e515734554f4b31cfb56eebf69b601977a0126b5ac77011dd3d701392cc4b3732df57dc35e19e
7
+ data.tar.gz: 7662e7a7d27c917cfea6467cefc24c08def9bb332bd2f76eeb88834ffb465767f05ba4400e66dbd33133b9fa7984d4cf568b75911f5265d9b953b72c7bbda80c
data/README.md CHANGED
@@ -143,7 +143,24 @@ $expand in oData is meant to join two resources together. For the Syndication AP
143
143
  client.properties(expand: "Media")
144
144
  ```
145
145
 
146
- #### Pagination, $top, and $skip
146
+ #### Automatically iterate over all results
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.
149
+
150
+ Here are a couple of examples of how that can be used:
151
+
152
+ ```ruby
153
+ client.properties(filter: "StandardStatus eq 'Active'") do |hash|
154
+ puts "#{hash['ListingKey']} – #{hash['UnparsedAddress']}"
155
+ end
156
+
157
+ client.properties(filter: "StandardStatus eq 'Active'") do |hash|
158
+ Listing.create(listing_key: hash['ListingKey'], data: hash)
159
+ end
160
+ ```
161
+
162
+
163
+ #### Manually iterate over all results
147
164
 
148
165
  The default number of results returned is 100. You can override the default limit using the `$top` parameter. The higher the number specific for `$top`, the longer the API response will take, and pay attention to that different services does enforce a cap for number of records returned.
149
166
 
@@ -47,7 +47,7 @@ module RESO
47
47
  }
48
48
 
49
49
  FILTERABLE_ENDPOINTS.keys.each do |method_name|
50
- define_method method_name do |*args|
50
+ define_method method_name do |*args, &block|
51
51
  hash = args.first.is_a?(Hash) ? args.first : {}
52
52
  endpoint = FILTERABLE_ENDPOINTS[method_name]
53
53
  params = {
@@ -61,7 +61,16 @@ module RESO
61
61
  "$count": hash[:count].to_s.presence,
62
62
  "$debug": hash[:debug]
63
63
  }.compact
64
- return perform_call(endpoint, params)
64
+ if !block.nil?
65
+ response = perform_call(endpoint, params)
66
+ response["value"].each{|hash| block.call(hash)} if response["value"].class.eql?(Array)
67
+ while response["@odata.nextLink"].present?
68
+ response = perform_call(response["@odata.nextLink"], nil)
69
+ response["value"].each{|hash| block.call(hash)} if response["value"].class.eql?(Array)
70
+ end
71
+ else
72
+ return perform_call(endpoint, params)
73
+ end
65
74
  end
66
75
  end
67
76
 
@@ -1,3 +1,3 @@
1
1
  module ResoApi
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.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.3.1
4
+ version: 0.4.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-03-04 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler