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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f02721407645903a2d9ac60db41b1d8cbf634ca114dda8a59d30adc2f965de8c
4
- data.tar.gz: 71e9bdeccb476d4410210361cc296a3185c683f63601da6d01f9560b1e9e8c3c
3
+ metadata.gz: a80f7fefc94aa78eeb2a8fcfc83807471d1b0b289dc3d8e6a42c1816f04aa0a0
4
+ data.tar.gz: fba2b29565b785c2bfd72e3365e87a5268e60026bedb583edd5669272f791de3
5
5
  SHA512:
6
- metadata.gz: f761f642d02074648b93393a673e8174f1152b3f5b4227a073bcfbabbd9fef33edd806c65742becbd1f27a7dcd4a7a4e2e1847a2071afe51774b68a7b07de179
7
- data.tar.gz: 5c0327820519b16c455ef8b6b4f7b8da293c4a4ac2b9558dbaca5f1feaf4217c9a60b104bca774d6434d45db67abdd47fceb8ef4372fc7cd25a165ce6ffac7ed
6
+ metadata.gz: b60f7e64694ccb74122bb9d1dc37cc9c7aafb2cd0cb967a708d884897709e92b80b1a605d8473904b081f4440c1f722043084960e375b797c74adedfbbc5fe30
7
+ data.tar.gz: 5a910405bee433c9330053d2487ccc92053aea27d3f746ffd638068bf2a2acb5ed5281855e56ed1267ce81306cac9dc5cd4ad0c68afa9a10d25860071cd6e802
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- realogy (0.5.9)
4
+ realogy (0.6.3)
5
5
  activerecord (>= 5.0)
6
6
  oauth2
7
7
 
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 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:
198
220
 
199
221
  ```ruby
200
- realogy.get_all_listings(brandCode: "COR", fromDate: 1.week.ago.to_query_string)
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 to_query_string:
207
- realogy.get_all_listings(brandCode: "COR", fromDate: 1.week.ago.to_query_string, toDate: DateTime.now.to_query_string)
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.to_query_string, type: "ForSale")
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.to_query_string, status: "Active")
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.to_query_string, countryCode: "IT")
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.to_query_string, limit: 10)
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
- return perform_api_call(endpoint, params)
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
- entities = []
82
- hash = args.first.is_a?(::Hash) ? args.first : {since: 15.minutes.ago}
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
- response = perform_api_call(endpoint, params)
86
- entities << response["data"]
87
- while response["nextLink"].present?
88
- 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)
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(".oauth-access-token.json")
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(".oauth-access-token.json")
190
+ @token.save_token_to_file(oauth2_token_path)
162
191
  return @token.token
163
192
  end
164
193
  end
@@ -1,11 +1,11 @@
1
1
  DateTime.class_eval do
2
- def to_query_string
2
+ def json_string
3
3
  self.to_json.split("\"").last
4
4
  end
5
5
  end
6
6
 
7
7
  ActiveSupport::TimeWithZone.class_eval do
8
- def to_query_string
8
+ def json_string
9
9
  self.to_datetime.to_json.split("\"").last
10
10
  end
11
11
  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.2"
2
+ VERSION = "0.6.5"
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.2
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Edlund