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
-
#handle ⇒ FFI::Pointer
Returns a pointer to the curl easy handle.
-
#initialize(options = {}) ⇒ Easy
constructor
Initialize a new Easy.
-
#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.
143 144 145 146 147 |
# File 'lib/ethon/easy.rb', line 143 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
#handle ⇒ FFI::Pointer
Returns a pointer to the curl easy handle.
186 187 188 |
# File 'lib/ethon/easy.rb', line 186 def handle @handle ||= Curl.easy_init end |
#reset ⇒ Object
Reset easy. This means resetting all options and instance variables. Also the easy handle is resetted.
173 174 175 176 177 178 |
# File 'lib/ethon/easy.rb', line 173 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.
159 160 161 162 163 164 165 166 |
# File 'lib/ethon/easy.rb', line 159 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.
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/ethon/easy.rb', line 194 def to_hash hash = {} hash[:return_code] = return_code hash[:response_header] = response_header hash[:response_body] = response_body Easies::Informations::AVAILABLE_INFORMATIONS.keys.each do |info| hash[info] = method(info).call end hash end |