realogy 0.6.3 → 0.6.4
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/README.md +38 -6
- data/lib/realogy/app/models/data_sync.rb +27 -10
- 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: 8bd21ebae2bdd067d907b8be8b4205f91874e8074f83189bcb719d793e251672
|
4
|
+
data.tar.gz: a9afc5328a86797ec677fd28aaaf1d1932bc29cf65a84e906b956c9d7ac76897
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb23e4584877fb4a473f05ee86d68a7a325adde0a7941a43f643d18b94238522673188f0d2adb8f80b332b2eb02614d97503c0404d9239072ec4247eff9b90de
|
7
|
+
data.tar.gz: 79329f73bdcc2f6467b46246e105bad993ee24bc335d3bd64e0fdd2001cc8cedb309a2949ef26be20ad7badd6b024ff1c22f5f25c8136ff09f7695ca1c39bc7b
|
data/README.md
CHANGED
@@ -182,16 +182,38 @@ 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:
|
@@ -220,6 +242,16 @@ realogy.get_all_listings(brandCode: "BHG", fromDate: 1.week.ago.to_query_string,
|
|
220
242
|
|
221
243
|
```
|
222
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)
|
251
|
+
```
|
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
|
@@ -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