reso_api 0.3.0 → 0.4.1

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: 91f8dc7ead6ed968688dfc9c53c0e5a35ed1c4dffe5801fad27d97fae704bf57
4
- data.tar.gz: e5a3d7475620f94bf470fde3e92a4e9dfbd4820c44df7aa1ed056e35bdb04ace
3
+ metadata.gz: 1308c7aa20b15c5aa0182575eb75e2a8a559b666de0ad71e1fd2e88d596e161c
4
+ data.tar.gz: '009565c60f86a0cd7af1272de8be1960577cc721d366d6216799728a6b9d816c'
5
5
  SHA512:
6
- metadata.gz: b1e5e3408a40ee54db7dec2d959a16af34a9f6b31e4590d30116da71a7b81b9513f4de5eb14f996cc3b21a1cd9293a8a48c31841cfbebdf1b2edba7e540cc9c5
7
- data.tar.gz: e7a10e99a931cd6a7e3eeb122d27fbc8c77a872846c4709264d3054586b63fff6a66c56488e9e41d455a95f9c4047df6db92ea114f22502fb3fc1479d2167f40
6
+ metadata.gz: 19afef8507aa12c680ec019d956380d7a9333fb02ea25a35ab1c7695d0c42180490730d8da684125c48e7cc918218566753b1e2ad2834528c362386eae765b03
7
+ data.tar.gz: 808c88eeca611e3b33203de52b865074bbef6ea74bd9ec3aedba809b3627a10ec4ff58ebdab855edaca9fe6cb0d60a2c39774d24b1b3c754dee7ab4c22533774
data/README.md CHANGED
@@ -140,10 +140,27 @@ client.properties(orderby: "City desc")
140
140
  $expand in oData is meant to join two resources together. For the Syndication API this means you can bring in photos to any property query.
141
141
 
142
142
  ```ruby
143
- client.properties(еxpand: "Media")
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,17 @@ 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 (next_link = response["@odata.nextLink"]).present?
68
+ endpoint = next_link.delete_prefix(base_url)
69
+ response = perform_call(endpoint, nil)
70
+ response["value"].each{|hash| block.call(hash)} if response["value"].class.eql?(Array)
71
+ end
72
+ else
73
+ return perform_call(endpoint, params)
74
+ end
65
75
  end
66
76
  end
67
77
 
@@ -1,3 +1,3 @@
1
1
  module ResoApi
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.1"
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.0
4
+ version: 0.4.1
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-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler