Class: Typhoeus::Easy

Constant Summary collapse

OPTION_VALUES =
Curl::Option.to_hash.dup
INFO_VALUES =
Curl::Info.to_hash.dup
AUTH_TYPES =
Curl::Auth.to_hash.dup
PROXY_TYPES =
Curl::Proxy.to_hash.dup
SSL_VERSIONS =
Curl::SSLVersion.to_hash.dup

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Typhoeus::EasyFu::Infos

#app_connect_time, #auth_methods, #connect_time, #curl_error_message, #curl_return_code, #curl_version, #effective_url, #get_info_double, #get_info_long, #get_info_string, #name_lookup_time, #pretransfer_time, #primary_ip, #redirect_count, #response_code, #start_transfer_time, #supports_zlib?, #timed_out?, #total_time_taken

Methods included from Typhoeus::EasyFu::Callbacks

#failure, #on_failure, #on_failure=, #on_success, #on_success=, #success

Methods included from Typhoeus::EasyFu::Proxy

#proxy=, #proxy_auth=, #proxy_credentials

Methods included from Typhoeus::EasyFu::Auth

#auth=, #auth_credentials

Methods included from Typhoeus::EasyFu::SSL

#disable_ssl_host_verification, #disable_ssl_peer_verification, included, #ssl_cacert=, #ssl_capath=, #ssl_cert=, #ssl_cert_type=, #ssl_key=, #ssl_key_password=, #ssl_key_type=, #ssl_version, #ssl_version=

Methods included from Typhoeus::EasyFu::Options

#connect_timeout=, #encoding=, #follow_location=, #header_function=, #interface=, #max_redirects=, #method=, #post_data=, #request_body=, #set_headers, #set_option, #timeout=, #url=, #user_agent=, #verbose=, #write_function=

Methods included from Typhoeus::EasyFu::FFIHelper

#body_write_callback, #double_ptr, #handle, #header_write_callback, included, #long_ptr, #read_callback, #string_ptr

Constructor Details

#initializeEasy

Returns a new instance of Easy.



33
34
35
36
37
# File 'lib/typhoeus/easy.rb', line 33

def initialize
  Curl.init
  reset(true)
  ObjectSpace.define_finalizer(self, self.class.finalizer(self))
end

Instance Attribute Details

#header_listObject (readonly)

Returns the value of attribute header_list.



30
31
32
# File 'lib/typhoeus/easy.rb', line 30

def header_list
  @header_list
end

#start_timeObject

Returns the value of attribute start_time.



31
32
33
# File 'lib/typhoeus/easy.rb', line 31

def start_time
  @start_time
end

#urlObject (readonly)

Returns the value of attribute url.



30
31
32
# File 'lib/typhoeus/easy.rb', line 30

def url
  @url
end

Instance Method Details

#curl_return_code=(code) ⇒ Object



111
112
113
# File 'lib/typhoeus/easy.rb', line 111

def curl_return_code=(code)
  @curl_return_code = (code.class == Symbol ? code : Curl::EasyCode[code])
end

#headersObject



43
44
45
# File 'lib/typhoeus/easy.rb', line 43

def headers
  @headers ||= {}
end

#headers=(hash) ⇒ Object



55
56
57
# File 'lib/typhoeus/easy.rb', line 55

def headers=(hash)
  @headers = hash
end

#methodObject



39
40
41
# File 'lib/typhoeus/easy.rb', line 39

def method
  @method ||= :get
end

#paramsObject



59
60
61
# File 'lib/typhoeus/easy.rb', line 59

def params
  @form.nil? ? {} : @form.params
end

#params=(params) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/typhoeus/easy.rb', line 63

def params=(params)
  @form = Typhoeus::Form.new(params)

  if method == :post
    @form.process!
    if @form.multipart?
      set_option(:httppost, @form)
    else
      self.post_data = @form.to_s
    end
  else
    self.url = "#{url}?#{@form.to_s}"
  end
end

#performObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/typhoeus/easy.rb', line 78

def perform
  set_headers()
  @curl_return_code = Curl.easy_perform(handle)
  resp_code = response_code()
  if resp_code >= 200 && resp_code <= 299
    success
  else
    failure
  end
  resp_code
end

#reset(fresh = nil) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/typhoeus/easy.rb', line 90

def reset(fresh = nil)
  unless fresh
    @response_code = 0
    @response_header = ""
    @response_body = ""
    @request_body = ""

    if @header_list
      Curl.slist_free_all(@header_list)
      @header_list = nil
    end

    Curl.easy_reset(handle)
  end

  self.write_function = body_write_callback
  self.header_function = header_write_callback
  self.encoding = ''
  self.ssl_version = :default
end

#response_bodyObject



47
48
49
# File 'lib/typhoeus/easy.rb', line 47

def response_body
  @response_body ||= ""
end

#response_headerObject



51
52
53
# File 'lib/typhoeus/easy.rb', line 51

def response_header
  @response_header ||= ""
end