realogy 0.6.2 → 0.6.5
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 +45 -13
- data/lib/realogy/app/models/data_sync.rb +41 -12
- data/lib/realogy/app/models/date_time.rb +2 -2
- data/lib/realogy/tasks/realogy.rake +5 -5
- data/lib/realogy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a80f7fefc94aa78eeb2a8fcfc83807471d1b0b289dc3d8e6a42c1816f04aa0a0
|
4
|
+
data.tar.gz: fba2b29565b785c2bfd72e3365e87a5268e60026bedb583edd5669272f791de3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b60f7e64694ccb74122bb9d1dc37cc9c7aafb2cd0cb967a708d884897709e92b80b1a605d8473904b081f4440c1f722043084960e375b797c74adedfbbc5fe30
|
7
|
+
data.tar.gz: 5a910405bee433c9330053d2487ccc92053aea27d3f746ffd638068bf2a2acb5ed5281855e56ed1267ce81306cac9dc5cd4ad0c68afa9a10d25860071cd6e802
|
data/Gemfile.lock
CHANGED
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
|
|
@@ -70,25 +70,50 @@ module Realogy
|
|
70
70
|
'limit': hash[:limit],
|
71
71
|
'status': hash[:status],
|
72
72
|
'toDate': hash[:toDate],
|
73
|
-
'type': hash[:type]
|
73
|
+
'type': hash[:type],
|
74
|
+
'followNext': hash[:followNext]
|
74
75
|
}.compact
|
75
|
-
|
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
|
76
88
|
end
|
77
89
|
end
|
78
90
|
|
79
91
|
DELTA_API_ENDPOINTS.keys.each do |method_name|
|
80
92
|
define_method method_name do |*args|
|
81
|
-
|
82
|
-
hash =
|
83
|
-
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?
|
84
95
|
endpoint = DELTA_API_ENDPOINTS[method_name]
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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)
|
89
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)
|
90
116
|
end
|
91
|
-
return entities.flatten
|
92
117
|
end
|
93
118
|
end
|
94
119
|
|
@@ -151,14 +176,18 @@ module Realogy
|
|
151
176
|
return client.client_credentials.get_token(scope: scope)
|
152
177
|
end
|
153
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
|
+
|
154
183
|
def oauth2_client_credentials_token(client_id, client_secret, token_url, scope)
|
155
|
-
@token = OAuth2::AccessToken.read_token_from_file(
|
184
|
+
@token = OAuth2::AccessToken.read_token_from_file(oauth2_token_path)
|
156
185
|
expiry = @token.try(:expires_at).present? ? DateTime.strptime(@token.expires_at.to_s, '%s') : 1.day.ago
|
157
186
|
if expiry > DateTime.now.utc
|
158
187
|
return @token.token
|
159
188
|
else
|
160
189
|
@token = oauth2_client_credentials_token_object(client_id, client_secret, token_url, scope)
|
161
|
-
@token.save_token_to_file(
|
190
|
+
@token.save_token_to_file(oauth2_token_path)
|
162
191
|
return @token.token
|
163
192
|
end
|
164
193
|
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