realogy 0.1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +166 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/realogy/install/install_generator.rb +23 -0
- data/lib/generators/realogy/install/templates/create_realogy_entities.rb +15 -0
- data/lib/realogy/app/models/application_record.rb +3 -0
- data/lib/realogy/app/models/data_sync.rb +112 -0
- data/lib/realogy/app/models/realogy/agent.rb +2 -0
- data/lib/realogy/app/models/realogy/company.rb +2 -0
- data/lib/realogy/app/models/realogy/entity.rb +24 -0
- data/lib/realogy/app/models/realogy/listing.rb +2 -0
- data/lib/realogy/app/models/realogy/office.rb +2 -0
- data/lib/realogy/app/models/realogy/team.rb +2 -0
- data/lib/realogy/railtie.rb +5 -0
- data/lib/realogy/tasks/realogy.rake +96 -0
- data/lib/realogy/version.rb +3 -0
- data/lib/realogy.rb +13 -0
- data/realogy.gemspec +40 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 158674314e0de0322caa8cfaea2a2dad52a45149
|
4
|
+
data.tar.gz: 4ee19dc86fcdb3ca33382f02e2ad7804ef6c025b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: acb855f47a001162b1fb682e6ae58520d7743554b84ce2d28d9aa652eb16cad5431884c6395d0e59d0339b9414f001c83638b2b782b7a2b8a9cbefdf1c60ea55
|
7
|
+
data.tar.gz: e16951a7df7497e26776d456e2bc44daddc2be4b7dcd7633b342cd8536579a20eee315d7dee11798cdbad0daae91af6df21ced83c19b397e19becc567bce98c1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at medlund@mac.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Michael Edlund
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
# Realogy
|
2
|
+
|
3
|
+
Ruby implementation of the Realogy DataSync API to synchronize local data store with the data maintained by Realogy.
|
4
|
+
|
5
|
+
The Realogy gem:
|
6
|
+
|
7
|
+
- Retrieves the JSON for the supported entities Agents, Companies, Listings, Offices, and Teams.
|
8
|
+
- Uses the JSON column type, so make sure your database is a recent version that supports it.
|
9
|
+
- Does _not_ perform any data mapping, as it strives to be agnostic to existing data structures. Add `after_save` hooks to capture saved JSON, transform it and save it where you want it saved.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'realogy'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
gem install realogy
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Set up for usage by creating Realogy's migration and running it.
|
30
|
+
|
31
|
+
rails g realogy:install
|
32
|
+
rails db:migrate
|
33
|
+
|
34
|
+
Realogy is expecting these ENV variables to be present to be able to function:
|
35
|
+
|
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
|
43
|
+
```
|
44
|
+
|
45
|
+
### Available Rake Tasks
|
46
|
+
|
47
|
+
#### Syncing Active Entities
|
48
|
+
|
49
|
+
There are a number of rake tasks for syncing active entities. By default, all countries are synced. A country code can optionally be passed in to sync only that country.
|
50
|
+
|
51
|
+
```
|
52
|
+
rails realogy:sync_active_agents # Sync Active Agents Everywhere
|
53
|
+
rails realogy:sync_active_agents[SE] # Sync Active Agents in Sweden
|
54
|
+
|
55
|
+
rails realogy:sync_active_companies # Sync Active Companies Everywhere
|
56
|
+
rails realogy:sync_active_companies[SE] # Sync Active Companies in Sweden
|
57
|
+
|
58
|
+
rails realogy:sync_active_listings # Sync Active Listings Everywhere
|
59
|
+
rails realogy:sync_active_listings[SE] # Sync Active Listings in Sweden
|
60
|
+
|
61
|
+
rails realogy:sync_active_offices # Sync Active Offices Everywhere
|
62
|
+
rails realogy:sync_active_offices[SE] # Sync Active Offices in Sweden
|
63
|
+
|
64
|
+
rails realogy:sync_active_teams # Sync Active Teams Everywhere
|
65
|
+
rails realogy:sync_active_teams[SE] # Sync Active Teams in Sweden
|
66
|
+
```
|
67
|
+
|
68
|
+
Catch-all that runs all other syncing tasks:
|
69
|
+
|
70
|
+
```
|
71
|
+
rails realogy:sync_active_entities # Sync all active entities
|
72
|
+
```
|
73
|
+
|
74
|
+
#### Delete Expired Entities
|
75
|
+
|
76
|
+
```
|
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
|
82
|
+
```
|
83
|
+
|
84
|
+
Catch-all that runs all other deletion tasks:
|
85
|
+
|
86
|
+
```
|
87
|
+
rails realogy:delete_expired_entities # Delete all expired entities
|
88
|
+
```
|
89
|
+
|
90
|
+
### Background/parallel processing
|
91
|
+
|
92
|
+
If Active Job isn't configured for queueing and background processing, Realogy will default to running rake tasks sequentially on the main thread.
|
93
|
+
|
94
|
+
Because of the volume of Realogy data, you will want to use Active Job for parallel processing in production. Configuring Active Job will cause available rake tasks to use it.
|
95
|
+
|
96
|
+
For example, if you've got Delayed Job installed, you'd add to your application.rb:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
config.active_job.queue_adapter = :delayed_job
|
100
|
+
```
|
101
|
+
|
102
|
+
### API Calls
|
103
|
+
|
104
|
+
#### Set up Realogy client
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
realogy = Realogy::DataSync.client
|
108
|
+
```
|
109
|
+
#### Retrieve array of objects
|
110
|
+
|
111
|
+
The calls to retrieve entities are:
|
112
|
+
|
113
|
+
```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()
|
119
|
+
```
|
120
|
+
|
121
|
+
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:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
# Fetch all active agents, for all brands, in all countries:
|
125
|
+
realogy.get_active_agents()
|
126
|
+
|
127
|
+
# Fetch all active agents, for all brands, in Sweden:
|
128
|
+
realogy.get_active_agents({countryCode: "SE"})
|
129
|
+
|
130
|
+
# Fetch all active Sotheby's agents in all countries:
|
131
|
+
realogy.get_active_agents({brandCode: "SIR"})
|
132
|
+
|
133
|
+
# Fetch all active Sotheby's agents in Sweden:
|
134
|
+
realogy.get_active_agents({brandCode: "SIR", countryCode: "SE"})
|
135
|
+
```
|
136
|
+
|
137
|
+
#### Retrieve delta of objects
|
138
|
+
|
139
|
+
TODO
|
140
|
+
|
141
|
+
#### Retrieve JSON object
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
realogy.get_agent_by_id(entity_id)
|
145
|
+
realogy.get_agent_by_id(entity_id)
|
146
|
+
realogy.get_listing_by_id(entity_id)
|
147
|
+
realogy.get_office_by_id(entity_id)
|
148
|
+
realogy.get_team_by_id(entity_id)
|
149
|
+
|
150
|
+
```
|
151
|
+
|
152
|
+
## Development
|
153
|
+
|
154
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
155
|
+
|
156
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
157
|
+
|
158
|
+
## Contributing
|
159
|
+
|
160
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/arcticleo/realogy-sync. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
161
|
+
|
162
|
+
|
163
|
+
## License
|
164
|
+
|
165
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
166
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "realogy"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Realogy
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
desc "Copy migration file to your application."
|
9
|
+
|
10
|
+
def self.next_migration_number(path)
|
11
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S%L")
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_model_file
|
15
|
+
%w[realogy_entities].each do |name|
|
16
|
+
migration_template "create_#{name}.rb", "db/migrate/create_#{name}.rb"
|
17
|
+
sleep 0.1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateRealogyEntities < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :realogy_entities do |t|
|
4
|
+
t.string :type
|
5
|
+
t.string :entity_id
|
6
|
+
t.datetime :last_update_on
|
7
|
+
t.json :data
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
add_index :realogy_entities, :type
|
12
|
+
add_index :realogy_entities, :entity_id
|
13
|
+
add_index :realogy_entities, :last_update_on
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Realogy
|
2
|
+
class DataSync
|
3
|
+
|
4
|
+
require 'net/http'
|
5
|
+
require 'oauth2'
|
6
|
+
|
7
|
+
@@instance = Realogy::DataSync.new
|
8
|
+
|
9
|
+
def self.client
|
10
|
+
return @@instance
|
11
|
+
end
|
12
|
+
|
13
|
+
private_class_method :new
|
14
|
+
|
15
|
+
# API endpoints by type
|
16
|
+
|
17
|
+
ACTIVE_API_ENDPOINTS = {
|
18
|
+
get_active_agents: "agents/active",
|
19
|
+
get_active_companies: "companies/active",
|
20
|
+
get_active_listings: "listings/active",
|
21
|
+
get_active_offices: "offices/active",
|
22
|
+
get_active_teams: "teams/active"
|
23
|
+
}
|
24
|
+
|
25
|
+
DELTA_API_ENDPOINTS = {
|
26
|
+
get_agent_delta: "agents/delta",
|
27
|
+
get_company_delta: "companies/delta",
|
28
|
+
get_listing_delta: "listings/delta",
|
29
|
+
get_office_delta: "offices/delta",
|
30
|
+
get_team_delta: "teams/delta"
|
31
|
+
}
|
32
|
+
|
33
|
+
DETAILS_API_ENDPOINTS = {
|
34
|
+
get_agent_by_id: "agents",
|
35
|
+
get_company_by_id: "companies",
|
36
|
+
get_listing_by_id: "listings",
|
37
|
+
get_office_by_id: "offices",
|
38
|
+
get_team_by_id: "teams"
|
39
|
+
}
|
40
|
+
|
41
|
+
# API Implementation
|
42
|
+
|
43
|
+
ACTIVE_API_ENDPOINTS.keys.each do |method_name|
|
44
|
+
define_method method_name do |*args|
|
45
|
+
hash = args.first.is_a?(Hash) ? args.first : {}
|
46
|
+
endpoint = ACTIVE_API_ENDPOINTS[method_name]
|
47
|
+
params = {
|
48
|
+
'brandCode': hash[:brandCode],
|
49
|
+
'countryCode': hash[:countryCode]
|
50
|
+
}.compact
|
51
|
+
return perform_api_call(endpoint, params)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
DETAILS_API_ENDPOINTS.keys.each do |method_name|
|
56
|
+
define_method method_name do |id|
|
57
|
+
endpoint = [DETAILS_API_ENDPOINTS[method_name], id].join("/")
|
58
|
+
return perform_api_call(endpoint, nil)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
# Utility
|
65
|
+
|
66
|
+
def uri_for_endpoint endpoint
|
67
|
+
return URI([ENV["REALOGY_API_BASE_URL"], endpoint].join("/"))
|
68
|
+
end
|
69
|
+
|
70
|
+
def perform_api_call(endpoint, params)
|
71
|
+
query = params.present? ? URI.encode_www_form(params) : ""
|
72
|
+
uri = uri_for_endpoint(endpoint)
|
73
|
+
uri.query && uri.query.length > 0 ? uri.query += '&' + query : uri.query = query
|
74
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
75
|
+
request['Ocp-Apim-Subscription-Key'] = ENV["REALOGY_SUBSCRIPTION_KEY"]
|
76
|
+
request['Authorization'] = "Bearer #{auth_token}"
|
77
|
+
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
78
|
+
http.request(request)
|
79
|
+
end
|
80
|
+
return JSON(response.body)
|
81
|
+
end
|
82
|
+
|
83
|
+
def auth_token
|
84
|
+
oauth2_client_credentials_token(
|
85
|
+
ENV["REALOGY_CLIENT_ID"],
|
86
|
+
ENV["REALOGY_CLIENT_SECRET"],
|
87
|
+
ENV["REALOGY_TOKEN_URL"],
|
88
|
+
ENV["REALOGY_SCOPE"]
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
def oauth2_client_credentials_token_object(client_id, client_secret, token_url, scope)
|
93
|
+
client = OAuth2::Client.new(
|
94
|
+
client_id,
|
95
|
+
client_secret,
|
96
|
+
token_url: token_url
|
97
|
+
)
|
98
|
+
return client.client_credentials.get_token(scope: scope)
|
99
|
+
end
|
100
|
+
|
101
|
+
def oauth2_client_credentials_token(client_id, client_secret, token_url, scope)
|
102
|
+
expiry = @token.try(:expires_at).present? ? DateTime.strptime(@token.expires_at.to_s, '%s') : 1.day.ago
|
103
|
+
if expiry > DateTime.now.utc
|
104
|
+
return @token.token
|
105
|
+
else
|
106
|
+
@token = oauth2_client_credentials_token_object(client_id, client_secret, token_url, scope)
|
107
|
+
return @token.token
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Realogy::Entity < ApplicationRecord
|
2
|
+
self.table_name = 'realogy_entities'
|
3
|
+
|
4
|
+
validates :type, presence: true
|
5
|
+
validates :entity_id, presence: true
|
6
|
+
validates :last_update_on, presence: true
|
7
|
+
|
8
|
+
def needs_updating?
|
9
|
+
self.new_record? || self.last_update_on_changed? || self.data.blank?
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.triage hash
|
13
|
+
@object = self.find_or_initialize_by(entity_id: hash["entityId"])
|
14
|
+
@object.last_update_on = hash["lastUpdateOn"]
|
15
|
+
@object.populate if @object.needs_updating?
|
16
|
+
end
|
17
|
+
|
18
|
+
def populate
|
19
|
+
call = ["get_", self.class.to_s.downcase.split("::").last, "_by_id"].join.to_sym
|
20
|
+
self.data = Realogy::DataSync.client.__send__(call, self.entity_id)
|
21
|
+
self.save if self.changed?
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
namespace :realogy do
|
2
|
+
|
3
|
+
def active_job_configured?
|
4
|
+
return Rails.application.config.active_job.queue_adapter.eql?(:async) ? false : true
|
5
|
+
end
|
6
|
+
|
7
|
+
desc "Sync all active entities"
|
8
|
+
task :sync_active_entities => [:sync_active_agents, :sync_active_companies, :sync_active_listings, :sync_active_offices, :sync_active_teams] do
|
9
|
+
puts
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Sync Active Agents"
|
13
|
+
task :sync_active_agents, [:country_code] => [:environment] do |t, args|
|
14
|
+
args.with_defaults(country_code: nil)
|
15
|
+
Realogy::DataSync.client.get_active_agents({countryCode: args["country_code"]}).each do |hash|
|
16
|
+
hash['class'] = "Realogy::Agent"
|
17
|
+
active_job_configured? ? PopulateRealogyEntityJob.perform_later(hash) : Realogy::Agent::triage(hash)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Sync Active Companies"
|
22
|
+
task :sync_active_companies, [:country_code] => [:environment] do |t, args|
|
23
|
+
args.with_defaults(country_code: nil)
|
24
|
+
Realogy::DataSync.client.get_active_companies({countryCode: args["country_code"]}).each do |hash|
|
25
|
+
hash['class'] = "Realogy::Company"
|
26
|
+
active_job_configured? ? PopulateRealogyEntityJob.perform_later(hash) : Realogy::Company::triage(hash)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Sync Active Listings"
|
31
|
+
task :sync_active_listings, [:country_code] => [:environment] do |t, args|
|
32
|
+
args.with_defaults(country_code: nil)
|
33
|
+
Realogy::DataSync.client.get_active_listings({countryCode: args["country_code"]}).each do |hash|
|
34
|
+
hash['class'] = "Realogy::Listing"
|
35
|
+
active_job_configured? ? PopulateRealogyEntityJob.perform_later(hash) : Realogy::Listing::triage(hash)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Sync Active Offices"
|
40
|
+
task :sync_active_offices, [:country_code] => [:environment] do |t, args|
|
41
|
+
args.with_defaults(country_code: nil)
|
42
|
+
Realogy::DataSync.client.get_active_offices({countryCode: args["country_code"]}).each do |hash|
|
43
|
+
hash['class'] = "Realogy::Office"
|
44
|
+
active_job_configured? ? PopulateRealogyEntityJob.perform_later(hash) : Realogy::Office::triage(hash)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Sync Active Teams"
|
49
|
+
task :sync_active_teams, [:country_code] => [:environment] do |t, args|
|
50
|
+
args.with_defaults(country_code: nil)
|
51
|
+
Realogy::DataSync.client.get_active_teams({countryCode: args["country_code"]}).each do |hash|
|
52
|
+
hash['class'] = "Realogy::Team"
|
53
|
+
active_job_configured? ? PopulateRealogyEntityJob.perform_later(hash) : Realogy::Team::triage(hash)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def delete_expired_entities_of_type klass
|
58
|
+
return unless %w(agents companies listings offices teams).include?(plural = klass.to_s.tableize.split("/").last)
|
59
|
+
call = ["get_active_", plural].join.to_sym
|
60
|
+
existing = klass.select(:entity_id).pluck(:entity_id)
|
61
|
+
current = Realogy::DataSync.client.__send__(call).map{|e| e["entityId"]}
|
62
|
+
klass.where(entity_id: (existing - current)).delete_all
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "Delete all expired entities"
|
66
|
+
task :delete_expired_entities => [:delete_expired_agents, :delete_expired_companies, :delete_expired_listings, :delete_expired_offices, :delete_expired_teams] do
|
67
|
+
puts
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "Delete Expired Agents"
|
71
|
+
task :delete_expired_agents => [:environment] do |t|
|
72
|
+
delete_expired_entities_of_type Realogy::Agent
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "Delete Expired Companies"
|
76
|
+
task :delete_expired_companies => [:environment] do |t|
|
77
|
+
delete_expired_entities_of_type Realogy::Company
|
78
|
+
end
|
79
|
+
|
80
|
+
desc "Delete Expired Listings"
|
81
|
+
task :delete_expired_listings => [:environment] do |t|
|
82
|
+
delete_expired_entities_of_type Realogy::Listing
|
83
|
+
end
|
84
|
+
|
85
|
+
desc "Delete Expired Offices"
|
86
|
+
task :delete_expired_offices => [:environment] do |t|
|
87
|
+
delete_expired_entities_of_type Realogy::Office
|
88
|
+
end
|
89
|
+
|
90
|
+
desc "Delete Expired Teams"
|
91
|
+
task :delete_expired_teams => [:environment] do |t|
|
92
|
+
delete_expired_entities_of_type Realogy::Team
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
end
|
data/lib/realogy.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "realogy/version"
|
2
|
+
require "realogy/railtie" if defined?(Rails)
|
3
|
+
require "realogy/app/models/application_record.rb"
|
4
|
+
require "realogy/app/models/data_sync.rb"
|
5
|
+
require "realogy/app/models/realogy/entity.rb"
|
6
|
+
require "realogy/app/models/realogy/agent.rb"
|
7
|
+
require "realogy/app/models/realogy/company.rb"
|
8
|
+
require "realogy/app/models/realogy/listing.rb"
|
9
|
+
require "realogy/app/models/realogy/office.rb"
|
10
|
+
require "realogy/app/models/realogy/team.rb"
|
11
|
+
|
12
|
+
module Realogy
|
13
|
+
end
|
data/realogy.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'realogy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "realogy"
|
8
|
+
spec.version = Realogy::VERSION
|
9
|
+
spec.authors = ["Michael Edlund"]
|
10
|
+
spec.email = ["medlund@mac.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Encapsulation of Realogy's DataSync API.}
|
13
|
+
spec.description = %q{Encapsulates the Realogy DataSync API to synchronize local data store with the data maintained by Realogy.}
|
14
|
+
spec.homepage = "https://github.com/arcticleo/realogy"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.required_ruby_version = '>= 2.4.3'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
# if spec.respond_to?(:metadata)
|
21
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
# else
|
23
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
24
|
+
# "public gem pushes."
|
25
|
+
# end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
spec.add_development_dependency 'sqlite3'
|
38
|
+
spec.add_dependency "activerecord", ">= 5.0"
|
39
|
+
spec.add_dependency "oauth2"
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: realogy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Edlund
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: oauth2
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Encapsulates the Realogy DataSync API to synchronize local data store
|
98
|
+
with the data maintained by Realogy.
|
99
|
+
email:
|
100
|
+
- medlund@mac.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- lib/generators/realogy/install/install_generator.rb
|
116
|
+
- lib/generators/realogy/install/templates/create_realogy_entities.rb
|
117
|
+
- lib/realogy.rb
|
118
|
+
- lib/realogy/app/models/application_record.rb
|
119
|
+
- lib/realogy/app/models/data_sync.rb
|
120
|
+
- lib/realogy/app/models/realogy/agent.rb
|
121
|
+
- lib/realogy/app/models/realogy/company.rb
|
122
|
+
- lib/realogy/app/models/realogy/entity.rb
|
123
|
+
- lib/realogy/app/models/realogy/listing.rb
|
124
|
+
- lib/realogy/app/models/realogy/office.rb
|
125
|
+
- lib/realogy/app/models/realogy/team.rb
|
126
|
+
- lib/realogy/railtie.rb
|
127
|
+
- lib/realogy/tasks/realogy.rake
|
128
|
+
- lib/realogy/version.rb
|
129
|
+
- realogy.gemspec
|
130
|
+
homepage: https://github.com/arcticleo/realogy
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 2.4.3
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.6.14
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Encapsulation of Realogy's DataSync API.
|
154
|
+
test_files: []
|