Class: RETS::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rets/client.rb

Constant Summary

URL_KEYS =
{:getobject => true, :login => true, :logout => true, :search => true, :getmetadata => true}

Class Method Summary (collapse)

Class Method Details

+ (RETS::Base::Core) login(args)

Attempts to login to a RETS server.

Parameters:

  • args (Hash)

Options Hash (args):

  • :url (String)

    Login URL for the RETS server

  • :username (String)

    Username to authenticate with

  • :password (String)

    Password to authenticate with

  • :auth_mode (Symbol, Optional)

    When set to :basic will automatically use HTTP Basic authentication, skips a discovery request when initially connecting

  • :useragent (Hash, Optional)

    Only necessary for User Agent authentication

    • :name [String, Optional] - Name to set the User-Agent to

    • :password [String, Optional] - Password to use for RETS-UA-Authorization

  • :rets_version (String, Optional)

    Forces RETS-UA-Authorization on the first request if this and useragent name/password are set. Can be auto detected, but usually lets you bypass 1 - 2 additional authentication requests initially.

  • :http (Hash, Optional)

    Additional configuration for the HTTP requests

    • :verify_mode [Integer, Optional] How to verify the SSL certificate when connecting through HTTPS, either OpenSSL::SSL::VERIFY_PEER or OpenSSL::SSL::VERIFY_NONE, defaults to OpenSSL::SSL::VERIFY_NONE

    • :ca_file [String, Optional] Path to the CA certification file in PEM format

    • :ca_path [String, Optional] Path to the directory containing CA certifications in PEM format

    • :proxy [Hash, Optional] Use a HTTP proxy to communicate with the RETS server

    • :proxy :address [String, Optional] Address to connect to the proxy

    • :proxy :port [Integer, Optional] Port to use

    • :proxy :username [String, Optional] Username to authenticate to the proxy with if authentication is required

    • :proxy :password [String, Optional] Password to authenticate to the proxy with if authentication is required

Returns:

Raises:



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
69
70
71
72
73
# File 'lib/rets/client.rb', line 35

def self.(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, :read_timeout => args[:read_timeout]) 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. = urls[:login]

  RETS::Base::Core.new(http, urls)
end