realogy 0.1.0 → 0.2.0
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 +5 -5
- data/README.md +53 -12
- data/lib/realogy/app/models/data_sync.rb +32 -5
- data/lib/realogy/app/models/realogy/entity.rb +1 -1
- data/lib/realogy/tasks/realogy.rake +45 -1
- data/lib/realogy/version.rb +1 -1
- data/realogy-0.1.0.gem +0 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 027741bd06711d8a56533a97c36c400cb05e63971fbd208c44918bc65620899e
|
4
|
+
data.tar.gz: 8211d5c915eef8636890f90498e233b61717dec03f2ab14b8a1afcbf81153b54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 321e8dfb8d03406ee0d3e21587c2a556bb72ded74b643e21c80238f016baef083419182da5b5108e36c237784f39e8a22b01ddf86ea3433aed560a7577598442
|
7
|
+
data.tar.gz: 8b31fd0668825b169f51a187b6506230842de9c0456a416d71bcaf572834121c74120edfe39bd0bae6b4228d3a42b234f54ad1e0068373036dac7a63ca9c7a2e
|
data/README.md
CHANGED
@@ -71,14 +71,35 @@ Catch-all that runs all other syncing tasks:
|
|
71
71
|
rails realogy:sync_active_entities # Sync all active entities
|
72
72
|
```
|
73
73
|
|
74
|
-
####
|
74
|
+
#### Syncing Entities Delta
|
75
|
+
|
76
|
+
There are a number of rake tasks for syncing entities within a delta span of time. Tasks default to last 15 minutes if not otherwise specified. These tasks will both update new/updated entities, as well as delete expired ones.
|
77
|
+
|
78
|
+
```
|
79
|
+
rails realogy:sync_agents_delta # Sync agents delta for last 15 minutes
|
80
|
+
rails realogy:sync_agents_delta[10] # Sync agents delta for last 10 minutes
|
81
|
+
|
82
|
+
rails realogy:sync_companies_delta # Sync companies delta for last 15 minutes
|
83
|
+
rails realogy:sync_companies_delta[10] # Sync companies delta for last 10 minutes
|
84
|
+
|
85
|
+
rails realogy:sync_listings_delta # Sync listings delta for last 15 minutes
|
86
|
+
rails realogy:sync_listings_delta[10] # Sync listings delta for last 10 minutes
|
87
|
+
|
88
|
+
rails realogy:sync_offices_delta # Sync offices delta for last 15 minutes
|
89
|
+
rails realogy:sync_offices_delta[10] # Sync offices delta for last 10 minutes
|
90
|
+
|
91
|
+
rails realogy:sync_teams_delta # Sync teams delta for last 15 minutes
|
92
|
+
rails realogy:sync_teams_delta[10] # Sync teams delta for last 10 minutes
|
93
|
+
```
|
94
|
+
|
95
|
+
#### Delete All Expired Entities
|
75
96
|
|
76
97
|
```
|
77
|
-
rails realogy:delete_expired_agents # Delete Expired Agents
|
78
|
-
rails realogy:delete_expired_companies # Delete Expired Companies
|
79
|
-
rails realogy:delete_expired_listings # Delete Expired Listings
|
80
|
-
rails realogy:delete_expired_offices # Delete Expired Offices
|
81
|
-
rails realogy:delete_expired_teams # Delete Expired Teams
|
98
|
+
rails realogy:delete_expired_agents # Delete All Expired Agents
|
99
|
+
rails realogy:delete_expired_companies # Delete All Expired Companies
|
100
|
+
rails realogy:delete_expired_listings # Delete All Expired Listings
|
101
|
+
rails realogy:delete_expired_offices # Delete All Expired Offices
|
102
|
+
rails realogy:delete_expired_teams # Delete All Expired Teams
|
82
103
|
```
|
83
104
|
|
84
105
|
Catch-all that runs all other deletion tasks:
|
@@ -111,11 +132,11 @@ realogy = Realogy::DataSync.client
|
|
111
132
|
The calls to retrieve entities are:
|
112
133
|
|
113
134
|
```ruby
|
114
|
-
realogy.get_active_agents
|
115
|
-
realogy.get_active_companies
|
116
|
-
realogy.get_active_listings
|
117
|
-
realogy.get_active_offices
|
118
|
-
realogy.get_active_teams
|
135
|
+
realogy.get_active_agents
|
136
|
+
realogy.get_active_companies
|
137
|
+
realogy.get_active_listings
|
138
|
+
realogy.get_active_offices
|
139
|
+
realogy.get_active_teams
|
119
140
|
```
|
120
141
|
|
121
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:
|
@@ -136,7 +157,27 @@ realogy.get_active_agents({brandCode: "SIR", countryCode: "SE"})
|
|
136
157
|
|
137
158
|
#### Retrieve delta of objects
|
138
159
|
|
139
|
-
|
160
|
+
The calls to retrieve entities that have recently changed are:
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
realogy.get_agents_delta
|
164
|
+
realogy.get_companies_delta
|
165
|
+
realogy.get_listings_delta
|
166
|
+
realogy.get_offices_delta
|
167
|
+
realogy.get_teams_delta
|
168
|
+
```
|
169
|
+
|
170
|
+
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.
|
171
|
+
|
172
|
+
When no argument is passed, the delta returned is for the last 15 minutes. A custom minutes delta can be passed in:
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
realogy.get_agents_delta({since: 15.minutes.ago}) # 15 minutes is the default
|
176
|
+
realogy.get_companies_delta({since: 1.hour.ago})
|
177
|
+
realogy.get_listings_delta({since: 2.hours.ago})
|
178
|
+
realogy.get_offices_delta({since: 5.minutes.ago})
|
179
|
+
realogy.get_teams_delta({since: 1.day.ago})
|
180
|
+
```
|
140
181
|
|
141
182
|
#### Retrieve JSON object
|
142
183
|
|
@@ -23,11 +23,11 @@ module Realogy
|
|
23
23
|
}
|
24
24
|
|
25
25
|
DELTA_API_ENDPOINTS = {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
get_agents_delta: "agents/delta",
|
27
|
+
get_companies_delta: "companies/delta",
|
28
|
+
get_listings_delta: "listings/delta",
|
29
|
+
get_offices_delta: "offices/delta",
|
30
|
+
get_teams_delta: "teams/delta"
|
31
31
|
}
|
32
32
|
|
33
33
|
DETAILS_API_ENDPOINTS = {
|
@@ -51,6 +51,22 @@ module Realogy
|
|
51
51
|
return perform_api_call(endpoint, params)
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
DELTA_API_ENDPOINTS.keys.each do |method_name|
|
56
|
+
define_method method_name do |*args|
|
57
|
+
entities = []
|
58
|
+
hash = args.first.is_a?(Hash) ? args.first : {since: 15.minutes.ago}
|
59
|
+
params = {'since': JSON[hash[:since].to_json]}
|
60
|
+
endpoint = DELTA_API_ENDPOINTS[method_name]
|
61
|
+
response = perform_api_call(endpoint, params)
|
62
|
+
entities << response["data"]
|
63
|
+
while response["nextLink"].present?
|
64
|
+
response = perform_simple_call(response["nextLink"])
|
65
|
+
entities << response["data"]
|
66
|
+
end
|
67
|
+
return entities.flatten
|
68
|
+
end
|
69
|
+
end
|
54
70
|
|
55
71
|
DETAILS_API_ENDPOINTS.keys.each do |method_name|
|
56
72
|
define_method method_name do |id|
|
@@ -67,6 +83,17 @@ module Realogy
|
|
67
83
|
return URI([ENV["REALOGY_API_BASE_URL"], endpoint].join("/"))
|
68
84
|
end
|
69
85
|
|
86
|
+
def perform_simple_call(url)
|
87
|
+
uri = URI(url)
|
88
|
+
request = Net::HTTP::Get.new(uri)
|
89
|
+
request['Ocp-Apim-Subscription-Key'] = ENV["REALOGY_SUBSCRIPTION_KEY"]
|
90
|
+
request['Authorization'] = "Bearer #{auth_token}"
|
91
|
+
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
92
|
+
http.request(request)
|
93
|
+
end
|
94
|
+
return JSON(response.body)
|
95
|
+
end
|
96
|
+
|
70
97
|
def perform_api_call(endpoint, params)
|
71
98
|
query = params.present? ? URI.encode_www_form(params) : ""
|
72
99
|
uri = uri_for_endpoint(endpoint)
|
@@ -10,7 +10,7 @@ class Realogy::Entity < ApplicationRecord
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.triage hash
|
13
|
-
@object = self.find_or_initialize_by(entity_id: hash["entityId"])
|
13
|
+
@object = self.find_or_initialize_by(entity_id: [hash["entityId"], hash["id"]].compact.first)
|
14
14
|
@object.last_update_on = hash["lastUpdateOn"]
|
15
15
|
@object.populate if @object.needs_updating?
|
16
16
|
end
|
@@ -59,7 +59,7 @@ namespace :realogy do
|
|
59
59
|
call = ["get_active_", plural].join.to_sym
|
60
60
|
existing = klass.select(:entity_id).pluck(:entity_id)
|
61
61
|
current = Realogy::DataSync.client.__send__(call).map{|e| e["entityId"]}
|
62
|
-
klass.where(entity_id: (existing - current)).
|
62
|
+
klass.where(entity_id: (existing - current)).destroy_all
|
63
63
|
end
|
64
64
|
|
65
65
|
desc "Delete all expired entities"
|
@@ -92,5 +92,49 @@ namespace :realogy do
|
|
92
92
|
delete_expired_entities_of_type Realogy::Team
|
93
93
|
end
|
94
94
|
|
95
|
+
def perform_delta_update_for klass, since
|
96
|
+
return unless %w(agents companies listings offices teams).include?(plural = klass.to_s.tableize.split("/").last)
|
97
|
+
call = "get_#{plural}_delta".to_sym
|
98
|
+
Realogy::DataSync.client.send(call, {since: since.to_i.minutes.ago}).each do |hash|
|
99
|
+
case hash["action"]
|
100
|
+
when "Delete"
|
101
|
+
klass.find_by(entity_id: hash["id"]).try(:destroy)
|
102
|
+
when "Upsert"
|
103
|
+
hash["class"] = klass.to_s
|
104
|
+
active_job_configured? ? PopulateRealogyEntityJob.perform_later(hash) : klass::triage(hash)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
desc "Delta update for Agents. Optionally provide delta in minutes."
|
110
|
+
task :sync_agents_delta, [:since_minutes] => [:environment] do |t, args|
|
111
|
+
args.with_defaults(since_minutes: 15)
|
112
|
+
perform_delta_update_for Realogy::Agent, args[:since_minutes]
|
113
|
+
end
|
114
|
+
|
115
|
+
desc "Delta update for Companies. Optionally provide delta in minutes."
|
116
|
+
task :sync_companies_delta, [:since_minutes] => [:environment] do |t, args|
|
117
|
+
args.with_defaults(since_minutes: 15)
|
118
|
+
perform_delta_update_for Realogy::Company, args[:since_minutes]
|
119
|
+
end
|
120
|
+
|
121
|
+
desc "Delta update for Listings. Optionally provide delta in minutes."
|
122
|
+
task :sync_listings_delta, [:since_minutes] => [:environment] do |t, args|
|
123
|
+
args.with_defaults(since_minutes: 15)
|
124
|
+
perform_delta_update_for Realogy::Listing, args[:since_minutes]
|
125
|
+
end
|
126
|
+
|
127
|
+
desc "Delta update for Offices. Optionally provide delta in minutes."
|
128
|
+
task :sync_offices_delta, [:since_minutes] => [:environment] do |t, args|
|
129
|
+
args.with_defaults(since_minutes: 15)
|
130
|
+
perform_delta_update_for Realogy::Office, args[:since_minutes]
|
131
|
+
end
|
132
|
+
|
133
|
+
desc "Delta update for Teams. Optionally provide delta in minutes."
|
134
|
+
task :sync_teams_delta, [:since_minutes] => [:environment] do |t, args|
|
135
|
+
args.with_defaults(since_minutes: 15)
|
136
|
+
perform_delta_update_for Realogy::Team, args[:since_minutes]
|
137
|
+
end
|
138
|
+
|
95
139
|
|
96
140
|
end
|
data/lib/realogy/version.rb
CHANGED
data/realogy-0.1.0.gem
ADDED
Binary file
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Edlund
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/realogy/railtie.rb
|
127
127
|
- lib/realogy/tasks/realogy.rake
|
128
128
|
- lib/realogy/version.rb
|
129
|
+
- realogy-0.1.0.gem
|
129
130
|
- realogy.gemspec
|
130
131
|
homepage: https://github.com/arcticleo/realogy
|
131
132
|
licenses:
|
@@ -147,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
148
|
version: '0'
|
148
149
|
requirements: []
|
149
150
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.6
|
151
|
+
rubygems_version: 2.7.6
|
151
152
|
signing_key:
|
152
153
|
specification_version: 4
|
153
154
|
summary: Encapsulation of Realogy's DataSync API.
|