Class: NOMS::Command::UserAgent::Requester::HTTPClient

Inherits:
Base
  • Object
show all
Defined in:
lib/noms/command/useragent/requester/httpclient.rb

Instance Attribute Summary

Attributes inherited from Base

#logger

Instance Method Summary collapse

Methods inherited from Base

#default_logger

Constructor Details

#initialize(opt = {}) ⇒ HTTPClient

Returns a new instance of HTTPClient.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/noms/command/useragent/requester/httpclient.rb', line 29

def initialize(opt={})
    @log = opt[:logger] || default_logger
    @log.debug "Creating #{self.class} with options: #{opt.inspect}"
    @client_opts = opt
    @client = ::HTTPClient.new :agent_name => "noms/#{NOMS::Command::VERSION} httpclient/#{::HTTPClient::VERSION}"
    @cookies = opt.has_key?(:cookies) ? opt[:cookies] : true
    if @cookies
        cookie_jar = File.join(NOMS::Command.home, 'cookies.txt')
        @client.set_cookie_store(cookie_jar)
    else
        @client.cookie_manager = nil
    end
    @client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

Instance Method Details

#request(opt = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/noms/command/useragent/requester/httpclient.rb', line 44

def request(opt={})
    response = @client.request(opt[:method].to_s.upcase, opt[:url], '', opt[:body], opt[:headers])
    noms_response = NOMS::Command::UserAgent::Response::HTTPClient.new(response)
    if @cookies
        # @client.save_cookie_store - There is a bug where
        # it thinks @is_saved is satisfied all the time and
        # the file isn't written, which is why we call
        # cookie manager directly.
        @client.cookie_manager.save_all_cookies(true)
    end
    noms_response
end

#set_auth(domain, username, password) ⇒ Object



57
58
59
# File 'lib/noms/command/useragent/requester/httpclient.rb', line 57

def set_auth(domain, username, password)
    @client.set_auth(domain, username, password)
end