caboose-rets 0.1.36 → 0.1.37

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.
@@ -1,3 +1,3 @@
1
1
  module CabooseRets
2
- VERSION = '0.1.36'
2
+ VERSION = '0.1.37'
3
3
  end
@@ -243,6 +243,7 @@ module RETS
243
243
  # @see #request_size
244
244
  # @see #request_hash
245
245
  def search(args, &block)
246
+ # puts "starting search..."
246
247
  if !block_given? and args[:count_mode] != :only
247
248
  raise ArgumentError, "No block found"
248
249
  end
@@ -264,8 +265,11 @@ module RETS
264
265
 
265
266
  @request_size, @request_hash, @request_time, @rets_data = nil, nil, nil, {}
266
267
 
268
+ # puts "req: #{req.to_s}"
269
+
267
270
  start = Time.now.utc.to_f
268
271
  @http.request(req) do |response|
272
+ # puts "URL: #{req[:url]}"
269
273
  if args[:disable_stream]
270
274
  stream = StringIO.new(response.body)
271
275
  @request_time = Time.now.utc.to_f - start
data/lib/rets/client.rb CHANGED
@@ -63,7 +63,7 @@ module RETS
63
63
  end
64
64
 
65
65
  http.login_uri = urls[:login]
66
-
66
+ # puts "URLS: #{urls.to_s}"
67
67
  RETS::Base::Core.new(http, urls)
68
68
  end
69
69
  end
data/lib/rets/http.rb CHANGED
@@ -8,7 +8,7 @@ module RETS
8
8
  ##
9
9
  # Creates a new HTTP instance which will automatically handle authenting to the RETS server.
10
10
  def initialize(args)
11
- @headers = {"User-Agent" => "Ruby RETS/v#{RETS::VERSION}", "Accept-Encoding" => "none"}
11
+ @headers = {"User-Agent" => "Ruby RETS/v#{RETS::VERSION}", "Accept-Encoding" => "none", "RETS-Version" => "1.8.0"}
12
12
  @request_count = 0
13
13
  @config = {:http => {}}.merge(args)
14
14
  @rets_data, @cookie_list = {}, {}
@@ -135,7 +135,7 @@ module RETS
135
135
  text = attr.last.value
136
136
  end
137
137
  end
138
-
138
+ # puts "replycode: #{code}"
139
139
  return code, text
140
140
  end
141
141
 
@@ -179,6 +179,8 @@ module RETS
179
179
  request_uri = args[:url].request_uri
180
180
  end
181
181
 
182
+ request_uri = request_uri[0..-2] if request_uri[-1] == '&'
183
+
182
184
  headers = args[:headers]
183
185
 
184
186
  # Digest will change every time due to how its setup
@@ -204,6 +206,9 @@ module RETS
204
206
  http.ca_path = @config[:http][:ca_path] if @config[:http][:ca_path]
205
207
  end
206
208
 
209
+ puts "request_uri: #{request_uri}"
210
+ # puts "headers: #{headers.to_s}"
211
+
207
212
  http.start do
208
213
  http.request_get(request_uri, headers) do |response|
209
214
  # Pass along the cookies
@@ -234,6 +239,10 @@ module RETS
234
239
  end
235
240
  end
236
241
 
242
+ # puts "response.code: #{response.code}"
243
+ # puts "response.body: #{response.body}"
244
+ # puts "response.message: #{response.message}"
245
+
237
246
  # Rather than returning HTTP 401 when User-Agent authentication is needed, Retsiq returns HTTP 200
238
247
  # with RETS error 20037. If we get a 20037, will let it pass through and handle it as if it was a HTTP 401.
239
248
  # Retsiq apparently returns a 20041 now instead of a 20037 for the same use case.
@@ -241,12 +250,13 @@ module RETS
241
250
  rets_code = nil
242
251
  if response.code != "401" and ( response.code != "200" or args[:check_response] )
243
252
  if response.body =~ /<RETS/i
253
+ # puts "found RETS in response body"
244
254
  rets_code, text = self.get_rets_response(Nokogiri::XML(response.body).xpath("//RETS").first)
245
255
  unless rets_code == "20037" or rets_code == "20041" or rets_code == "20052" or rets_code == "0"
246
256
  raise RETS::APIError.new("#{rets_code}: #{text}", rets_code, text)
247
257
  end
248
-
249
258
  elsif !args[:check_response]
259
+ # puts "didn't find RETS in response body and check_response is false"
250
260
  raise RETS::HTTPError.new("#{response.code}: #{response.message}", response.code, response.message)
251
261
  end
252
262
  end
@@ -13,26 +13,29 @@ namespace :caboose_rets do
13
13
  desc "Do a simple search"
14
14
  task :simple_search => :environment do
15
15
  type = ['p','a','o','oh']
16
- rets_config = CabooseRets::RetsConfig.where("rets_url ILIKE ?","%mlsmatrix%").order('RANDOM()').first
16
+ @@config = nil
17
+ config = YAML::load(File.open("#{Rails.root}/config/rets_importer.yml"))
18
+ config = config[Rails.env]
19
+ config.each { |key,val| @@config[key] = val }
17
20
  client = RETS::Client.login(
18
- :url => rets_config.rets_url,
19
- :username => rets_config.rets_username,
20
- :password => rets_config.rets_password
21
+ :url => config['url'],
22
+ :username => config['username'],
23
+ :password => config['password']
21
24
  )
