realogy 0.6.0 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +56 -14
- data/lib/realogy/app/models/data_sync.rb +48 -13
- data/lib/realogy/app/models/date_time.rb +11 -0
- data/lib/realogy/version.rb +1 -1
- data/lib/realogy.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aab45e699e4b2c1f6ba3fef7e61a61b8b2f7fcc139ed4ff1da6aba33ce59111f
|
4
|
+
data.tar.gz: 9e71798f4f6b24b7ce0b6e1dd30ebf786a85c339a4469aa4b0e9e47caf774bd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ad2a9d30633e053bd1349ce784f8fee960e1ae1dcf69d99d76d129f21827484709793dcf0a3c9608023157e5cdfbcfaa4ec32f8caecc1fc73a9e81348ff9e77
|
7
|
+
data.tar.gz: 3786088a323b5d662d61adcc410ee6c42fbd955e1022e1e3a52dfdc3ccd026cebaf3807b2c00e94cf47a61d7a8c414112e18e1c403743f5c61d198722b5a4ba5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -31,15 +31,16 @@ Set up for usage by creating Realogy's migration and running it.
|
|
31
31
|
rails g realogy:install
|
32
32
|
rails db:migrate
|
33
33
|
|
34
|
-
Realogy is expecting these
|
34
|
+
Realogy is expecting these encrypted credentials to be present to be able to function:
|
35
35
|
|
36
36
|
```
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
realogy:
|
38
|
+
client_id:
|
39
|
+
client_secret:
|
40
|
+
token_url:
|
41
|
+
scope:
|
42
|
+
subscription_key:
|
43
|
+
api_base_url:
|
43
44
|
```
|
44
45
|
|
45
46
|
### Available Rake Tasks
|
@@ -127,9 +128,10 @@ config.active_job.queue_adapter = :delayed_job
|
|
127
128
|
```ruby
|
128
129
|
realogy = Realogy::DataSync.client
|
129
130
|
```
|
130
|
-
#### Retrieve array of objects
|
131
131
|
|
132
|
-
|
132
|
+
#### Get active objects
|
133
|
+
|
134
|
+
The calls to retrieve active entities are:
|
133
135
|
|
134
136
|
```ruby
|
135
137
|
realogy.get_active_agents
|
@@ -139,20 +141,31 @@ realogy.get_active_offices
|
|
139
141
|
realogy.get_active_teams
|
140
142
|
```
|
141
143
|
|
142
|
-
When no argument is submitted, all entities are returned.
|
144
|
+
When no argument is submitted, all active entities are returned.
|
145
|
+
|
146
|
+
Filters can be applied for `brandCode` and `countryCode`. For example:
|
143
147
|
|
144
148
|
```ruby
|
145
149
|
# Fetch all active agents, for all brands, in all countries:
|
146
|
-
realogy.get_active_agents
|
150
|
+
realogy.get_active_agents
|
147
151
|
|
148
152
|
# Fetch all active agents, for all brands, in Sweden:
|
149
|
-
realogy.
|
153
|
+
realogy.get_active_companies(countryCode: "SE")
|
150
154
|
|
155
|
+
# Allowed brandCode values: C21, CB, ERA, SIR, BHG, CBC, ZIP, CLB, & COR
|
151
156
|
# Fetch all active Sotheby's agents in all countries:
|
152
|
-
realogy.
|
157
|
+
realogy.get_active_offices(brandCode: "SIR")
|
153
158
|
|
154
159
|
# Fetch all active Sotheby's agents in Sweden:
|
155
|
-
realogy.
|
160
|
+
realogy.get_active_teams(brandCode: "SIR", countryCode: "SE")
|
161
|
+
```
|
162
|
+
|
163
|
+
When fetching listings, the type of listing can also be specified:
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
# Allowed type values: ForSale, ForRent, ForSaleCommercial, & ForLeaseCommercial
|
167
|
+
# Fetch all active agents, for all brands, in all countries:
|
168
|
+
realogy.get_active_listings(type: "ForSale")
|
156
169
|
```
|
157
170
|
|
158
171
|
#### Retrieve delta of objects
|
@@ -179,6 +192,35 @@ realogy.get_offices_delta({since: 5.minutes.ago})
|
|
179
192
|
realogy.get_teams_delta({since: 1.day.ago})
|
180
193
|
```
|
181
194
|
|
195
|
+
#### Get all listings
|
196
|
+
|
197
|
+
To retrieve all listings, `fromDate` and `brandCode` are mandatory parameters. A minimum call to retrieve all listing entities could look like this:
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
realogy.get_all_listings(brandCode: "COR", fromDate: 1.week.ago.to_query_string)
|
201
|
+
```
|
202
|
+
|
203
|
+
These are additional filters that can be applied:
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
# fromDate and toDate must be converted to supported text format. This is done with to_query_string:
|
207
|
+
realogy.get_all_listings(brandCode: "COR", fromDate: 1.week.ago.to_query_string, toDate: DateTime.now.to_query_string)
|
208
|
+
|
209
|
+
# Allowed type values: ForSale, ForRent, ForSaleCommercial, & ForLeaseCommercial
|
210
|
+
realogy.get_all_listings(brandCode: "C21", fromDate: 1.week.ago.to_query_string, type: "ForSale")
|
211
|
+
|
212
|
+
# Allowed status values: Active, Available, Pending, & Closed
|
213
|
+
realogy.get_all_listings(brandCode: "CB", fromDate: 1.week.ago.to_query_string, status: "Active")
|
214
|
+
|
215
|
+
# Limit results to a particular country
|
216
|
+
realogy.get_all_listings(brandCode: "SIR", fromDate: 1.week.ago.to_query_string, countryCode: "IT")
|
217
|
+
|
218
|
+
# Limit number of listings per result batch. Allowed span: 10–1000.
|
219
|
+
realogy.get_all_listings(brandCode: "BHG", fromDate: 1.week.ago.to_query_string, limit: 10)
|
220
|
+
|
221
|
+
```
|
222
|
+
|
223
|
+
|
182
224
|
#### Retrieve JSON object
|
183
225
|
|
184
226
|
```ruby
|
@@ -4,13 +4,13 @@ module Realogy
|
|
4
4
|
require 'net/http'
|
5
5
|
require 'oauth2'
|
6
6
|
require 'json'
|
7
|
-
|
7
|
+
|
8
8
|
@@instance = Realogy::DataSync.new
|
9
9
|
|
10
10
|
def self.client
|
11
11
|
return @@instance
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
private_class_method :new
|
15
15
|
|
16
16
|
# API endpoints by type
|
@@ -23,6 +23,10 @@ module Realogy
|
|
23
23
|
get_active_teams: "teams/active"
|
24
24
|
}
|
25
25
|
|
26
|
+
ALL_API_ENDPOINTS = {
|
27
|
+
get_all_listings: "listings/all"
|
28
|
+
}
|
29
|
+
|
26
30
|
DELTA_API_ENDPOINTS = {
|
27
31
|
get_agents_delta: "agents/delta",
|
28
32
|
get_companies_delta: "companies/delta",
|
@@ -47,12 +51,43 @@ module Realogy
|
|
47
51
|
endpoint = ACTIVE_API_ENDPOINTS[method_name]
|
48
52
|
params = {
|
49
53
|
'brandCode': hash[:brandCode],
|
50
|
-
'countryCode': hash[:countryCode]
|
54
|
+
'countryCode': hash[:countryCode],
|
55
|
+
'type': hash[:type]
|
51
56
|
}.compact
|
52
57
|
return perform_api_call(endpoint, params)
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
61
|
+
ALL_API_ENDPOINTS.keys.each do |method_name|
|
62
|
+
define_method method_name do |*args|
|
63
|
+
hash = args.first.is_a?(::Hash) ? args.first : {}
|
64
|
+
endpoint = ALL_API_ENDPOINTS[method_name]
|
65
|
+
params = {
|
66
|
+
'brandCode': hash[:brandCode],
|
67
|
+
'countryCode': hash[:countryCode],
|
68
|
+
'cursor': hash[:cursor],
|
69
|
+
'fromDate': hash[:fromDate],
|
70
|
+
'limit': hash[:limit],
|
71
|
+
'status': hash[:status],
|
72
|
+
'toDate': hash[:toDate],
|
73
|
+
'type': hash[:type],
|
74
|
+
'followNext': hash[:followNext]
|
75
|
+
}.compact
|
76
|
+
if hash[:followNext]
|
77
|
+
entities = []
|
78
|
+
response = perform_api_call(endpoint, params)
|
79
|
+
entities << response["data"]
|
80
|
+
while response["nextLink"].present?
|
81
|
+
response = perform_simple_call(response["nextLink"])
|
82
|
+
entities << response["data"]
|
83
|
+
end
|
84
|
+
return entities.flatten
|
85
|
+
else
|
86
|
+
return perform_api_call(endpoint, params)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
56
91
|
DELTA_API_ENDPOINTS.keys.each do |method_name|
|
57
92
|
define_method method_name do |*args|
|
58
93
|
entities = []
|
@@ -81,13 +116,13 @@ module Realogy
|
|
81
116
|
# Utility
|
82
117
|
|
83
118
|
def uri_for_endpoint endpoint
|
84
|
-
return URI([
|
119
|
+
return URI([Rails.application.credentials.dig(:realogy, :api_base_url), endpoint].join("/"))
|
85
120
|
end
|
86
121
|
|
87
122
|
def perform_simple_call(url)
|
88
123
|
uri = URI(url)
|
89
124
|
request = Net::HTTP::Get.new(uri)
|
90
|
-
request['Ocp-Apim-Subscription-Key'] =
|
125
|
+
request['Ocp-Apim-Subscription-Key'] = Rails.application.credentials.dig(:realogy, :subscription_key)
|
91
126
|
request['Authorization'] = "Bearer #{auth_token}"
|
92
127
|
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
93
128
|
http.max_retries = 10
|
@@ -101,7 +136,7 @@ module Realogy
|
|
101
136
|
uri = uri_for_endpoint(endpoint)
|
102
137
|
uri.query && uri.query.length > 0 ? uri.query += '&' + query : uri.query = query
|
103
138
|
request = Net::HTTP::Get.new(uri.request_uri)
|
104
|
-
request['Ocp-Apim-Subscription-Key'] =
|
139
|
+
request['Ocp-Apim-Subscription-Key'] = Rails.application.credentials.dig(:realogy, :subscription_key)
|
105
140
|
request['Authorization'] = "Bearer #{auth_token}"
|
106
141
|
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
107
142
|
http.max_retries = 10
|
@@ -112,10 +147,10 @@ module Realogy
|
|
112
147
|
|
113
148
|
def auth_token
|
114
149
|
oauth2_client_credentials_token(
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
150
|
+
Rails.application.credentials.dig(:realogy, :client_id),
|
151
|
+
Rails.application.credentials.dig(:realogy, :client_secret),
|
152
|
+
Rails.application.credentials.dig(:realogy, :token_url),
|
153
|
+
Rails.application.credentials.dig(:realogy, :scope)
|
119
154
|
)
|
120
155
|
end
|
121
156
|
|
@@ -148,9 +183,9 @@ OAuth2::AccessToken.class_eval do
|
|
148
183
|
data = nil
|
149
184
|
token = nil
|
150
185
|
client = OAuth2::Client.new(
|
151
|
-
|
152
|
-
|
153
|
-
token_url:
|
186
|
+
Rails.application.credentials.dig(:realogy, :client_id),
|
187
|
+
Rails.application.credentials.dig(:realogy, :client_secret),
|
188
|
+
token_url: Rails.application.credentials.dig(:realogy, :token_url)
|
154
189
|
)
|
155
190
|
if File.exists?(path)
|
156
191
|
File.open(path) do |f|
|
data/lib/realogy/version.rb
CHANGED
data/lib/realogy.rb
CHANGED
@@ -2,6 +2,7 @@ require "realogy/version"
|
|
2
2
|
require "realogy/railtie" if defined?(Rails)
|
3
3
|
require "realogy/app/models/application_record.rb"
|
4
4
|
require "realogy/app/models/data_sync.rb"
|
5
|
+
require "realogy/app/models/date_time.rb"
|
5
6
|
require "realogy/app/models/hash.rb"
|
6
7
|
require "realogy/app/models/realogy/entity.rb"
|
7
8
|
require "realogy/app/models/realogy/agent.rb"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: realogy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
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-
|
11
|
+
date: 2022-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- lib/realogy/app/jobs/populate_realogy_entity_job.rb
|
121
121
|
- lib/realogy/app/models/application_record.rb
|
122
122
|
- lib/realogy/app/models/data_sync.rb
|
123
|
+
- lib/realogy/app/models/date_time.rb
|
123
124
|
- lib/realogy/app/models/hash.rb
|
124
125
|
- lib/realogy/app/models/realogy/agent.rb
|
125
126
|
- lib/realogy/app/models/realogy/company.rb
|