realogy 0.6.0 → 0.6.3

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: cd7ef6df4687d14ecd5f52c86533588c914184f0a9c3d68c78432d2ea5946aca
4
- data.tar.gz: 5a4ad93bc7453b08427c0de9bce3231809915e6ba2e9d557e62bd5861b3fc266
3
+ metadata.gz: aab45e699e4b2c1f6ba3fef7e61a61b8b2f7fcc139ed4ff1da6aba33ce59111f
4
+ data.tar.gz: 9e71798f4f6b24b7ce0b6e1dd30ebf786a85c339a4469aa4b0e9e47caf774bd7
5
5
  SHA512:
6
- metadata.gz: f43e3d9c6bb73e924a74d0788d116b81caee67a42d924a20c7f9f54217fd00b5934486bf618a8b2fb6f1733099881093c302945678ff0a9f034227dc65081372
7
- data.tar.gz: 7020419b4f767b7ad66cb5a4de2c2624db5f2fd8909d98431032b30da2db3f5f93fe4521c820eb35d2f37d3c1f42b5387bf1a34cd3a9fb06be5cd31611c04e4c
6
+ metadata.gz: 5ad2a9d30633e053bd1349ce784f8fee960e1ae1dcf69d99d76d129f21827484709793dcf0a3c9608023157e5cdfbcfaa4ec32f8caecc1fc73a9e81348ff9e77
7
+ data.tar.gz: 3786088a323b5d662d61adcc410ee6c42fbd955e1022e1e3a52dfdc3ccd026cebaf3807b2c00e94cf47a61d7a8c414112e18e1c403743f5c61d198722b5a4ba5
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
@@ -31,15 +31,16 @@ Set up for usage by creating Realogy's migration and running it.
31
31
  rails g realogy:install
32
32
  rails db:migrate
33
33
 
34
- Realogy is expecting these ENV variables to be present to be able to function:
34
+ Realogy is expecting these encrypted credentials to be present to be able to function:
35
35
 
36
36
  ```
37
- REALOGY_CLIENT_ID
38
- REALOGY_CLIENT_SECRET
39
- REALOGY_TOKEN_URL
40
- REALOGY_SCOPE
41
- REALOGY_SUBSCRIPTION_KEY
42
- REALOGY_API_BASE_URL
37
+ realogy:
38
+ client_id:
39
+ client_secret:
40
+ token_url:
41
+ scope:
42
+ subscription_key:
43
+ api_base_url:
43
44
  ```
44
45
 
45
46
  ### Available Rake Tasks
@@ -127,9 +128,10 @@ config.active_job.queue_adapter = :delayed_job
127
128
  ```ruby
128
129
  realogy = Realogy::DataSync.client
129
130
  ```
130
- #### Retrieve array of objects
131
131
 
132
- The calls to retrieve entities are:
132
+ #### Get active objects
133
+
134
+ The calls to retrieve active entities are:
133
135
 
134
136
  ```ruby
135
137
  realogy.get_active_agents
@@ -139,20 +141,31 @@ realogy.get_active_offices
139
141
  realogy.get_active_teams
140
142
  ```
141
143
 
142
- When no argument is submitted, all entities are returned. Filters can be applied for `brandCode` or `countryCode` though, provided as keys in a hash. For example:
144
+ When no argument is submitted, all active entities are returned.
145
+
146
+ Filters can be applied for `brandCode` and `countryCode`. For example:
143
147
 
144
148
  ```ruby
145
149
  # Fetch all active agents, for all brands, in all countries:
146
- realogy.get_active_agents()
150
+ realogy.get_active_agents
147
151
 
148
152
  # Fetch all active agents, for all brands, in Sweden:
149
- realogy.get_active_agents({countryCode: "SE"})
153
+ realogy.get_active_companies(countryCode: "SE")
150
154
 
155
+ # Allowed brandCode values: C21, CB, ERA, SIR, BHG, CBC, ZIP, CLB, & COR
151
156
  # Fetch all active Sotheby's agents in all countries:
152
- realogy.get_active_agents({brandCode: "SIR"})
157
+ realogy.get_active_offices(brandCode: "SIR")
153
158
 
154
159
  # Fetch all active Sotheby's agents in Sweden:
155
- realogy.get_active_agents({brandCode: "SIR", countryCode: "SE"})
160
+ realogy.get_active_teams(brandCode: "SIR", countryCode: "SE")
161
+ ```
162
+
163
+ When fetching listings, the type of listing can also be specified:
164
+
165
+ ```ruby
166
+ # Allowed type values: ForSale, ForRent, ForSaleCommercial, & ForLeaseCommercial
167
+ # Fetch all active agents, for all brands, in all countries:
168
+ realogy.get_active_listings(type: "ForSale")
156
169
  ```
