realogy 0.6.9 → 0.6.11
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 +4 -4
- data/lib/realogy/app/models/data_sync.rb +4 -0
- data/lib/realogy/app/models/realogy/entity.rb +53 -14
- data/lib/realogy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16b4f3e20df302badddd3af150745656f53fc1cbc3ea6457e82bd7ca4eed055c
|
4
|
+
data.tar.gz: 4a93d40d4c122ad052c2122083aaf2878d1ad466f8e2c68d90da171116e321ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6de6ebb0b2ef83481f5d983c0028bb3b0918e450b6099476e863e0b22c63d0b858a7b18abec54d2a7b82c520beffe5218f3b84992070423574e832909300bd42
|
7
|
+
data.tar.gz: 10c3201b1dd9e24e0bc54ac2d1034266b18c9260278dc227ed3d94ea127cc7e789bb8d648b8a396449bb697028d596a87a57de9e8df67b769667aed2e95ec35c
|
@@ -152,6 +152,10 @@ module Realogy
|
|
152
152
|
request['Ocp-Apim-Subscription-Key'] = Rails.application.credentials.dig(:realogy, :subscription_key)
|
153
153
|
request['Authorization'] = "Bearer #{auth_token}"
|
154
154
|
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
155
|
+
http.open_timeout = 10 # seconds to wait for connection
|
156
|
+
http.read_timeout = 30 # seconds to wait for response
|
157
|
+
http.write_timeout = 10
|
158
|
+
http.ssl_timeout = 10
|
155
159
|
http.max_retries = 10
|
156
160
|
http.request(request)
|
157
161
|
end
|
@@ -6,58 +6,97 @@ class Realogy::Entity < ApplicationRecord
|
|
6
6
|
validates :last_update_on, presence: true
|
7
7
|
|
8
8
|
def needs_updating?
|
9
|
-
|
9
|
+
new_record? || last_update_on_changed? || data.blank?
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.triage
|
13
|
-
|
12
|
+
def self.triage(hash)
|
13
|
+
entity_id = [hash["entityId"], hash["id"]].compact.first
|
14
|
+
@object = find_or_initialize_by(entity_id: entity_id)
|
14
15
|
@object.last_update_on = hash["lastUpdateOn"].to_s.to_datetime
|
15
|
-
|
16
|
+
|
17
|
+
if data_provided_in_hash?(hash)
|
18
|
+
@object.data = extract_entity_data(hash)
|
19
|
+
@object.save if @object.changed?
|
20
|
+
elsif @object.needs_updating?
|
21
|
+
@object.populate
|
22
|
+
end
|
16
23
|
end
|
17
24
|
|
18
25
|
def get_data
|
19
|
-
|
20
|
-
|
26
|
+
retries = 0
|
27
|
+
max_retries = 3
|
28
|
+
|
29
|
+
begin
|
30
|
+
call = ["get_", self.class.to_s.downcase.split("::").last, "_by_id"].join.to_sym
|
31
|
+
Realogy::DataSync.client.__send__(call, entity_id)
|
32
|
+
rescue OpenSSL::SSL::SSLError, Net::OpenTimeout, Net::ReadTimeout, Errno::ECONNRESET => e
|
33
|
+
retries += 1
|
34
|
+
if retries <= max_retries
|
35
|
+
sleep_time = 2**retries # 2s, 4s, 8s
|
36
|
+
Rails.logger.warn "[Realogy::Entity] Retry #{retries}/#{max_retries} for #{entity_id} after
|
37
|
+
#{sleep_time}s (#{e.class})"
|
38
|
+
sleep(sleep_time)
|
39
|
+
retry
|
40
|
+
else
|
41
|
+
Rails.logger.error "[Realogy::Entity] Failed to fetch #{entity_id} after #{max_retries} retries:
|
42
|
+
#{e.message}"
|
43
|
+
raise
|
44
|
+
end
|
45
|
+
end
|
21
46
|
end
|
22
47
|
|
23
48
|
def populate
|
24
49
|
result = get_data
|
25
50
|
self.data = result unless result.blank?
|
26
|
-
|
51
|
+
save if changed?
|
27
52
|
end
|
28
53
|
|
29
54
|
def dig_for_array(*path)
|
30
|
-
return nil unless (json =
|
55
|
+
return nil unless (json = data).is_a?(Hash)
|
31
56
|
(v = json.dig(*path)).is_a?(Array) ? v : nil
|
32
57
|
end
|
33
58
|
|
34
59
|
def dig_for_boolean(*path)
|
35
|
-
return nil unless (json =
|
60
|
+
return nil unless (json = data).is_a?(Hash)
|
36
61
|
(v = json.dig(*path)).to_s.upcase.eql?("TRUE") ? true : nil
|
37
62
|
end
|
38
63
|
|
39
64
|
def dig_for_datetime(*path)
|
40
|
-
|
65
|
+
data.dig(*path).to_datetime rescue nil
|
41
66
|
end
|
42
67
|
|
43
68
|
def dig_for_decimal(*path)
|
44
|
-
return nil unless (json =
|
69
|
+
return nil unless (json = data).is_a?(Hash)
|
45
70
|
(v = json.dig(*path).to_f) != 0.0 ? v : nil
|
46
71
|
end
|
47
72
|
|
48
73
|
def dig_for_hash(*path)
|
49
|
-
return nil unless (json =
|
74
|
+
return nil unless (json = data).is_a?(Hash)
|
50
75
|
(v = json.dig(*path)).is_a?(Hash) ? v : nil
|
51
76
|
end
|
52
77
|
|
53
78
|
def dig_for_integer(*path)
|
54
|
-
return nil unless (json =
|
79
|
+
return nil unless (json = data).is_a?(Hash)
|
55
80
|
(v = json.dig(*path).to_i) != 0 ? v : nil
|
56
81
|
end
|
57
82
|
|
58
83
|
def dig_for_string(*path)
|
59
|
-
return nil unless (json =
|
84
|
+
return nil unless (json = data).is_a?(Hash)
|
60
85
|
(v = json.dig(*path)).to_s.present? ? (v.eql?("0") ? nil : v) : nil
|
61
86
|
end
|
62
87
|
|
88
|
+
class << self
|
89
|
+
private
|
90
|
+
|
91
|
+
def data_provided_in_hash?(hash)
|
92
|
+
# Check if hash contains entity data beyond just metadata fields
|
93
|
+
metadata_keys = %w[entityId id lastUpdateOn class action]
|
94
|
+
(hash.keys - metadata_keys).any?
|
95
|
+
end
|
96
|
+
|
97
|
+
def extract_entity_data(hash)
|
98
|
+
# Remove metadata fields and return just the entity data
|
99
|
+
hash.except("class", "action")
|
100
|
+
end
|
101
|
+
end
|
63
102
|
end
|
data/lib/realogy/version.rb
CHANGED