caboose-rets 0.1.194 → 0.1.195
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/app/controllers/caboose_rets/properties_controller.rb +1 -1
- data/app/models/caboose_rets/media.rb +74 -74
- data/app/models/caboose_rets/rets_importer.rb +223 -143
- data/app/models/caboose_rets/rets_importer_old.rb +622 -0
- data/lib/caboose_rets/version.rb +1 -1
- data/lib/tasks/caboose_rets.rake +8 -4
- metadata +3 -2
@@ -1,21 +1,9 @@
|
|
1
|
-
|
2
|
-
require "rets/version"
|
3
|
-
require "rets/exceptions"
|
4
|
-
require "rets/client"
|
5
|
-
require "rets/http"
|
6
|
-
require "rets/stream_http"
|
7
|
-
require "rets/base/core"
|
8
|
-
require "rets/base/sax_search"
|
9
|
-
require "rets/base/sax_metadata"
|
10
|
-
|
11
|
-
require 'httparty'
|
12
|
-
require 'json'
|
13
|
-
|
14
|
-
# http://rets.solidearth.com/ClientHome.aspx
|
1
|
+
require 'oauth2'
|
15
2
|
|
16
3
|
class CabooseRets::RetsImporter # < ActiveRecord::Base
|
17
4
|
|
18
5
|
@@rets_client = nil
|
6
|
+
@@rets_access = nil
|
19
7
|
@@config = nil
|
20
8
|
|
21
9
|
def self.config
|
@@ -24,12 +12,12 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
24
12
|
|
25
13
|
def self.get_config
|
26
14
|
@@config = {
|
27
|
-
'
|
28
|
-
'
|
29
|
-
'
|
15
|
+
'endpoint' => nil,
|
16
|
+
'token_endpoint' => nil,
|
17
|
+
'client_id' => nil,
|
18
|
+
'client_secret' => nil,
|
30
19
|
'temp_path' => nil,
|
31
|
-
'log_file' => nil
|
32
|
-
'media_base_url' => nil
|
20
|
+
'log_file' => nil
|
33
21
|
}
|
34
22
|
config = YAML::load(File.open("#{Rails.root}/config/rets_importer.yml"))
|
35
23
|
config = config[Rails.env]
|
@@ -39,15 +27,58 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
39
27
|
def self.client
|
40
28
|
self.get_config if @@config.nil? || @@config['url'].nil?
|
41
29
|
if @@rets_client.nil?
|
42
|
-
@@rets_client =
|
43
|
-
|
44
|
-
|
45
|
-
:
|
30
|
+
@@rets_client = ::OAuth2::Client.new(
|
31
|
+
@@config['client_id'],
|
32
|
+
@@config['client_secret'],
|
33
|
+
site: @@config['endpoint'],
|
34
|
+
token_url: @@config['token_endpoint']
|
46
35
|
)
|
47
36
|
end
|
48
37
|
return @@rets_client
|
49
38
|
end
|
50
39
|
|
40
|
+
def self.access
|
41
|
+
@@rets_access = self.client.client_credentials.get_token
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.resource(resource_name, query, per_page = 100, count = false, select_column = nil, page_number = 1)
|
45
|
+
|
46
|
+
params = {
|
47
|
+
"$filter" => query,
|
48
|
+
"$top" => per_page
|
49
|
+
}
|
50
|
+
|
51
|
+
extra_path = ""
|
52
|
+
|
53
|
+
if count
|
54
|
+
extra_path = "/$count"
|
55
|
+
end
|
56
|
+
|
57
|
+
if !select_column.blank?
|
58
|
+
params["$select"] = "ListingId"
|
59
|
+
end
|
60
|
+
|
61
|
+
if page_number > 1
|
62
|
+
params["$skip"] = ((page_number - 1) * per_page)
|
63
|
+
end
|
64
|
+
|
65
|
+
url_path = "/trestle/odata/#{resource_name}#{extra_path}"
|
66
|
+
|
67
|
+
# self.log3(resource_name, nil, "Making request to URL #{url_path} with params #{params}")
|
68
|
+
|
69
|
+
response = self.access.get(url_path, params: params )
|
70
|
+
|
71
|
+
if response && response.body
|
72
|
+
if response.parsed['@odata.count']
|
73
|
+
return response.parsed['@odata.count']
|
74
|
+
else
|
75
|
+
return response.parsed['value']
|
76
|
+
end
|
77
|
+
else
|
78
|
+
return nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
51
82
|
def self.meta(class_type)
|
52
83
|
case class_type
|
53
84
|
when 'Office' then Caboose::StdClass.new({ :search_type => 'Office' , :remote_key_field => 'OfficeMlsId' , :local_key_field => 'lo_mls_id' , :local_table => 'rets_offices' , :date_modified_field => 'ModificationTimestamp'})
|
@@ -62,32 +93,44 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
62
93
|
# Import method
|
63
94
|
#=============================================================================
|
64
95
|
|
96
|
+
def self.import_one_property(mls_number)
|
97
|
+
response = self.resource('Property', "ListingId eq '#{mls_number}'")
|
98
|
+
data = response ? response[0] : nil
|
99
|
+
# self.log3('Property',nil,"WE GOT THE PROPERTY: #{data['ListingId']}") if data
|
100
|
+
obj = data ? self.get_instance_with_id('Property', data) : nil
|
101
|
+
if obj.nil?
|
102
|
+
self.log3(class_type,nil,"Error: object is nil")
|
103
|
+
self.log3(class_type,nil,data.inspect)
|
104
|
+
else
|
105
|
+
obj.parse(data)
|
106
|
+
obj.save
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
65
110
|
def self.import(class_type, query)
|
66
111
|
m = self.meta(class_type)
|
67
112
|
self.log3(class_type,nil,"Importing #{m.search_type}:#{class_type} with query #{query}...")
|
68
113
|
self.get_config if @@config.nil? || @@config['url'].nil?
|
69
|
-
|
70
|
-
:search_type => m.search_type,
|
71
|
-
:class => class_type,
|
72
|
-
:query => query,
|
73
|
-
:timeout => -1
|
74
|
-
}
|
114
|
+
|
75
115
|
obj = nil
|
76
116
|
|
77
117
|
begin
|
78
|
-
self.
|
79
|
-
|
80
|
-
|
81
|
-
self.
|
82
|
-
|
83
|
-
|
118
|
+
results = self.resource(m.search_type, query)
|
119
|
+
if results && results.count > 0
|
120
|
+
results.each do |data|
|
121
|
+
obj = self.get_instance_with_id(class_type, data)
|
122
|
+
if obj.nil?
|
123
|
+
self.log3(class_type,nil,"Error: object is nil")
|
124
|
+
self.log3(class_type,nil,data.inspect)
|
125
|
+
next
|
126
|
+
end
|
127
|
+
obj.parse(data)
|
128
|
+
obj.save
|
84
129
|
end
|
85
|
-
obj.parse(data)
|
86
|
-
obj.save
|
87
130
|
end
|
88
|
-
rescue
|
131
|
+
rescue
|
89
132
|
self.log3(class_type,nil,"Import error for #{class_type}: #{query}")
|
90
|
-
self.log3(class_type,nil,err.message)
|
133
|
+
#self.log3(class_type,nil,err.message)
|
91
134
|
end
|
92
135
|
end
|
93
136
|
|
@@ -130,56 +173,50 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
130
173
|
self.log3(class_type,nil,"Updating #{class_type} modified after #{date_modified} and #{si}")
|
131
174
|
m = self.meta(class_type)
|
132
175
|
k = m.remote_key_field
|
133
|
-
d = date_modified.in_time_zone(CabooseRets::timezone).strftime("%FT%
|
176
|
+
d = date_modified.in_time_zone(CabooseRets::timezone).strftime("%FT%TZ")
|
134
177
|
|
135
178
|
statusquery = ""
|
136
179
|
case class_type
|
137
|
-
when 'Property' then statusquery = "OriginatingSystemName
|
138
|
-
when 'Office' then statusquery = "OfficeStatus
|
139
|
-
when 'Member' then statusquery = "MemberStatus
|
140
|
-
when 'OpenHouse' then statusquery = "OpenHouseKeyNumeric
|
180
|
+
when 'Property' then statusquery = "OriginatingSystemName eq 'WESTAL'"
|
181
|
+
when 'Office' then statusquery = "OfficeStatus eq 'Active'"
|
182
|
+
when 'Member' then statusquery = "MemberStatus eq 'Active'"
|
183
|
+
when 'OpenHouse' then statusquery = "OpenHouseKeyNumeric gt 0"
|
141
184
|
end
|
142
185
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
self.
|
155
|
-
self.
|
156
|
-
|
157
|
-
|
158
|
-
when 'Property' then self.delay(:priority => 10, :queue => 'rets').import_properties(data[k], save_images)
|
159
|
-
when 'Office' then self.delay(:priority => 10, :queue => 'rets').import_office( data[k], false)
|
160
|
-
when 'Member' then self.delay(:priority => 10, :queue => 'rets').import_agent( data[k], false)
|
161
|
-
when 'OpenHouse' then self.delay(:priority => 10, :queue => 'rets').import_open_house(data[k], false)
|
186
|
+
query = "#{m.date_modified_field} gt #{d} and #{statusquery}"
|
187
|
+
|
188
|
+
self.log3(class_type,nil,"Searching with query: " + query)
|
189
|
+
|
190
|
+
results = self.resource(m.search_type, query, 1000)
|
191
|
+
|
192
|
+
if results && results.count > 0
|
193
|
+
results.each do |data|
|
194
|
+
# self.log3(class_type,nil,"Resulting data: " + data.to_s)
|
195
|
+
case class_type
|
196
|
+
when 'Property' then self.delay(:priority => 10, :queue => 'rets').import_properties(data[k], save_images)
|
197
|
+
when 'Office' then self.delay(:priority => 10, :queue => 'rets').import_office( data[k], false)
|
198
|
+
when 'Member' then self.delay(:priority => 10, :queue => 'rets').import_agent( data[k], false)
|
199
|
+
when 'OpenHouse' then self.delay(:priority => 10, :queue => 'rets').import_open_house(data[k], false)
|
200
|
+
end
|
162
201
|
end
|
163
202
|
end
|
164
203
|
|
165
204
|
# Check for changed images
|
166
205
|
if class_type == 'Property' && Rails.env.production?
|
167
206
|
self.log3("Property",nil,"Checking for modified images on Properties...")
|
168
|
-
d1 = (self.last_updated - 1.hours).in_time_zone(CabooseRets::timezone).strftime("%FT%
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
self.log3(class_type,nil,"Resulting data: " + data.to_s)
|
182
|
-
self.delay(:priority => 10, :queue => 'rets').import_properties(data[k], true)
|
207
|
+
d1 = (self.last_updated - 1.hours).in_time_zone(CabooseRets::timezone).strftime("%FT%TZ")
|
208
|
+
|
209
|
+
query = "PhotosChangeTimestamp gt #{d1} and OriginatingSystemName eq 'WESTAL' and MlsStatus eq 'Active'"
|
210
|
+
|
211
|
+
self.log3(class_type,nil,"Searching with query: " + query)
|
212
|
+
|
213
|
+
results = self.resource(m.search_type, query, 1000)
|
214
|
+
|
215
|
+
if results && results.count > 0
|
216
|
+
results.each do |data|
|
217
|
+
# self.log3(class_type,nil,"Resulting data: " + data.to_s)
|
218
|
+
self.delay(:priority => 10, :queue => 'rets').import_properties(data[k], true)
|
219
|
+
end
|
183
220
|
end
|
184
221
|
end
|
185
222
|
|
@@ -193,10 +230,10 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
193
230
|
si = save_images ? 'saving images' : 'not saving images'
|
194
231
|
self.log3('Property',mls_id,"Importing Property #{mls_id} and #{si}...")
|
195
232
|
save_images = true if !CabooseRets::Property.where(:mls_number => mls_id.to_s).exists?
|
196
|
-
self.import('Property', "
|
233
|
+
self.import('Property', "ListingId eq '#{mls_id}'")
|
197
234
|
p = CabooseRets::Property.where(:mls_number => mls_id.to_s).first
|
198
235
|
if p != nil && p.status == 'Active'
|
199
|
-
self.download_property_images(p) if save_images == true && Rails.env.production?
|
236
|
+
self.download_property_images(p) if save_images == true # && Rails.env.production?
|
200
237
|
if p.latitude.blank? || p.latitude == '0.0' || p.longitude.blank? || p.longitude == '0.0'
|
201
238
|
self.update_coords(p)
|
202
239
|
end
|
@@ -207,7 +244,7 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
207
244
|
|
208
245
|
def self.import_office(mls_id, save_images = true)
|
209
246
|
self.log3('Office',mls_id,"Importing Office #{mls_id}...")
|
210
|
-
self.import('Office', "
|
247
|
+
self.import('Office', "OfficeMlsId eq '#{mls_id}'")
|
211
248
|
office = CabooseRets::Office.where(:matrix_unique_id => mls_id.to_s).first
|
212
249
|
end
|
213
250
|
|
@@ -216,7 +253,7 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
216
253
|
a = CabooseRets::Agent.where(:mls_id => mls_id.to_s).first
|
217
254
|
if a.nil?
|
218
255
|
self.log3('Agent',mls_id,"Importing new Agent #{mls_id}...")
|
219
|
-
self.import('Member', "
|
256
|
+
self.import('Member', "MemberMlsId eq '#{mls_id}'")
|
220
257
|
a = CabooseRets::Agent.where(:mls_id => mls_id.to_s).first
|
221
258
|
if a
|
222
259
|
a.last_updated = DateTime.now
|
@@ -229,7 +266,7 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
229
266
|
is_old = diff > 86400 # 24 hours
|
230
267
|
if is_old
|
231
268
|
self.log3('Agent',mls_id,"Updating existing Agent #{mls_id}...")
|
232
|
-
self.import('Member', "
|
269
|
+
self.import('Member', "MemberMlsId eq '#{mls_id}'")
|
233
270
|
a.last_updated = DateTime.now
|
234
271
|
a.save
|
235
272
|
else
|
@@ -240,12 +277,12 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
240
277
|
|
241
278
|
def self.import_open_house(oh_id, save_images = true)
|
242
279
|
self.log3('OpenHouse',oh_id,"Importing Open House #{oh_id}...")
|
243
|
-
self.import('OpenHouse', "
|
280
|
+
self.import('OpenHouse', "OpenHouseKey eq '#{oh_id}'")
|
244
281
|
end
|
245
282
|
|
246
283
|
def self.import_media(id, save_images = true)
|
247
284
|
self.log3('Media',id,"Importing Media #{id}...")
|
248
|
-
self.import('Media', "
|
285
|
+
self.import('Media', "MediaObjectID eq '#{id}'")
|
249
286
|
end
|
250
287
|
|
251
288
|
#=============================================================================
|
@@ -253,58 +290,102 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
253
290
|
#=============================================================================
|
254
291
|
|
255
292
|
def self.download_property_images(p)
|
256
|
-
|
293
|
+
# return if Rails.env.development?
|
257
294
|
self.log3('Property',p.mls_number,"Downloading images for #{p.mls_number}...")
|
258
295
|
ids_to_keep = []
|
259
296
|
begin
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
297
|
+
|
298
|
+
query = "ResourceRecordKey eq '#{p.matrix_unique_id}'"
|
299
|
+
photos = self.resource('Media',query,100)
|
300
|
+
|
301
|
+
photos.each do |photo|
|
302
|
+
ind = photo['Order']
|
303
|
+
self.log3('Media',p.mls_number,"Downloading photo with order #{ind}")
|
265
304
|
is_new = false
|
266
|
-
m = CabooseRets::Media.where(:media_mui =>
|
305
|
+
m = CabooseRets::Media.where(:media_mui => photo['ResourceRecordKey'], :media_order => ind).first
|
267
306
|
is_new = true if m.nil?
|
268
307
|
m = CabooseRets::Media.new if m.nil?
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
end
|
273
|
-
m.media_mui = headers['content-id']
|
308
|
+
|
309
|
+
url = photo['MediaURL']
|
310
|
+
m.media_mui = photo['ResourceRecordKey']
|
274
311
|
m.media_order = ind
|
275
312
|
m.media_type = 'Photo'
|
276
|
-
|
313
|
+
m.media_remarks = photo['ShortDescription']
|
314
|
+
|
277
315
|
old_cm_id = is_new ? nil : m.media_id
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
end
|
299
|
-
self.log3("Media",p.mls_number,"Image rets_media_#{headers['content-id']}_#{ind} saved")
|
300
|
-
else
|
301
|
-
self.log3("Media",p.mls_number,"CabooseMedia was not created for some reason, not saving RetsMedia")
|
302
|
-
end
|
303
|
-
rescue
|
304
|
-
self.log3("Media",p.mls_number,"Error processing image #{ind} from RETS")
|
316
|
+
|
317
|
+
cm = is_new ? Caboose::Media.new : Caboose::Media.where(:id => old_cm_id).first
|
318
|
+
|
319
|
+
cm.name = "rets_media_#{photo['ResourceRecordKey']}_#{ind}"
|
320
|
+
cm.save
|
321
|
+
|
322
|
+
m.media_id = cm.id
|
323
|
+
m.save
|
324
|
+
ids_to_keep << m.id
|
325
|
+
|
326
|
+
if !is_new
|
327
|
+
old_media = Caboose::Media.where(:id => old_cm_id).first
|
328
|
+
self.log3("Media",p.mls_number,"Deleting old CabooseMedia #{old_media.id}")
|
329
|
+
old_media.destroy if Rails.env.production?
|
330
|
+
end
|
331
|
+
|
332
|
+
if Rails.env.production?
|
333
|
+
cm.download_image_from_url(url)
|
334
|
+
else
|
335
|
+
puts "would download photo from URL #{url}"
|
305
336
|
end
|
306
|
-
|
337
|
+
|
307
338
|
end
|
339
|
+
|
340
|
+
# self.client.get_object(:resource => 'Property', :type => 'Photo', :location => false, :id => "#{p.matrix_unique_id}:*") do |headers, content|
|
341
|
+
# next if headers.blank?
|
342
|
+
# ind = headers['orderhint'] ? headers['orderhint'].to_i : 1
|
343
|
+
# self.log3('Media',p.mls_number,headers.to_s)
|
344
|
+
# self.log3('Media',p.mls_number,"Downloading photo with content-id #{headers['content-id']}, index #{ind}")
|
345
|
+
# is_new = false
|
346
|
+
# m = CabooseRets::Media.where(:media_mui => headers['content-id'], :media_order => ind).first
|
347
|
+
# is_new = true if m.nil?
|
348
|
+
# m = CabooseRets::Media.new if m.nil?
|
349
|
+
# tmp_path = "#{Rails.root}/tmp/rets_media_#{headers['content-id']}_#{ind}.jpeg"
|
350
|
+
# File.open(tmp_path, "wb") do |f|
|
351
|
+
# f.write(content)
|
352
|
+
# end
|
353
|
+
# m.media_mui = headers['content-id']
|
354
|
+
# m.media_order = ind
|
355
|
+
# m.media_type = 'Photo'
|
356
|
+
# cm = nil
|
357
|
+
# old_cm_id = is_new ? nil : m.media_id
|
358
|
+
# begin
|
359
|
+
# cm = Caboose::Media.new
|
360
|
+
# cm.image = File.open(tmp_path)
|
361
|
+
# cm.name = "rets_media_#{headers['content-id']}_#{ind}"
|
362
|
+
# cm.original_name = "rets_media_#{headers['content-id']}_#{ind}.jpeg"
|
363
|
+
# cm.processed = true
|
364
|
+
# cm.save
|
365
|
+
# if cm && !cm.id.blank?
|
366
|
+
# m.media_id = cm.id
|
367
|
+
# m.save
|
368
|
+
# ids_to_keep << m.id
|
369
|
+
# if is_new
|
370
|
+
# self.log3("Media",p.mls_number,"Created new RetsMedia object #{m.id}, media_id = #{m.media_id}")
|
371
|
+
# else
|
372
|
+
# old_media = Caboose::Media.where(:id => old_cm_id).first
|
373
|
+
# if old_media
|
374
|
+
# self.log3("Media",p.mls_number,"Deleting old CabooseMedia #{old_media.id}")
|
375
|
+
# old_media.destroy
|
376
|
+
# end
|
377
|
+
# self.log3("Media",p.mls_number,"RetsMedia object already existed #{m.id}, updated media_id = #{m.media_id}")
|
378
|
+
# end
|
379
|
+
# self.log3("Media",p.mls_number,"Image rets_media_#{headers['content-id']}_#{ind} saved")
|
380
|
+
# else
|
381
|
+
# self.log3("Media",p.mls_number,"CabooseMedia was not created for some reason, not saving RetsMedia")
|
382
|
+
# end
|
383
|
+
# rescue
|
384
|
+
# self.log3("Media",p.mls_number,"Error processing image #{ind} from RETS")
|
385
|
+
# end
|
386
|
+
# `rm #{tmp_path}`
|
387
|
+
# end
|
388
|
+
|
308
389
|
rescue
|
309
390
|
self.log3("Media",p.mls_number,"Error downloading images for property with MLS # #{p.mls_number}")
|
310
391
|
end
|
@@ -316,7 +397,7 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
316
397
|
CabooseRets::Media.where(:media_mui => p.matrix_unique_id).where("id not in (?)",ids_to_keep).each do |med|
|
317
398
|
self.log3("Media",p.mls_number,"Deleting old RetsMedia #{med.id} and CabooseMedia #{med.media_id}...")
|
318
399
|
m = Caboose::Media.where(:id => med.media_id).where("name ILIKE ?","rets_media%").first
|
319
|
-
m.destroy if m
|
400
|
+
m.destroy if m && Rails.env.production?
|
320
401
|
med.destroy
|
321
402
|
end
|
322
403
|
end
|
@@ -393,7 +474,7 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
393
474
|
|
394
475
|
def self.purge_properties() self.delay(:priority => 10, :queue => 'rets').purge_helper('Property', '2012-01-01') end
|
395
476
|
def self.purge_offices() self.delay(:priority => 10, :queue => 'rets').purge_helper('Office', '2012-01-01') end
|
396
|
-
def self.purge_agents() self.delay(:priority => 10, :queue => 'rets').purge_helper('Member', '2012-01-
|
477
|
+
def self.purge_agents() self.delay(:priority => 10, :queue => 'rets').purge_helper('Member', '2012-01-01T') end
|
397
478
|
def self.purge_open_houses() self.delay(:priority => 10, :queue => 'rets').purge_helper('OpenHouse', '2012-01-01') end
|
398
479
|
|
399
480
|
|
@@ -410,32 +491,31 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
|
|
410
491
|
statusquery = ""
|
411
492
|
|
412
493
|
case class_type
|
413
|
-
when 'Property' then statusquery = "MlsStatus
|
414
|
-
when 'Office' then statusquery = "OfficeStatus
|
415
|
-
when 'Member' then statusquery = "MemberStatus
|
416
|
-
when 'OpenHouse' then statusquery = "OpenHouseKeyNumeric
|
494
|
+
when 'Property' then statusquery = "MlsStatus eq 'Active'"
|
495
|
+
when 'Office' then statusquery = "OfficeStatus eq 'Active'"
|
496
|
+
when 'Member' then statusquery = "MemberStatus eq 'Active'"
|
497
|
+
when 'OpenHouse' then statusquery = "OpenHouseKeyNumeric gt 0"
|
417
498
|
end
|
418
499
|
|
419
|
-
|
420
|
-
|
421
|
-
:class => class_type,
|
422
|
-
:query => "(#{m.date_modified_field}=#{date_modified}T00:00:01+)AND(#{statusquery})AND(OriginatingSystemName=WESTAL)",
|
423
|
-
:standard_names_only => true,
|
424
|
-
:limit => 1000,
|
425
|
-
:timeout => -1
|
426
|
-
}
|
500
|
+
query = "#{m.date_modified_field} gt #{date_modified}T00:00:01Z and #{statusquery} and OriginatingSystemName eq 'WESTAL'"
|
501
|
+
|
427
502
|
count = 0
|
428
|
-
self.
|
429
|
-
|
503
|
+
result = self.resource(class_type, query, 1, true, nil)
|
504
|
+
|
505
|
+
count = result ? result.to_f : 0.0
|
506
|
+
|
430
507
|
batch_count = (count.to_f/1000.0).ceil
|
431
508
|
|
432
509
|
ids = []
|
433
510
|
k = m.remote_key_field
|
434
511
|
(0...batch_count).each do |i|
|
435
512
|
self.log3(class_type,nil,"Getting ids for #{class_type} (batch #{i+1} of #{batch_count})...")
|
436
|
-
|
513
|
+
|
514
|
+
results = self.resource(class_type, query, 1000, false, k, (i+1))
|
515
|
+
results.each do |data|
|
437
516
|
ids << data[k]
|
438
517
|
end
|
518
|
+
|
439
519
|
end
|
440
520
|
|
441
521
|
# Only do stuff if we got a real response from the server
|