Parent

Typhoeus::Easy

Constants

AUTH_TYPES
CURLINFO_STRING

These integer codes are available in curl/curl.h

INFO_VALUES
OPTION_VALUES
PROXY_TYPES
SSL_VERSIONS

Attributes

curl_return_code[R]
headers[R]
method[R]
params[R]
response_body[R]
response_header[R]
ssl_version[R]
start_time[RW]
url[R]

Public Class Methods

new() click to toggle source
# File lib/typhoeus/easy.rb, line 88
def initialize
  @method = :get
  @headers = {}

  set_defaults
end

Public Instance Methods

app_connect_time() click to toggle source
# File lib/typhoeus/easy.rb, line 153
def app_connect_time
  get_info_double(INFO_VALUES[:CURLINFO_APPCONNECT_TIME])
end
auth=(authinfo) click to toggle source
# File lib/typhoeus/easy.rb, line 132
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
auth_methods() click to toggle source
# File lib/typhoeus/easy.rb, line 137
def auth_methods
  get_info_long(INFO_VALUES[:CURLINFO_HTTPAUTH_AVAIL])
end
connect_time() click to toggle source
# File lib/typhoeus/easy.rb, line 161
def connect_time
  get_info_double(INFO_VALUES[:CURLINFO_CONNECT_TIME])
end
connect_timeout=(milliseconds) click to toggle source
# File lib/typhoeus/easy.rb, line 193
def connect_timeout=(milliseconds)
  @connect_timeout = milliseconds
  set_option(OPTION_VALUES[:CURLOPT_NOSIGNAL], 1)
  set_option(OPTION_VALUES[:CURLOPT_CONNECTTIMEOUT_MS], milliseconds)
end
curl_version() click to toggle source
# File lib/typhoeus/easy.rb, line 408
def curl_version
  version
end
disable_ssl_host_verification() click to toggle source
# File lib/typhoeus/easy.rb, line 235
def disable_ssl_host_verification
  set_option(OPTION_VALUES[:CURLOPT_VERIFYHOST], 0)
end
disable_ssl_peer_verification() click to toggle source
# File lib/typhoeus/easy.rb, line 231
def disable_ssl_peer_verification
  set_option(OPTION_VALUES[:CURLOPT_VERIFYPEER], 0)
end
effective_url() click to toggle source
# File lib/typhoeus/easy.rb, line 169
def effective_url
  get_info_string(INFO_VALUES[:CURLINFO_EFFECTIVE_URL])
end
encoding=(encoding) click to toggle source
# File lib/typhoeus/easy.rb, line 101
def encoding=(encoding)
  # Enable encoding/compression support
  set_option(OPTION_VALUES[:CURLOPT_ENCODING], encoding)
end
failure() click to toggle source

gets called when finished and response code is 300-599 or curl returns an error code

# File lib/typhoeus/easy.rb, line 375
def failure
  @failure.call(self) if @failure
end
follow_location=(boolean) click to toggle source
# File lib/typhoeus/easy.rb, line 181
def follow_location=(boolean)
  if boolean
    set_option(OPTION_VALUES[:CURLOPT_FOLLOWLOCATION], 1)
  else
    set_option(OPTION_VALUES[:CURLOPT_FOLLOWLOCATION], 0)
  end
end
get_info_double(option) click to toggle source
# File lib/typhoeus/easy.rb, line 404
def get_info_double(option)
  easy_getinfo_double(option)
end
get_info_long(option) click to toggle source
# File lib/typhoeus/easy.rb, line 400
def get_info_long(option)
  easy_getinfo_long(option)
end
get_info_string(option) click to toggle source
# File lib/typhoeus/easy.rb, line 396
def get_info_string(option)
  easy_getinfo_string(option)
end
headers=(hash) click to toggle source
# File lib/typhoeus/easy.rb, line 113
def headers=(hash)
  @headers = hash
end
interface=(interface) click to toggle source
# File lib/typhoeus/easy.rb, line 117
def interface=(interface)
  @interface = interface
  set_option(OPTION_VALUES[:CURLOPT_INTERFACE], interface)
end
max_redirects=(redirects) click to toggle source
# File lib/typhoeus/easy.rb, line 189
def max_redirects=(redirects)
  set_option(OPTION_VALUES[:CURLOPT_MAXREDIRS], redirects)