157
170
 
158
171
  #### Retrieve delta of objects
@@ -179,6 +192,35 @@ realogy.get_offices_delta({since: 5.minutes.ago})
179
192
  realogy.get_teams_delta({since: 1.day.ago})
180
193
  ```
181
194
 
195
+ #### Get all listings
196
+
197
+ To retrieve all listings, `fromDate` and `brandCode` are mandatory parameters. A minimum call to retrieve all listing entities could look like this:
198
+
199
+ ```ruby
200
+ realogy.get_all_listings(brandCode: "COR", fromDate: 1.week.ago.to_query_string)
201
+ ```
202
+
203
+ These are additional filters that can be applied:
204
+
205
+ ```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)
208
+
209
+ # Allowed type values: ForSale, ForRent, ForSaleCommercial, & ForLeaseCommercial
210
+ realogy.get_all_listings(brandCode: "C21", fromDate: 1.week.ago.to_query_string, type: "ForSale")
211
+
212
+ # Allowed status values: Active, Available, Pending, & Closed
213
+ realogy.get_all_listings(brandCode: "CB", fromDate: 1.week.ago.to_query_string, status: "Active")
214
+
215
+ # Limit results to a particular country
216
+ realogy.get_all_listings(brandCode: "SIR", fromDate: 1.week.ago.to_query_string, countryCode: "IT")
217
+
218
+ # 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)
220
+
221
+ ```
222
+
223
+
182
224
  #### Retrieve JSON object
183
225
 
184
226
  ```ruby
@@ -4,13 +4,13 @@ module Realogy
4
4
  require 'net/http'
5
5
  require 'oauth2'
6
6
  require 'json'
7
-
7
+
8
8
  @@instance = Realogy::DataSync.new
9
9
 
10
10
  def self.client
11
11
  return @@instance
12
12
  end
13
-
13
+
14
14
  private_class_method :new
15
15
 
16
16
  # API endpoints by type
@@ -23,6 +23,10 @@ module Realogy
23
23
  get_active_teams: "teams/active"
24
24
  }
25
25
 
