Class: Ethon::Easy
- Inherits:
-
Object
- Object
- Ethon::Easy
- Includes:
- Callbacks, Header, Http, Informations, Operations, Options, ResponseCallbacks
- Defined in:
- lib/ethon/easy.rb,
lib/ethon/easy/form.rb,
lib/ethon/easy/http.rb,
lib/ethon/easy/util.rb,
lib/ethon/easy/header.rb,
lib/ethon/easy/params.rb,
lib/ethon/easy/options.rb,
lib/ethon/easy/http/get.rb,
lib/ethon/easy/http/put.rb,
lib/ethon/easy/callbacks.rb,
lib/ethon/easy/http/head.rb,
lib/ethon/easy/http/post.rb,
lib/ethon/easy/queryable.rb,
lib/ethon/easy/http/patch.rb,
lib/ethon/easy/operations.rb,
lib/ethon/easy/http/delete.rb,
lib/ethon/easy/http/options.rb,
lib/ethon/easy/http/putable.rb,
lib/ethon/easy/informations.rb,
lib/ethon/easy/http/postable.rb,
lib/ethon/easy/http/actionable.rb,
lib/ethon/easy/response_callbacks.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Callbacks, Header, Http, Informations, Operations, Options, Queryable, ResponseCallbacks, Util Classes: Form, Params
Constant Summary
Constants included from Informations
Informations::AVAILABLE_INFORMATIONS
Instance Attribute Summary collapse
-
#return_code ⇒ Symbol
Returns the curl return code.
Attributes included from Options
Class Method Summary collapse
-
.finalizer(easy) ⇒ Object
private
Frees libcurls easy represantation including its headers if any.
Instance Method Summary collapse
-
#escape(value) ⇒ String
private
Url escapes the value.
-
#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 ResponseCallbacks
Methods included from Operations
Methods included from Http
Methods included from Header
#compose_header, #header_list, #headers, #headers=
Methods included from Options
#accept_encoding=, #cainfo=, #capath=, #connecttimeout=, #connecttimeout_ms=, #copypostfields=, #customrequest=, #dns_cache_timeout=, #followlocation=, #forbid_reuse=, #httpauth=, #httpget=, #httppost=, #infilesize=, #interface=, #keypasswd=, #maxredirs=, #nobody=, #nosignal=, #postfieldsize=, #proxy=, #proxyauth=, #proxyport=, #proxytype=, #proxyuserpwd=, #readdata=, #readfunction=, #ssl_verifyhost=, #ssl_verifypeer=, #sslcert=, #sslcerttype=, #sslkey=, #sslkeytype=, #sslversion=, #timeout=, #timeout_ms=, #upload=, #useragent=, #userpwd=, #verbose=
Methods included from Callbacks
#body_write_callback, #header_write_callback, included, #read_callback, #set_callbacks, #set_read_callback
Methods included from Informations
Constructor Details
#initialize(options = {}) ⇒ Easy
Initialize a new Easy. It initializes curl, if not already done and applies the provided options. Look into Options to see what you can provide in the options hash.
234 235 236 237 238 239 |
# File 'lib/ethon/easy.rb', line 234 def initialize( = {}) Curl.init ObjectSpace.define_finalizer(self, self.class.finalizer(self)) set_attributes() set_callbacks end |
Instance Attribute Details
#return_code ⇒ Symbol
Returns the curl return code.
197 198 199 |
# File 'lib/ethon/easy.rb', line 197 def return_code @return_code end |
Class Method Details
.finalizer(easy) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Frees libcurls easy represantation including its headers if any.
211 212 213 214 215 216 |
# File 'lib/ethon/easy.rb', line 211 def finalizer(easy) proc { Curl.slist_free_all(easy.header_list) if easy.header_list Curl.easy_cleanup(easy.handle) } end |
Instance Method Details
#escape(value) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Url escapes the value.
282 283 284 |
# File 'lib/ethon/easy.rb', line 282 def escape(value) Curl.easy_escape(handle, value, 0) end |
#log_inspect ⇒ String
Return pretty log out.
309 310 311 312 313 314 315 316 317 |
# File 'lib/ethon/easy.rb', line 309 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.
265 266 267 268 269 270 |
# File 'lib/ethon/easy.rb', line 265 def reset @url = nil @hash = nil Curl.easy_reset(handle) set_callbacks end |
#set_attributes(options) ⇒ Object
Set given options.
251 252 253 254 255 256 257 258 |
# File 'lib/ethon/easy.rb', line 251 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.
290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/ethon/easy.rb', line 290 def to_hash return @hash if defined?(@hash) && @hash @hash = { :return_code => return_code, :response_headers => response_headers, :response_body => response_body } Easy::Informations::AVAILABLE_INFORMATIONS.keys.each do |info| @hash[info] = method(info).call end @hash end |