end
method=(method) click to toggle source
# File lib/typhoeus/easy.rb, line 239
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 = @request_body.to_s
  elsif method == :head
    set_option(OPTION_VALUES[:CURLOPT_NOBODY], 1)
  else
    set_option(OPTION_VALUES[:CURLOPT_CUSTOMREQUEST], method.to_s.upcase)
  end
end
name_lookup_time() click to toggle source
# File lib/typhoeus/easy.rb, line 165
def name_lookup_time
  get_info_double(INFO_VALUES[:CURLINFO_NAMELOOKUP_TIME])
end
on_failure(&block) click to toggle source
# File lib/typhoeus/easy.rb, line 379
def on_failure(&block)
  @failure = block
end
on_failure=(block) click to toggle source
# File lib/typhoeus/easy.rb, line 383
def on_failure=(block)
  @failure = block
end
on_success(&block) click to toggle source
# File lib/typhoeus/easy.rb, line 365
def on_success(&block)
  @success = block
end
on_success=(block) click to toggle source
# File lib/typhoeus/easy.rb, line 369
def on_success=(block)
  @success = block
end
params=(params) click to toggle source
# File lib/typhoeus/easy.rb, line 266
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
perform() click to toggle source
# File lib/typhoeus/easy.rb, line 340
def perform
  set_headers()
  easy_perform()
  resp_code = response_code()
  if resp_code >= 200 && resp_code <= 299
    success
  else
    failure
  end
  resp_code
end
post_data=(data) click to toggle source
# File lib/typhoeus/easy.rb, line 256
def post_data=(data)
  @post_data_set = true
  set_option(OPTION_VALUES[:CURLOPT_POSTFIELDSIZE], data.bytesize)
  set_option(OPTION_VALUES[:CURLOPT_COPYPOSTFIELDS], data)
end
pretransfer_time() click to toggle source
# File lib/typhoeus/easy.rb, line 157
def pretransfer_time
  get_info_double(INFO_VALUES[:CURLINFO_PRETRANSFER_TIME])
end
primary_ip() click to toggle source
# File lib/typhoeus/easy.rb, line 173
def primary_ip
  get_info_string(INFO_VALUES[:CURLINFO_PRIMARY_IP])
end
proxy=(proxy) click to toggle source
# File lib/typhoeus/easy.rb, line 122
def proxy=(proxy)
  set_option(OPTION_VALUES[:CURLOPT_PROXY], proxy[:server])
  set_option(OPTION_VALUES[:CURLOPT_PROXYTYPE], proxy[:type]) if proxy[:type]
end
proxy_auth=(authinfo) click to toggle source
# File lib/typhoeus/easy.rb, line 127
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
request_body=(request_body) click to toggle source
# File lib/typhoeus/easy.rb, line 213
def request_body=(request_body)
  @request_body = request_body
  if @method == :put
    easy_set_request_body(@request_body.to_s)
  else
    self.post_data = request_body
  end
end
reset() click to toggle source
# File lib/typhoeus/easy.rb, line 387
def reset
  @response_code = 0
  @response_header = ""
  @response_body = ""
  @request_body = ""
  easy_reset()
  set_defaults
end
response_code() click to toggle source
# File lib/typhoeus/easy.rb, line 177
def response_code
  get_info_long(INFO_VALUES[:CURLINFO_RESPONSE_CODE])
end
set_defaults() click to toggle source
# File lib/typhoeus/easy.rb, line 95
def set_defaults
  # Enable encoding/compression support
  self.encoding = ''
  self.ssl_version = :default
end
set_headers() click to toggle source
# File lib/typhoeus/easy.rb, line 352
def set_headers
  headers.each_pair do |key, value|
    easy_add_header("#{key}: #{value}")
  end
  easy_set_headers() unless headers.empty?
end
set_option(option, value) click to toggle source
# File lib/typhoeus/easy.rb, line 329
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
ssl_cacert=(cacert) click to toggle source

Set SSL CACERT " File holding one or more certificates to verify the peer with. "

# File lib/typhoeus/easy.rb, line 318
def ssl_cacert=(cacert)
  set_option(OPTION_VALUES[:CURLOPT_CAINFO], cacert)
end
ssl_capath=(capath) click to toggle source

Set CAPATH " directory holding multiple CA certificates to verify the peer with. The certificate directory must be prepared using the openssl c_rehash utility. "