26
+ ALL_API_ENDPOINTS = {
27
+ get_all_listings: "listings/all"
28
+ }
29
+
26
30
  DELTA_API_ENDPOINTS = {
27
31
  get_agents_delta: "agents/delta",
28
32
  get_companies_delta: "companies/delta",
@@ -47,12 +51,43 @@ module Realogy
47
51
  endpoint = ACTIVE_API_ENDPOINTS[method_name]
48
52
  params = {
49
53
  'brandCode': hash[:brandCode],
50
- 'countryCode': hash[:countryCode]
54
+ 'countryCode': hash[:countryCode],
55
+ 'type': hash[:type]
51
56
  }.compact
52
57
  return perform_api_call(endpoint, params)
53
58
  end
54
59
  end
55
60
 
61
+ ALL_API_ENDPOINTS.keys.each do |method_name|
62
+ define_method method_name do |*args|
63
+ hash = args.first.is_a?(::Hash) ? args.first : {}
64
+ endpoint = ALL_API_ENDPOINTS[method_name]
65
+ params = {
66
+ 'brandCode': hash[:brandCode],
67
+ 'countryCode': hash[:countryCode],
68
+ 'cursor': hash[:cursor],
69
+ 'fromDate': hash[:fromDate],
70
+ 'limit': hash[:limit],
71
+ 'status': hash[:status],
72
+ 'toDate': hash[:toDate],
73
+ 'type': hash[:type],
74
+ 'followNext': hash[:followNext]
75
+ }.compact
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
88
+ end
89
+ end
90
+
56
91
  DELTA_API_ENDPOINTS.keys.each do |method_name|
57
92
  define_method method_name do |*args|
58
93
  entities = []
@@ -81,13 +116,13 @@ module Realogy
81
116
  # Utility
82
117
 
83
118
  def uri_for_endpoint endpoint
84
- return URI([ENV["REALOGY_API_BASE_URL"], endpoint].join("/"))
119
+ return URI([Rails.application.credentials.dig(:realogy, :api_base_url), endpoint].join("/"))
85
120
  end
86
121
 
87
122
  def perform_simple_call(url)
88
123
  uri = URI(url)
89
124
  request = Net::HTTP::Get.new(uri)
90
- request['Ocp-Apim-Subscription-Key'] = ENV["REALOGY_SUBSCRIPTION_KEY"]
125
+ request['Ocp-Apim-Subscription-Key'] = Rails.application.credentials.dig(:realogy, :subscription_key)
91
126
  request['Authorization'] = "Bearer #{auth_token}"
92
127
  response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
93
128
  http.max_retries = 10
@@ -101,7 +136,7 @@ module Realogy
101
136
  uri = uri_for_endpoint(endpoint)
102
137
  uri.query && uri.query.length > 0 ? uri.query += '&' + query : uri.query = query
103
138
  request = Net::HTTP::Get.new(uri.request_uri)
104
- request['Ocp-Apim-Subscription-Key'] = ENV["REALOGY_SUBSCRIPTION_KEY"]
139
+ request['Ocp-Apim-Subscription-Key'] = Rails.application.credentials.dig(:realogy, :subscription_key)
105
140
  request['Authorization'] = "Bearer #{auth_token}"
106
141
  response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
107
142
  http.max_retries = 10
@@ -112,10 +147,10 @@ module Realogy
112
147
 
113
148
  def auth_token
114
149
  oauth2_client_credentials_token(
115
- ENV["REALOGY_CLIENT_ID"],
116
- ENV["REALOGY_CLIENT_SECRET"],
117
- ENV["REALOGY_TOKEN_URL"],
118
- ENV["REALOGY_SCOPE"]
150
+ Rails.application.credentials.dig(:realogy, :client_id),
151
+ Rails.application.credentials.dig(:realogy, :client_secret),
152
+ Rails.application.credentials.dig(:realogy, :token_url),
153
+ Rails.application.credentials.dig(:realogy, :scope)
119
154
  )
120
155
  end
121
156
 
@@ -148,9 +183,9 @@ OAuth2::AccessToken.class_eval do
148
183
  data = nil
149
184
  token = nil
150
185
  client = OAuth2::Client.new(
151
- ENV["REALOGY_CLIENT_ID"],
152
- ENV["REALOGY_CLIENT_SECRET"],
153
- token_url: ENV["REALOGY_TOKEN_URL"]
186
+ Rails.application.credentials.dig(:realogy, :client_id),
187
+ Rails.application.credentials.dig(:realogy, :client_secret),
188
+ token_url: Rails.application.credentials.dig(:realogy, :token_url)
154
189
  )
155
190
  if File.exists?(path)
156
191
  File.open(path) do |f|
@@ -0,0 +1,11 @@
1
+ DateTime.class_eval do
2
+ def to_query_string
3
+ self.to_json.split("\"").last
4
+ end
5
+ end
6
+
7
+ ActiveSupport::TimeWithZone.class_eval do
8
+ def to_query_string
9
+ self.to_datetime.to_json.split("\"").last
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Realogy
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.3"
3
3
  end
data/lib/realogy.rb CHANGED
@@ -2,6 +2,7 @@ require "realogy/version"
2
2
  require "realogy/railtie" if defined?(Rails)
3
3
  require "realogy/app/models/application_record.rb"
4
4
  require "realogy/app/models/data_sync.rb"
5
+ require "realogy/app/models/date_time.rb"
5
6
  require "realogy/app/models/hash.rb"
6
7
  require "realogy/app/models/realogy/entity.rb"
7
8
  require "realogy/app/models/realogy/agent.rb"
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.0
4
+ version: 0.6.3
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-14 00:00:00.000000000 Z
11
+ date: 2022-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,6 +120,7 @@ files:
120
120
  - lib/realogy/app/jobs/populate_realogy_entity_job.rb
121
121
  - lib/realogy/app/models/application_record.rb
122
122
  - lib/realogy/app/models/data_sync.rb
123
+ - lib/realogy/app/models/date_time.rb
123
124
  - lib/realogy/app/models/hash.rb
124
125
  - lib/realogy/app/models/realogy/agent.rb
125
126
  - lib/realogy/app/models/realogy/company.rb