Object
# File lib/typhoeus/request.rb, line 159 159: def self.delete(url, params = {}) 160: run(url, params.merge(:method => :delete)) 161: end
# File lib/typhoeus/request.rb, line 147 147: def self.get(url, params = {}) 148: run(url, params.merge(:method => :get)) 149: end
# File lib/typhoeus/request.rb, line 163 163: def self.head(url, params = {}) 164: run(url, params.merge(:method => :head)) 165: end
Initialize a new Request
Options:
url : Endpoint (URL) of the request
options : A hash containing options among :
** :method : :get (default) / :post / :put ** :params : params as a Hash ** :body ** :timeout : timeout (ms) ** :connect_timeout : connect timeout (ms) ** :headers : headers as Hash ** :user_agent : user agent (string) ** :cache_timeout : cache timeout (ms) ** +:follow_location ** +:max_redirects ** +:proxy ** +:disable_ssl_peer_verification ** +:ssl_cert ** +:ssl_cert_type ** +:ssl_key ** +:ssl_key_type ** +:ssl_key_password ** +:ssl_cacert ** +:ssl_capath ** +:verbose ** +:username ** +:password ** +:auth_method
# File lib/typhoeus/request.rb, line 37 37: def initialize(url, options = {}) 38: @method = options[:method] || :get 39: @params = options[:params] 40: @body = options[:body] 41: @timeout = options[:timeout] 42: @connect_timeout = options[:connect_timeout] 43: @headers = options[:headers] || {} 44: @user_agent = options[:user_agent] || Typhoeus::USER_AGENT 45: @cache_timeout = options[:cache_timeout] 46: @follow_location = options[:follow_location] 47: @max_redirects = options[:max_redirects] 48: @proxy = options[:proxy] 49: @disable_ssl_peer_verification = options[:disable_ssl_peer_verification] 50: @ssl_cert = options[:ssl_cert] 51: @ssl_cert_type = options[:ssl_cert_type] 52: @ssl_key = options[:ssl_key] 53: @ssl_key_type = options[:ssl_key_type] 54: @ssl_key_password = options[:ssl_key_password] 55: @ssl_cacert = options[:ssl_cacert] 56: @ssl_capath = options[:ssl_capath] 57: @verbose = options[:verbose] 58: @username = options[:username] 59: @password = options[:password] 60: @auth_method = options[:auth_method] 61: 62: if @method == :post 63: @url = url 64: else 65: @url = @params ? "#{url}?#{params_string}" : url 66: end 67: @on_complete = nil 68: @after_complete = nil 69: @handled_response = nil 70: end
# File lib/typhoeus/request.rb, line 151 151: def self.post(url, params = {}) 152: run(url, params.merge(:method => :post)) 153: end
# File lib/typhoeus/request.rb, line 109 109: def after_complete(&block) 110: @after_complete = block 111: end
# File lib/typhoeus/request.rb, line 113 113: def after_complete=(proc) 114: @after_complete = proc 115: end
# File lib/typhoeus/request.rb, line 136 136: def cache_key 137: Digest::SHA1.hexdigest(url) 138: end
# File lib/typhoeus/request.rb, line 124 124: def call_after_complete 125: @after_complete.call(@handled_response) if @after_complete 126: end
# File lib/typhoeus/request.rb, line 117 117: def call_handlers 118: if @on_complete 119: @handled_response = @on_complete.call(response) 120: call_after_complete 121: end 122: end
# File lib/typhoeus/request.rb, line 132 132: def handled_response 133: @handled_response || response 134: end
# File lib/typhoeus/request.rb, line 128 128: def handled_response=(val) 129: @handled_response = val 130: end
# File lib/typhoeus/request.rb, line 82 82: def headers 83: @headers["User-Agent"] = @user_agent 84: @headers 85: end
# File lib/typhoeus/request.rb, line 72 72: def host 73: slash_location = @url.index('/', 8) 74: if slash_location 75: @url.slice(0, slash_location) 76: else 77: query_string_location = @url.index('?') 78: return query_string_location ? @url.slice(0, query_string_location) : @url 79: end 80: end
# File lib/typhoeus/request.rb, line 101 101: def on_complete(&block) 102: @on_complete = block 103: end
# File lib/typhoeus/request.rb, line 105 105: def on_complete=(proc) 106: @on_complete = proc 107: end
# File lib/typhoeus/request.rb, line 87 87: def params_string 88: params.keys.sort { |a, b| a.to_s <=> b.to_s }.collect do |k| 89: value = params[k] 90: if value.is_a? Hash 91: value.keys.collect {|sk| Rack::Utils.escape("#{k}[#{sk}]") + "=" + Rack::Utils.escape(value[sk].to_s)} 92: elsif value.is_a? Array 93: key = Rack::Utils.escape(k.to_s) 94: value.collect { |v| "#{key}=#{Rack::Utils.escape(v.to_s)}" }.join('&') 95: else 96: "#{Rack::Utils.escape(k.to_s)}=#{Rack::Utils.escape(params[k].to_s)}" 97: end 98: end.flatten.join("&") 99: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.