Class: NOMS::Command::UserAgent::Requester::Typhoeus
- Defined in:
- lib/noms/command/useragent/requester/typhoeus.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #get_auth(url) ⇒ Object
-
#initialize(opt = {}) ⇒ Typhoeus
constructor
A new instance of Typhoeus.
- #request(opt = {}) ⇒ Object
- #set_auth(domain, username, password) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(opt = {}) ⇒ Typhoeus
Returns a new instance of Typhoeus.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/noms/command/useragent/requester/typhoeus.rb', line 30 def initialize(opt={}) @log = opt[:logger] || default_logger @log.debug "Creating #{self.class} with options: #{opt.inspect}" @agent_name = "noms/#{NOMS::Command::VERSION} typhoeus/#{::Typhoeus::VERSION}" @auth = { } @client_opts = { :ssl_verifypeer => false } = opt.has_key?(:cookies) ? opt[:cookies] : true if = File.join(NOMS::Command.home, 'cookies.txt') @client_opts = @client_opts.merge({ :cookiefile => , :cookiejar => }) end end |
Instance Method Details
#get_auth(url) ⇒ Object
49 50 51 52 53 |
# File 'lib/noms/command/useragent/requester/typhoeus.rb', line 49 def get_auth(url) url = URI.parse(url) unless url.respond_to? :scheme domain = url.scheme + '://' + url.host + ':' + url.port.to_s + '/' @auth[domain] || { } end |
#request(opt = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/noms/command/useragent/requester/typhoeus.rb', line 55 def request(opt={}) url = opt[:url] spec = @client_opts.merge({ :method => opt[:method] || opt[:get], :headers => { 'User-Agent' => @agent_name }.merge(opt[:headers]), :body => opt[:body] }).merge(get_auth(url)) request = ::Typhoeus::Request.new(opt[:url], spec) response = request.run NOMS::Command::UserAgent::Response::Typhoeus.new(response) end |
#set_auth(domain, username, password) ⇒ Object
69 70 71 |
# File 'lib/noms/command/useragent/requester/typhoeus.rb', line 69 def set_auth(domain, username, password) @auth[domain] = { :userpwd => [username, password].join(':') } end |