22
25
  type.each do |t|
23
26
  if t == 'p'
24
27
  params = {
25
28
  :search_type => 'Property',
26
- :class => 'Listing',
27
- :query => "(Matrix_Unique_ID=0+)",
28
- :limit => 100,
29
+ :class => 'Property',
30
+ :query => "(MlsStatus=Active)",
31
+ :limit => 1,
29
32
  :timeout => -1
30
33
  }
31
34
  elsif t == 'a'
32
35
  params = {
33
- :search_type => 'Agent',
34
- :class => 'Agent',
35
- :query => "(Matrix_Unique_ID=0+)",
36
+ :search_type => 'Member',
37
+ :class => 'Member',
38
+ :query => "(MemberStatus=Active)",
36
39
  :limit => 1,
37
40
  :timeout => -1
38
41
  }
@@ -40,7 +43,7 @@ namespace :caboose_rets do
40
43
  params = {
41
44
  :search_type => 'Office',
42
45
  :class => 'Office',
43
- :query => "(Matrix_Unique_ID=0+)",
46
+ :query => "(OfficeStatus=Active)",
44
47
  :limit => 1,
45
48
  :timeout => -1
46
49
  }
@@ -48,7 +51,7 @@ namespace :caboose_rets do
48
51
  params = {
49
52
  :search_type => 'OpenHouse',
50
53
  :class => 'OpenHouse',
51
- :query => "(Matrix_Unique_ID=0+)",
54
+ :query => "(OpenHouseKeyNumeric=0+)",
52
55
  :limit => 1,
53
56
  :timeout => -1
54
57
  }
@@ -69,36 +72,37 @@ namespace :caboose_rets do
69
72
  task :reimport_property_images => :environment do
70
73
  props = CabooseRets::Property.all
71
74
  props.each do |p|
72
- CabooseRets::RetsImporter.log("- Reimporting images for #{p.matrix_unique_id}...")
73
- CabooseRets::Media.where(:media_mui => p.matrix_unique_id, :media_type => 'Photo').destroy_all
75
+ CabooseRets::RetsImporter.log("- Reimporting images for #{p.mls_number}...")
76
+ CabooseRets::Media.where(:media_mui => p.mls_number, :media_type => 'Photo').destroy_all
74
77
  CabooseRets::RetsImporter.download_property_images(p)
75
78
  end
76
79
  end
77
80
 
78
81
  desc "Import rets data"
79
82
  task :import => :environment do
80
- CabooseRets::RetsImporter.import('Agent' , "(Matrix_Unique_ID=0+)")
81
- CabooseRets::RetsImporter.import('Listing' , "(Matrix_Unique_ID=0+)")
82
- CabooseRets::RetsImporter.import('Office' , "(Matrix_Unique_ID=0+)")
83
- CabooseRets::RetsImporter.import('OpenHouse', "(Matrix_Unique_ID=0+)")
83
+ CabooseRets::RetsImporter.import('Member' , "(MemberStatus=Active)")
84
+ CabooseRets::RetsImporter.import('Property' , "(MlsStatus=Active)")
85
+ CabooseRets::RetsImporter.import('Office' , "(OfficeStatus=Active)")
86
+ CabooseRets::RetsImporter.import('OpenHouse' , "(OpenHouseKeyNumeric=0+)")
84
87
  end
85
88
 
86
89
  desc "Single Import Test"
87
90
  task :import_one => :environment do
88
- CabooseRets::RetsImporter.import_properties('9468475' , "(Matrix_Unique_ID=9468475)")
91
+ #CabooseRets::RetsImporter.import_properties('130185',false)
92
+ CabooseRets::RetsImporter.import_agent('118596368',false)
89
93
  end
90
94
 
91
95
  desc "Purge rets data"
92
96
  task :purge => :environment do
93
- CabooseRets::RetsImporter.purge_helper('Listing', '2013-08-06')
97
+ CabooseRets::RetsImporter.purge_helper('Property', '2013-08-06')
94
98
  CabooseRets::RetsImporter.purge_helper('Office', '2012-01-01')
95
- CabooseRets::RetsImporter.purge_helper('Agent', '2012-01-01')
99
+ CabooseRets::RetsImporter.purge_helper('Member', '2012-01-01')
96
100
  CabooseRets::RetsImporter.purge_helper('OpenHouse', '2012-01-01')
97
101
  end
98
102
 
99
103
  desc "update helper"
100
104
  task :uh => :environment do
101
- CabooseRets::RetsImporter.update_helper('Listing', last_updated)
105
+ CabooseRets::RetsImporter.update_helper('Property', last_updated)
102
106
  end
103
107
 
104
108
  #desc "Delete old rets properties"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-rets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.36
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-13 00:00:00.000000000 Z
11
+ date: 2018-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caboose-cms