Class: Ethon::Easy
- Inherits:
-
Object
- Object
- Ethon::Easy
- Includes:
- Ethon::Easies::Callbacks, Ethon::Easies::Header, Ethon::Easies::Http, Ethon::Easies::Informations, Ethon::Easies::Operations, Ethon::Easies::Options, Ethon::Easies::ResponseCallbacks
- Defined in:
- lib/ethon/easy.rb
Overview
This is the class representing the libcurl easy interface See curl.haxx.se/libcurl/c/libcurl-easy.html for more informations.
Constant Summary
Constants included from Ethon::Easies::Informations
Ethon::Easies::Informations::AVAILABLE_INFORMATIONS
Instance Attribute Summary collapse
-
#return_code ⇒ Object
Returns the value of attribute return_code.
Class Method Summary collapse
-
.finalizer(easy) ⇒ Object
Free libcurl representation from an easy handle.
Instance Method Summary collapse
- #escape(value) ⇒ Object
-
#handle ⇒ FFI::Pointer
Returns a pointer to the curl easy handle.
-
#initialize(options = {}) ⇒ Easy
constructor
Initialize a new Easy.
-
#log_inspect ⇒ String
Return pretty log out.
-
#reset ⇒ Object
Reset easy.
-
#set_attributes(options) ⇒ Object
Set given options.
-
#to_hash ⇒ Hash
Returns the informations available through libcurl as a hash.
Methods included from Ethon::Easies::ResponseCallbacks
Methods included from Ethon::Easies::Operations
Methods included from Ethon::Easies::Http
Methods included from Ethon::Easies::Header
#compose_header, #header_list, #headers, #headers=, #set_headers
Methods included from Ethon::Easies::Options
included, #set_options, #value_for
Methods included from Ethon::Easies::Callbacks
#body_write_callback, #header_write_callback, included, #read_callback, #set_callbacks, #set_read_callback
Methods included from Ethon::Easies::Informations
Constructor Details
#initialize(options = {}) ⇒ Easy
Initialize a new Easy. It initializes curl, if not already done and applies the provided options.
145 146 147 148 149 |
# File 'lib/ethon/easy.rb', line 145 def initialize( = {}) Curl.init ObjectSpace.define_finalizer(self, self.class.finalizer(self)) set_attributes() end |
Instance Attribute Details
#return_code ⇒ Object
Returns the value of attribute return_code.
43 44 45 |
# File 'lib/ethon/easy.rb', line 43 def return_code @return_code end |
Class Method Details
Instance Method Details
#escape(value) ⇒ Object
182 183 184 |
# File 'lib/ethon/easy.rb', line 182 def escape(value) Curl.easy_escape(handle, value, 0) end |
#handle ⇒ FFI::Pointer
Returns a pointer to the curl easy handle.
192 193 194 |
# File 'lib/ethon/easy.rb', line 192 def handle @handle ||= Curl.easy_init end |
#log_inspect ⇒ String
Return pretty log out.
219 220 221 222 223 224 225 226 227 |
# File 'lib/ethon/easy.rb', line 219 def log_inspect hash = { :url => url, :response_code => response_code, :return_code => return_code, :total_time => total_time } "EASY #{hash.map{|k, v| "#{k}=#{v}"}.flatten.join(' ')}" end |
#reset ⇒ Object
Reset easy. This means resetting all options and instance variables. Also the easy handle is resetted.
175 176 177 178 179 180 |
# File 'lib/ethon/easy.rb', line 175 def reset (instance_variables - [:@handle, :@header_list]).each do |ivar| instance_variable_set(ivar, nil) end Curl.easy_reset(handle) end |
#set_attributes(options) ⇒ Object
Set given options.
161 162 163 164 165 166 167 168 |
# File 'lib/ethon/easy.rb', line 161 def set_attributes() .each_pair do |key, value| unless respond_to?("#{key}=") raise Errors::InvalidOption.new(key) end method("#{key}=").call(value) end end |
#to_hash ⇒ Hash
Returns the informations available through libcurl as a hash.
200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/ethon/easy.rb', line 200 def to_hash return @hash if defined?(@hash) && @hash @hash = { :return_code => return_code, :response_header => response_header, :response_body => response_body } Easies::Informations::AVAILABLE_INFORMATIONS.keys.each do |info| @hash[info] = method(info).call end @hash end |