realogy 0.6.3 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -13
- data/lib/realogy/app/models/data_sync.rb +27 -10
- data/lib/realogy/app/models/date_time.rb +2 -2
- data/lib/realogy/app/models/realogy/entity.rb +8 -4
- data/lib/realogy/tasks/realogy.rake +5 -5
- data/lib/realogy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aa56109fdeb645bb6a4544df6faae341203c0534ff8d50a0c47ab0e6753c194
|
4
|
+
data.tar.gz: b8ce2398aacae3dc9d732796a54e136df42827db293c6426e1efe461954ff7fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e78dfe59e417f9afbb2ccd7d9089b42c66c891c0cb17177dd9ff7d615c117cf1593165a064034d2a666c9ff655518584926505b86e2adade54c11046c65e10e
|
7
|
+
data.tar.gz: 52fa17778ad6ac7334f15a8ba83d50ded61fda896689a885bbf18c30063d9cdef0e34036dcfea825d5fb336156fc35bbd7768621ba53d6b36b987fc44c2fb9c7
|
data/README.md
CHANGED
@@ -182,44 +182,76 @@ realogy.get_teams_delta
|
|
182
182
|
|
183
183
|
Each hash in the returned arrays includes a key `action` that returns either `Delete` or `Upsert` to indicate if the object has been deleted or created/updated.
|
184
184
|
|
185
|
-
When no argument is passed, the delta returned is for the last
|
185
|
+
When no argument is passed, the delta returned is for the last 20 minutes. A custom minutes delta can be passed in:
|
186
186
|
|
187
187
|
```ruby
|
188
|
-
realogy.get_agents_delta(
|
189
|
-
realogy.get_companies_delta(
|
190
|
-
realogy.get_listings_delta(
|
191
|
-
realogy.get_offices_delta(
|
192
|
-
realogy.get_teams_delta(
|
188
|
+
realogy.get_agents_delta(since: 20.minutes.ago) # 20 minutes is the default
|
189
|
+
realogy.get_companies_delta(since: 1.hour.ago)
|
190
|
+
realogy.get_listings_delta(since: 2.hours.ago)
|
191
|
+
realogy.get_offices_delta(since: 5.minutes.ago)
|
192
|
+
realogy.get_teams_delta(since: 1.day.ago)
|
193
193
|
```
|
194
194
|
|
195
|
+
A few additional parameters are allowed:
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
realogy.get_listings_delta(brandCode: "SIR")
|
199
|
+
realogy.get_listings_delta(companyIds: "12345")
|
200
|
+
realogy.get_listings_delta(companyIds: "12345, 23456, 34567")
|
201
|
+
realogy.get_listings_delta(countryCode: "IT")
|
202
|
+
realogy.get_listings_delta(limit: 10)
|
203
|
+
realogy.get_listings_delta(type: "ForSale")
|
204
|
+
```
|
205
|
+
|
206
|
+
In case there are more entities available than is returned by the initial call, there will be a `nextLink` value present in the JSON response. By calling the `nextLink` URL as long as it is present, you will make retrieve all results.
|
207
|
+
|
208
|
+
If you want to automatically return all entities, pass in the flag `followNext: true` in your call:
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
realogy.get_listings_delta( ... , followNext: true)
|
212
|
+
```
|
213
|
+
|
214
|
+
When passing in `followNext: true`, the returned result will be an array of entities rather than the JSON object returned if it is omitted.
|
215
|
+
|
216
|
+
|
195
217
|
#### Get all listings
|
196
218
|
|
197
219
|
To retrieve all listings, `fromDate` and `brandCode` are mandatory parameters. A minimum call to retrieve all listing entities could look like this:
|
198
220
|
|
199
221
|
```ruby
|
200
|
-
realogy.get_all_listings(brandCode: "COR", fromDate: 1.week.ago.
|
222
|
+
realogy.get_all_listings(brandCode: "COR", fromDate: 1.week.ago.json_string)
|
201
223
|
```
|
202
224
|
|
203
225
|
These are additional filters that can be applied:
|
204
226
|
|
205
227
|
```ruby
|
206
|
-
# fromDate and toDate must be converted to supported text format. This is done with
|
207
|
-
realogy.get_all_listings(brandCode: "COR", fromDate: 1.week.ago.
|
228
|
+
# fromDate and toDate must be converted to supported text format. This is done with json_string:
|
229
|
+
realogy.get_all_listings(brandCode: "COR", fromDate: 1.week.ago.json_string, toDate: DateTime.now.json_string)
|
208
230
|
|
209
231
|
# Allowed type values: ForSale, ForRent, ForSaleCommercial, & ForLeaseCommercial
|
210
|
-
realogy.get_all_listings(brandCode: "C21", fromDate: 1.week.ago.
|
232
|
+
realogy.get_all_listings(brandCode: "C21", fromDate: 1.week.ago.json_string, type: "ForSale")
|
211
233
|
|
212
234
|
# Allowed status values: Active, Available, Pending, & Closed
|
213
|
-
realogy.get_all_listings(brandCode: "CB", fromDate: 1.week.ago.
|
235
|
+
realogy.get_all_listings(brandCode: "CB", fromDate: 1.week.ago.json_string, status: "Active")
|
214
236
|
|
215
237
|
# Limit results to a particular country
|
216
|
-
realogy.get_all_listings(brandCode: "SIR", fromDate: 1.week.ago.
|
238
|
+
realogy.get_all_listings(brandCode: "SIR", fromDate: 1.week.ago.json_string, countryCode: "IT")
|
217
239
|
|
218
240
|
# Limit number of listings per result batch. Allowed span: 10–1000.
|
219
|
-
realogy.get_all_listings(brandCode: "BHG", fromDate: 1.week.ago.
|
241
|
+
realogy.get_all_listings(brandCode: "BHG", fromDate: 1.week.ago.json_string, limit: 10)
|
242
|
+
|
243
|
+
```
|
220
244
|
|
245
|
+
In case there are more listings available than is returned by the `get_all_listings` call, there will be a `nextLink` value present in the JSON response. By calling the `nextLink` URL as long as it is present, you will traverse through all results.
|
246
|
+
|
247
|
+
If you want to automatically return all results, pass in the flag `followNext: true` in your call:
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
realogy.get_all_listings( ... , followNext: true)
|
221
251
|
```
|
222
252
|
|
253
|
+
When passing in `followNext: true`, the returned result will be an array of entities rather than the JSON object returned if it is omitted.
|
254
|
+
|
223
255
|
|
224
256
|
#### Retrieve JSON object
|
225
257
|
|
@@ -90,17 +90,30 @@ module Realogy
|
|
90
90
|
|
91
91
|
DELTA_API_ENDPOINTS.keys.each do |method_name|
|
92
92
|
define_method method_name do |*args|
|
93
|
-
|
94
|
-
hash =
|
95
|
-
params = {'since': JSON[hash[:since].to_json]}
|
93
|
+
hash = args.first.is_a?(::Hash) ? args.first : {}
|
94
|
+
hash[:since] = JSON(20.minutes.ago.to_json) if hash[:since].blank?
|
96
95
|
endpoint = DELTA_API_ENDPOINTS[method_name]
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
96
|
+
params = {
|
97
|
+
'since': JSON[hash[:since].to_json],
|
98
|
+
'brandCode': hash[:brandCode],
|
99
|
+
'companyIds': hash[:companyIds].to_s.split(',').map(&:strip),
|
100
|
+
'countryCode': hash[:countryCode],
|
101
|
+
'limit': hash[:limit],
|
102
|
+
'type': hash[:type],
|
103
|
+
'followNext': hash[:followNext]
|
104
|
+
}.compact
|
105
|
+
if hash[:followNext]
|
106
|
+
entities = []
|
107
|
+
response = perform_api_call(endpoint, params)
|
101
108
|
entities << response["data"]
|
109
|
+
while response["nextLink"].present?
|
110
|
+
response = perform_simple_call(response["nextLink"])
|
111
|
+
entities << response["data"]
|
112
|
+
end
|
113
|
+
return entities.flatten
|
114
|
+
else
|
115
|
+
return perform_api_call(endpoint, params)
|
102
116
|
end
|
103
|
-
return entities.flatten
|
104
117
|
end
|
105
118
|
end
|
106
119
|
|
@@ -163,14 +176,18 @@ module Realogy
|
|
163
176
|
return client.client_credentials.get_token(scope: scope)
|
164
177
|
end
|
165
178
|
|
179
|
+
def oauth2_token_path
|
180
|
+
return File.join(Dir.tmpdir, [Rails.application.credentials.dig(:realogy, :client_id).parameterize, "-oauth-token.json"].join)
|
181
|
+
end
|
182
|
+
|
166
183
|
def oauth2_client_credentials_token(client_id, client_secret, token_url, scope)
|
167
|
-
@token = OAuth2::AccessToken.read_token_from_file(
|
184
|
+
@token = OAuth2::AccessToken.read_token_from_file(oauth2_token_path)
|
168
185
|
expiry = @token.try(:expires_at).present? ? DateTime.strptime(@token.expires_at.to_s, '%s') : 1.day.ago
|
169
186
|
if expiry > DateTime.now.utc
|
170
187
|
return @token.token
|
171
188
|
else
|
172
189
|
@token = oauth2_client_credentials_token_object(client_id, client_secret, token_url, scope)
|
173
|
-
@token.save_token_to_file(
|
190
|
+
@token.save_token_to_file(oauth2_token_path)
|
174
191
|
return @token.token
|
175
192
|
end
|
176
193
|
end
|
@@ -2,7 +2,7 @@ class Realogy::Entity < ApplicationRecord
|
|
2
2
|
self.table_name = 'realogy_entities'
|
3
3
|
|
4
4
|
validates :type, presence: true
|
5
|
-
validates :entity_id, presence: true
|
5
|
+
validates :entity_id, presence: true, uniqueness: true
|
6
6
|
validates :last_update_on, presence: true
|
7
7
|
|
8
8
|
def needs_updating?
|
@@ -14,10 +14,14 @@ class Realogy::Entity < ApplicationRecord
|
|
14
14
|
@object.last_update_on = hash["lastUpdateOn"].to_s.to_datetime
|
15
15
|
@object.populate if @object.needs_updating?
|
16
16
|
end
|
17
|
-
|
18
|
-
def
|
17
|
+
|
18
|
+
def get_data
|
19
19
|
call = ["get_", self.class.to_s.downcase.split("::").last, "_by_id"].join.to_sym
|
20
|
-
|
20
|
+
Realogy::DataSync.client.__send__(call, self.entity_id)
|
21
|
+
end
|
22
|
+
|
23
|
+
def populate
|
24
|
+
result = get_data
|
21
25
|
self.data = result unless result.blank?
|
22
26
|
self.save if self.changed?
|
23
27
|
end
|
@@ -108,31 +108,31 @@ namespace :realogy do
|
|
108
108
|
|
109
109
|
desc "Delta update for Agents. Optionally provide delta in minutes."
|
110
110
|
task :sync_agents_delta, [:since_minutes] => [:environment] do |t, args|
|
111
|
-
args.with_defaults(since_minutes:
|
111
|
+
args.with_defaults(since_minutes: 20)
|
112
112
|
perform_delta_update_for Realogy::Agent, args[:since_minutes]
|
113
113
|
end
|
114
114
|
|
115
115
|
desc "Delta update for Companies. Optionally provide delta in minutes."
|
116
116
|
task :sync_companies_delta, [:since_minutes] => [:environment] do |t, args|
|
117
|
-
args.with_defaults(since_minutes:
|
117
|
+
args.with_defaults(since_minutes: 20)
|
118
118
|
perform_delta_update_for Realogy::Company, args[:since_minutes]
|
119
119
|
end
|
120
120
|
|
121
121
|
desc "Delta update for Listings. Optionally provide delta in minutes."
|
122
122
|
task :sync_listings_delta, [:since_minutes] => [:environment] do |t, args|
|
123
|
-
args.with_defaults(since_minutes:
|
123
|
+
args.with_defaults(since_minutes: 20)
|
124
124
|
perform_delta_update_for Realogy::Listing, args[:since_minutes]
|
125
125
|
end
|
126
126
|
|
127
127
|
desc "Delta update for Offices. Optionally provide delta in minutes."
|
128
128
|
task :sync_offices_delta, [:since_minutes] => [:environment] do |t, args|
|
129
|
-
args.with_defaults(since_minutes:
|
129
|
+
args.with_defaults(since_minutes: 20)
|
130
130
|
perform_delta_update_for Realogy::Office, args[:since_minutes]
|
131
131
|
end
|
132
132
|
|
133
133
|
desc "Delta update for Teams. Optionally provide delta in minutes."
|
134
134
|
task :sync_teams_delta, [:since_minutes] => [:environment] do |t, args|
|
135
|
-
args.with_defaults(since_minutes:
|
135
|
+
args.with_defaults(since_minutes: 20)
|
136
136
|
perform_delta_update_for Realogy::Team, args[:since_minutes]
|
137
137
|
end
|
138
138
|
|
data/lib/realogy/version.rb
CHANGED
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.6
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|