realogy 0.6.3 → 0.6.4

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: aab45e699e4b2c1f6ba3fef7e61a61b8b2f7fcc139ed4ff1da6aba33ce59111f
4
- data.tar.gz: 9e71798f4f6b24b7ce0b6e1dd30ebf786a85c339a4469aa4b0e9e47caf774bd7
3
+ metadata.gz: 8bd21ebae2bdd067d907b8be8b4205f91874e8074f83189bcb719d793e251672
4
+ data.tar.gz: a9afc5328a86797ec677fd28aaaf1d1932bc29cf65a84e906b956c9d7ac76897
5
5
  SHA512:
6
- metadata.gz: 5ad2a9d30633e053bd1349ce784f8fee960e1ae1dcf69d99d76d129f21827484709793dcf0a3c9608023157e5cdfbcfaa4ec32f8caecc1fc73a9e81348ff9e77
7
- data.tar.gz: 3786088a323b5d662d61adcc410ee6c42fbd955e1022e1e3a52dfdc3ccd026cebaf3807b2c00e94cf47a61d7a8c414112e18e1c403743f5c61d198722b5a4ba5
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 15 minutes. A custom minutes delta can be passed in:
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({since: 15.minutes.ago}) # 15 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})
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
- entities = []
94
- hash = args.first.is_a?(::Hash) ? args.first : {since: 15.minutes.ago}
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
- response = perform_api_call(endpoint, params)
98
- entities << response["data"]
99
- while response["nextLink"].present?
100
- response = perform_simple_call(response["nextLink"])
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(".oauth-access-token.json")
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(".oauth-access-token.json")
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: 15)
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: 15)
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: 15)
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: 15)
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: 15)
135
+ args.with_defaults(since_minutes: 20)
136
136
  perform_delta_update_for Realogy::Team, args[:since_minutes]
137
137
  end
138
138
 
@@ -1,3 +1,3 @@
1
1
  module Realogy
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: realogy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Edlund