Class: RETS::Client
- Inherits:
-
Object
- Object
- RETS::Client
- Defined in:
- lib/rets/client.rb
Constant Summary collapse
- URL_KEYS =
{:getobject => true, :login => true, :logout => true, :search => true, :getmetadata => true}
Class Method Summary collapse
-
.login(args) ⇒ RETS::Base::Core
Attempts to login to a RETS server.
Class Method Details
.login(args) ⇒ RETS::Base::Core
Attempts to login to a RETS server.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rets/client.rb', line 30 def self.login(args) raise ArgumentError, "No URL passed" unless args[:url] urls = {:login => URI.parse(args[:url])} raise ArgumentError, "Invalid URL passed" unless urls[:login].is_a?(URI::HTTP) base_url = urls[:login].to_s base_url.gsub!(urls[:login].path, "") if urls[:login].path http = RETS::HTTP.new(args) http.request(:url => urls[:login], :check_response => true) do |response| rets_attr = Nokogiri::XML(response.body).xpath("//RETS") if rets_attr.empty? raise RETS::ResponseError, "Does not seem to be a RETS server." end rets_attr.first.content.split("\n").each do |row| key, value = row.split("=", 2) next unless key and value key, value = key.downcase.strip.to_sym, value.strip if URL_KEYS[key] # In case it's a relative path and doesn't include the domain if value =~ /(http|www)/ urls[key] = URI.parse(value) else key_url = URI.parse(urls[:login].to_s) key_url.path = value urls[key] = key_url end end end end http.login_uri = urls[:login] # puts "URLS: #{urls.to_s}" RETS::Base::Core.new(http, urls) end |