class Typhoeus::Easy
def app_connect_time
def app_connect_time get_info_double(INFO_VALUES[:CURLINFO_APPCONNECT_TIME]) end
def auth=(authinfo)
def auth=(authinfo) set_option(OPTION_VALUES[:CURLOPT_USERPWD], "#{authinfo[:username]}:#{authinfo[:password]}") set_option(OPTION_VALUES[:CURLOPT_HTTPAUTH], authinfo[:method]) if authinfo[:method] end
def auth_methods
def auth_methods get_info_long(INFO_VALUES[:CURLINFO_HTTPAUTH_AVAIL]) end
def connect_time
def connect_time get_info_double(INFO_VALUES[:CURLINFO_CONNECT_TIME]) end
def connect_timeout=(milliseconds)
def connect_timeout=(milliseconds) @connect_timeout = milliseconds set_option(OPTION_VALUES[:CURLOPT_NOSIGNAL], 1) set_option(OPTION_VALUES[:CURLOPT_CONNECTTIMEOUT_MS], milliseconds) end
def curl_version
def curl_version version end
def disable_ssl_peer_verification
def disable_ssl_peer_verification set_option(OPTION_VALUES[:CURLOPT_VERIFYPEER], 0) end
def effective_url
def effective_url get_info_string(INFO_VALUES[:CURLINFO_EFFECTIVE_URL]) end
def failure
def failure @failure.call(self) if @failure end
def follow_location=(boolean)
def follow_location=(boolean) if boolean set_option(OPTION_VALUES[:CURLOPT_FOLLOWLOCATION], 1) else set_option(OPTION_VALUES[:CURLOPT_FOLLOWLOCATION], 0) end end
def get_info_double(option)
def get_info_double(option) easy_getinfo_double(option) end
def get_info_long(option)
def get_info_long(option) easy_getinfo_long(option) end
def get_info_string(option)
def get_info_string(option) easy_getinfo_string(option) end
def headers=(hash)
def headers=(hash) @headers = hash end
def initialize
def initialize @method = :get @headers = {} # Enable encoding/compression support set_option(OPTION_VALUES[:CURLOPT_ENCODING], '') end
def max_redirects=(redirects)
def max_redirects=(redirects) set_option(OPTION_VALUES[:CURLOPT_MAXREDIRS], redirects) end
def method=(method)
def method=(method) @method = method if method == :get set_option(OPTION_VALUES[:CURLOPT_HTTPGET], 1) elsif method == :post set_option(OPTION_VALUES[:CURLOPT_HTTPPOST], 1) self.post_data = "" elsif method == :put set_option(OPTION_VALUES[:CURLOPT_UPLOAD], 1) self.request_body = "" unless @request_body elsif method == :head set_option(OPTION_VALUES[:CURLOPT_NOBODY], 1) else set_option(OPTION_VALUES[:CURLOPT_CUSTOMREQUEST], method.to_s.upcase) end end
def name_lookup_time
def name_lookup_time get_info_double(INFO_VALUES[:CURLINFO_NAMELOOKUP_TIME]) end
def on_failure(&block)
def on_failure(&block) @failure = block end
def on_failure=(block)
def on_failure=(block) @failure = block end
def on_success(&block)
def on_success(&block) @success = block end
def on_success=(block)
def on_success=(block) @success = block end
def params
def params @form.nil? ? {} : @form.params end
def params=(params)
def params=(params) @form = Typhoeus::Form.new(params) if method == :post @form.process! if @form.multipart? set_option(OPTION_VALUES[:CURLOPT_HTTPPOST], @form) else self.post_data = @form.to_s end else self.url = "#{url}?#{@form.to_s}" end end
def perform
def perform set_headers() easy_perform() resp_code = response_code() if resp_code >= 200 && resp_code <= 299 success else failure end resp_code end
def post_data=(data)
def post_data=(data) @post_data_set = true set_option(OPTION_VALUES[:CURLOPT_POSTFIELDSIZE], data.length) set_option(OPTION_VALUES[:CURLOPT_COPYPOSTFIELDS], data) end
def pretransfer_time
def pretransfer_time get_info_double(INFO_VALUES[:CURLINFO_PRETRANSFER_TIME]) end
def proxy=(proxy)
def proxy=(proxy) set_option(OPTION_VALUES[:CURLOPT_PROXY], proxy[:server]) set_option(OPTION_VALUES[:CURLOPT_PROXYTYPE], proxy[:type]) if proxy[:type] end
def proxy_auth=(authinfo)
def proxy_auth=(authinfo) set_option(OPTION_VALUES[:CURLOPT_PROXYUSERPWD], "#{authinfo[:username]}:#{authinfo[:password]}") set_option(OPTION_VALUES[:CURLOPT_PROXYAUTH], authinfo[:method]) if authinfo[:method] end
def request_body=(request_body)
def request_body=(request_body) @request_body = request_body if @method == :put easy_set_request_body(@request_body) headers["Transfer-Encoding"] = "" headers["Expect"] = "" else self.post_data = request_body end end
def reset
def reset @response_code = 0 @response_header = "" @response_body = "" easy_reset() end
def response_code
def response_code get_info_long(INFO_VALUES[:CURLINFO_RESPONSE_CODE]) end
def set_headers
def set_headers headers.each_pair do |key, value| easy_add_header("#{key}: #{value}") end easy_set_headers() unless headers.empty? end
def set_option(option, value)
def set_option(option, value) case value when String easy_setopt_string(option, value) when Typhoeus::Form easy_setopt_form(option, value) else easy_setopt_long(option, value) if value end end
def ssl_cacert=(cacert)
" File holding one or more certificates to verify the peer with. "
Set SSL CACERT
def ssl_cacert=(cacert) set_option(OPTION_VALUES[:CURLOPT_CAINFO], cacert) end
def ssl_capath=(capath)
" directory holding multiple CA certificates to verify the peer with. The certificate directory must be prepared using the openssl c_rehash utility. "
Set CAPATH
def ssl_capath=(capath) set_option(OPTION_VALUES[:CURLOPT_CAPATH], capath) end
def ssl_cert=(cert)
" The string should be the file name of your certificate. "
Set SSL certificate
def ssl_cert=(cert) set_option(OPTION_VALUES[:CURLOPT_SSLCERT], cert) end
def ssl_cert_type=(cert_type)
Set SSL certificate type
def ssl_cert_type=(cert_type) raise "Invalid ssl cert type : '#{cert_type}'..." if cert_type and !%w(PEM DER).include?(cert_type) set_option(OPTION_VALUES[:CURLOPT_SSLCERTTYPE], cert_type) end
def ssl_key=(key)
The default format is "PEM" and can be changed with ssl_key_type=
" The string should be the file name of your private key. "
Set SSL Key file
def ssl_key=(key) set_option(OPTION_VALUES[:CURLOPT_SSLKEY], key) end
def ssl_key_password=(key_password)
def ssl_key_password=(key_password) set_option(OPTION_VALUES[:CURLOPT_KEYPASSWD], key_password) end
def ssl_key_type=(key_type)
" The string should be the format of your private key. Supported formats are "PEM", "DER" and "ENG". "
Set SSL Key type
def ssl_key_type=(key_type) raise "Invalid ssl key type : '#{key_type}'..." if key_type and !%w(PEM DER ENG).include?(key_type) set_option(OPTION_VALUES[:CURLOPT_SSLKEYTYPE], key_type) end
def start_transfer_time
def start_transfer_time get_info_double(INFO_VALUES[:CURLINFO_STARTTRANSFER_TIME]) end
def success
def success @success.call(self) if @success end
def supports_zlib?
def supports_zlib? !!(curl_version.match(/zlib/)) end
def timed_out?
def timed_out? curl_return_code == 28 end
def timeout=(milliseconds)
def timeout=(milliseconds) @timeout = milliseconds set_option(OPTION_VALUES[:CURLOPT_NOSIGNAL], 1) set_option(OPTION_VALUES[:CURLOPT_TIMEOUT_MS], milliseconds) end
def total_time_taken
def total_time_taken get_info_double(INFO_VALUES[:CURLINFO_TOTAL_TIME]) end
def url=(url)
def url=(url) @url = url set_option(OPTION_VALUES[:CURLOPT_URL], url) end
def user_agent=(user_agent)
def user_agent=(user_agent) set_option(OPTION_VALUES[:CURLOPT_USERAGENT], user_agent) end
def verbose=(boolean)
def verbose=(boolean) set_option(OPTION_VALUES[:CURLOPT_VERBOSE], !!boolean ? 1 : 0) end