# File lib/typhoeus/easy.rb, line 325
def ssl_capath=(capath)
  set_option(OPTION_VALUES[:CURLOPT_CAPATH], capath)
end
ssl_cert=(cert) click to toggle source

Set SSL certificate " The string should be the file name of your certificate. " The default format is "PEM" and can be changed with ssl_cert_type=

# File lib/typhoeus/easy.rb, line 284
def ssl_cert=(cert)
  set_option(OPTION_VALUES[:CURLOPT_SSLCERT], cert)
end
ssl_cert_type=(cert_type) click to toggle source

Set SSL certificate type " The string should be the format of your certificate. Supported formats are "PEM" and "DER" "

# File lib/typhoeus/easy.rb, line 290
def ssl_cert_type=(cert_type)
  raise "Invalid ssl cert type : '#{cert_type}'..." if cert_type and !%(PEM DER p12).include?(cert_type)
  set_option(OPTION_VALUES[:CURLOPT_SSLCERTTYPE], cert_type)
end
ssl_key=(key) click to toggle source

Set SSL Key file " The string should be the file name of your private key. " The default format is "PEM" and can be changed with ssl_key_type=

# File lib/typhoeus/easy.rb, line 299
def ssl_key=(key)
  set_option(OPTION_VALUES[:CURLOPT_SSLKEY], key)
end
ssl_key_password=(key_password) click to toggle source
# File lib/typhoeus/easy.rb, line 311
def ssl_key_password=(key_password)
  set_option(OPTION_VALUES[:CURLOPT_KEYPASSWD], key_password)
end
ssl_key_type=(key_type) click to toggle source

Set SSL Key type " The string should be the format of your private key. Supported formats are "PEM", "DER" and "ENG". "

# File lib/typhoeus/easy.rb, line 306
def ssl_key_type=(key_type)
  raise "Invalid ssl key type : '#{key_type}'..." if key_type and !%(PEM DER ENG).include?(key_type)
  set_option(OPTION_VALUES[:CURLOPT_SSLKEYTYPE], key_type)
end
ssl_version=(version) click to toggle source
# File lib/typhoeus/easy.rb, line 106
def ssl_version=(version)
  raise "Invalid SSL version: '#{version}' supplied! Please supply one as listed in Typhoeus::Easy::SSL_VERSIONS" unless SSL_VERSIONS.has_key?(version)
  @ssl_version = version

  set_option(OPTION_VALUES[:CURLOPT_SSLVERSION], SSL_VERSIONS[version])
end
start_transfer_time() click to toggle source
# File lib/typhoeus/easy.rb, line 149
def start_transfer_time
  get_info_double(INFO_VALUES[:CURLINFO_STARTTRANSFER_TIME])
end
success() click to toggle source

gets called when finished and response code is not 2xx, or curl returns an error code.

# File lib/typhoeus/easy.rb, line 361
def success
  @success.call(self) if @success
end
supports_zlib?() click to toggle source
# File lib/typhoeus/easy.rb, line 209
def supports_zlib?
  !!(curl_version.match(/zlib/))
end
timed_out?() click to toggle source
# File lib/typhoeus/easy.rb, line 205
def timed_out?
  curl_return_code == 28
end
timeout=(milliseconds) click to toggle source
# File lib/typhoeus/easy.rb, line 199
def timeout=(milliseconds)
  @timeout = milliseconds
  set_option(OPTION_VALUES[:CURLOPT_NOSIGNAL], 1)
  set_option(OPTION_VALUES[:CURLOPT_TIMEOUT_MS], milliseconds)
end
total_time_taken() click to toggle source
# File lib/typhoeus/easy.rb, line 145
def total_time_taken
  get_info_double(INFO_VALUES[:CURLINFO_TOTAL_TIME])
end
url=(url) click to toggle source
# File lib/typhoeus/easy.rb, line 226
def url=(url)
  @url = url
  set_option(OPTION_VALUES[:CURLOPT_URL], url)
end
user_agent=(user_agent) click to toggle source
# File lib/typhoeus/easy.rb, line 222
def user_agent=(user_agent)
  set_option(OPTION_VALUES[:CURLOPT_USERAGENT], user_agent)
end
verbose=(boolean) click to toggle source
# File lib/typhoeus/easy.rb, line 141
def verbose=(boolean)
  set_option(OPTION_VALUES[:CURLOPT_VERBOSE], !!boolean ? 1 : 0)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.