Class: Rets::HttpClient
- Inherits:
-
Object
- Object
- Rets::HttpClient
- Defined in:
- lib/rets/http_client.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#login_url ⇒ Object
readonly
Returns the value of attribute login_url.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #http_cookie(name) ⇒ Object
- #http_get(url, params = nil, extra_headers = {}) ⇒ Object
- #http_post(url, params, extra_headers = {}) ⇒ Object
-
#initialize(http, options, logger, login_url) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #log_http_traffic(method, url, params, headers, &block) ⇒ Object
- #rets_extra_headers ⇒ Object
- #save_cookie_store(force = nil) ⇒ Object
Constructor Details
#initialize(http, options, logger, login_url) ⇒ HttpClient
Returns a new instance of HttpClient.
5 6 7 8 9 10 11 |
# File 'lib/rets/http_client.rb', line 5 def initialize(http, , logger, login_url) @http = http @options = @logger = logger @login_url = login_url @options.fetch(:ca_certs, []).each {|c| @http.ssl_config.add_trust_ca(c) } end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
3 4 5 |
# File 'lib/rets/http_client.rb', line 3 def http @http end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'lib/rets/http_client.rb', line 3 def logger @logger end |
#login_url ⇒ Object (readonly)
Returns the value of attribute login_url.
3 4 5 |
# File 'lib/rets/http_client.rb', line 3 def login_url @login_url end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/rets/http_client.rb', line 3 def @options end |
Instance Method Details
#http_cookie(name) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/rets/http_client.rb', line 84 def (name) http..each do |c| return c.value if c.name.downcase == name.downcase && c.match?(URI.parse(login_url)) end nil end |
#http_get(url, params = nil, extra_headers = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rets/http_client.rb', line 13 def http_get(url, params=nil, extra_headers={}) http.set_auth(url, [:username], [:password]) headers = extra_headers.merge(rets_extra_headers) res = nil log_http_traffic("POST", url, params, headers) do res = http.get(url, params, headers) end Client::ErrorChecker.check(res) res end |
#http_post(url, params, extra_headers = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rets/http_client.rb', line 24 def http_post(url, params, extra_headers = {}) http.set_auth(url, [:username], [:password]) headers = extra_headers.merge(rets_extra_headers) res = nil log_http_traffic("POST", url, params, headers) do res = http.post(url, params, headers) end Client::ErrorChecker.check(res) res end |
#log_http_traffic(method, url, params, headers, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rets/http_client.rb', line 35 def log_http_traffic(method, url, params, headers, &block) # optimization, we don't want to compute log params # if logging is off if logger.debug? logger.debug "Rets::Client >> #{method} #{url}" logger.debug "Rets::Client >> params = #{params.inspect}" logger.debug "Rets::Client >> headers = #{headers.inspect}" end res = block.call # optimization, we don't want to compute log params # if logging is off, especially when there is a loop just # for logging if logger.debug? logger.debug "Rets::Client << Status #{res.status_code}" res.headers.each { |k, v| logger.debug "Rets::Client << #{k}: #{v}" } end end |
#rets_extra_headers ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rets/http_client.rb', line 65 def rets_extra_headers user_agent = [:agent] || "Client/1.0" rets_version = [:version] || "RETS/1.7.2" headers = { "User-Agent" => user_agent, "RETS-Version" => rets_version } if [:ua_password] up = Digest::MD5.hexdigest "#{user_agent}:#{[:ua_password]}" session_id = ('RETS-Session-ID') || '' digest = Digest::MD5.hexdigest "#{up}::#{session_id}:#{rets_version}" headers.merge!("RETS-UA-Authorization" => "Digest #{digest}") end headers end |
#save_cookie_store(force = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/rets/http_client.rb', line 55 def (force=nil) if [:cookie_store] if force @http..(true, true, true) else @http. end end end |