reso_api 0.2.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: cd054df51a2872e84c6828f7feb57c73657d5d8f0b81ee8635c42373f5b8cdaf
4
- data.tar.gz: 5cbab3e17c508eafe75757797a9ff7201652b7fb3aed8643634d86899627ad5e
3
+ metadata.gz: df418de7906726ce76a9ef70d0b28bb65f21fe04b5264a6e8f2f6eaeb5a67853
4
+ data.tar.gz: 1b193a3d83c5c6449def7557e098f70f1079b01217768587c542fd763f020710
5
5
  SHA512:
6
- metadata.gz: ab2cc31aa83fea44277e85e90969090a11262aaa3a6d6878e910599a516d47229878411f94fad9ad5f242a44029e62dab90e75437f5d297d3c35cfc4653b7632
7
- data.tar.gz: b4763063bd29b3899229c19521d0b841050027e9e4c101bc49a36b4f79cbb418df93b50646de7d99bd4129caea183b4a89bdc2fae4b4ccb46a97cc61315b9b05
6
+ metadata.gz: 94f88f67b6a5e455d0be9964e57941e7546add7f731ec066399e515734554f4b31cfb56eebf69b601977a0126b5ac77011dd3d701392cc4b3732df57dc35e19e
7
+ data.tar.gz: 7662e7a7d27c917cfea6467cefc24c08def9bb332bd2f76eeb88834ffb465767f05ba4400e66dbd33133b9fa7984d4cf568b75911f5265d9b953b72c7bbda80c
data/README.md CHANGED
@@ -31,11 +31,14 @@ To set up an API client and access a service, you need three pieces of informati
31
31
  - Client ID
32
32
  - Client Secret
33
33
  - Base API endpoint
34
+ - Authentication URL
34
35
 
35
- You pass these three pieces of information when creating an instance of an API client:
36
+ You'll recognize the base API endpoint by it ending with /odata, and the authentication URL by it likely ending with /token.
37
+
38
+ You pass these four pieces of information to create an instance of an API client:
36
39
 
37
40
  ```ruby
38
- client = RESO::API::Client.new(client_id: client_id, client_secret: client_secret, base_url: base_url)
41
+ client = RESO::API::Client.new(client_id: client_id, client_secret: client_secret, auth_url: auth_url, base_url: base_url)
39
42
  ```
40
43
 
41
44
  When calling API endpoints using the initialized client, it will automatically fetch and manage access and authentication tokens transparently in the background.
@@ -137,10 +140,27 @@ client.properties(orderby: "City desc")
137
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.
138
141
 
139
142
  ```ruby
140
- client.properties(еxpand: "Media")
143
+ client.properties(expand: "Media")
141
144
  ```
142
145
 
143
- #### 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
144
164
 
145
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.
146
166
 
@@ -200,6 +220,7 @@ client.properties(top: 5, orderby: "ListingKey", skiptoken: "3yd-AAABORMI-320039
200
220
  This gem should work with any RESO Web API compliant service, but these are those that have been confirmed to work.
201
221
 
202
222
  - [ListHub](https://www.listhub.com)
223
+ - [CoreLogic Trestle](https://trestle.corelogic.com)
203
224
 
204
225
  If you use this gem to connect to another service or MLS, please submit a pull request with that service added in alphabetical order in this list.
205
226
 
@@ -7,16 +7,17 @@ module RESO
7
7
  require 'json'
8
8
  require 'tmpdir'
9
9
 
10
- attr_accessor :client_id, :client_secret, :base_url
10
+ attr_accessor :client_id, :client_secret, :auth_url, :base_url
11
11
 
12
12
  def initialize(**opts)
13
- @client_id, @client_secret, @base_url = opts.values_at(:client_id, :client_secret, :base_url)
13
+ @client_id, @client_secret, @auth_url, @base_url = opts.values_at(:client_id, :client_secret, :auth_url, :base_url)
14
14
  validate!
15
15
  end
16
16
 
17
17
  def validate!
18
18
  raise 'Missing Client ID `client_id`' if client_id.nil?
19
19
  raise 'Missing Client Secret `client_secret`' if client_secret.nil?
20
+ raise 'Missing Authentication URL `auth_url`' if auth_url.nil?
20
21
  raise 'Missing API Base URL `base_url`' if base_url.nil?
21
22
  end
22
23
 
@@ -28,25 +29,25 @@ module RESO
28
29
  }
29
30
 
30
31
  DETAIL_ENDPOINTS = {
31
- medium: "odata/Media",
32
- member: "odata/Member",
33
- office: "odata/Office",
34
- property: "odata/Property"
32
+ medium: "/Media",
33
+ member: "/Member",
34
+ office: "/Office",
35
+ property: "/Property"
35
36
  }
36
37
 
37
38
  FILTERABLE_ENDPOINTS = {
38
- media: "odata/Media",
39
- members: "odata/Member",
40
- offices: "odata/Office",
41
- properties: "odata/Property"
39
+ media: "/Media",
40
+ members: "/Member",
41
+ offices: "/Office",
42
+ properties: "/Property"
42
43
  }
43
44
 
44
45
  PASSTHROUGH_ENDPOINTS = {
45
- metadata: "odata/$metadata"
46
+ metadata: "/$metadata"
46
47
  }
47
48
 
48
49
  FILTERABLE_ENDPOINTS.keys.each do |method_name|
49
- define_method method_name do |*args|
50
+ define_method method_name do |*args, &block|
50
51
  hash = args.first.is_a?(Hash) ? args.first : {}
51
52
  endpoint = FILTERABLE_ENDPOINTS[method_name]
52
53
  params = {
@@ -60,7 +61,16 @@ module RESO
60
61
  "$count": hash[:count].to_s.presence,
61
62
  "$debug": hash[:debug]
62
63
  }.compact
63
- 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
64
74
  end
65
75
  end
66
76
 
@@ -82,7 +92,9 @@ module RESO
82
92
  OAuth2::Client.new(
83
93
  client_id,
84
94
  client_secret,
85
- token_url: [base_url, "oauth2/token"].join
95
+ token_url: auth_url,
96
+ scope: "api",
97
+ grant_type: "client_credentials"
86
98
  )
87
99
  end
88
100
 
@@ -1,3 +1,3 @@
1
1
  module ResoApi
2
- VERSION = "0.2.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.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Edlund
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-23 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
@@ -107,7 +107,7 @@ files:
107
107
  homepage: https://github.com/arcticleo/reso_api
108
108
  licenses: []
109
109
  metadata: {}
110
- post_install_message:
110
+ post_install_message:
111
111
  rdoc_options: []
112
112
  require_paths:
113
113
  - lib
@@ -122,8 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  requirements: []
125
- rubygems_version: 3.1.4
126
- signing_key:
125
+ rubygems_version: 3.3.7
126
+ signing_key:
127
127
  specification_version: 4
128
128
  summary: RESO Web API Wrapper
129
129
  test_files: []