Class: Typhoeus::EasyFactory Private

Inherits:
Object
  • Object
show all
Defined in:
lib/typhoeus/easy_factory.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This is a Factory for easies to be used in the hydra. Before an easy is ready to be added to a multi the on_complete callback to be set. This is done by this class.

Since:

  • 0.5.0

Constant Summary collapse

RENAMED_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

{
    :auth_method => :httpauth,
    :connect_timeout => :connecttimeout,
    :encoding => :accept_encoding,
    :follow_location => :followlocation,
    :max_redirects => :maxredirs,
    :proxy_type => :proxytype,
    :ssl_cacert => :cainfo,
    :ssl_capath => :capath,
    :ssl_cert => :sslcert,
    :ssl_cert_type => :sslcerttype,
    :ssl_key => :sslkey,
    :ssl_key_password => :keypasswd,
    :ssl_key_type => :sslkeytype,
    :ssl_version => :sslversion,
}
CHANGED_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

{
    :disable_ssl_host_verification => :ssl_verifyhost,
    :disable_ssl_peer_verification => :ssl_verifypeer,
    :proxy_auth_method => :proxyauth,
}
REMOVED_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

Set.new([:cache_key_basis, :cache_timeout, :user_agent])
SANITIZE_IGNORE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

Set.new([:method, :cache_ttl, :cache])
SANITIZE_TIMEOUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

Set.new([:timeout_ms, :connecttimeout_ms])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, hydra = nil) ⇒ EasyFactory

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.

Create an easy factory.

Examples:

Create easy factory.

Typhoeus::Hydra::EasyFactory.new(request, hydra)

Parameters:

  • request (Request)

    The request to build an easy for.

  • hydra (Hydra) (defaults to: nil)

    The hydra to build an easy for.

Since:

  • 0.5.0



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

def initialize(request, hydra = nil)
  @request = request
  @hydra = hydra
end

Instance Attribute Details

#hydraTyphoeus::Hydra (readonly)

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.

Returns the hydra provided.

Returns:

Since:

  • 0.5.0



49
50
51
# File 'lib/typhoeus/easy_factory.rb', line 49

def hydra
  @hydra
end

#requestTyphoeus::Request (readonly)

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.

Returns the request provided.

Returns:

Since:

  • 0.5.0



44
45
46
# File 'lib/typhoeus/easy_factory.rb', line 44

def request
  @request
end

Instance Method Details

#easyEthon::Easy

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.

Return the easy in question.

Examples:

Return easy.

easy_factory.easy

Returns:

  • (Ethon::Easy)

    The easy.

Since:

  • 0.5.0



69
70
71
# File 'lib/typhoeus/easy_factory.rb', line 69

def easy
  @easy ||= Typhoeus::Pool.get
end

#getEthon::Easy

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.

Fabricated easy.

Examples:

Prepared easy.

easy_factory.get

Returns:

  • (Ethon::Easy)

    The easy.

Since:

  • 0.5.0



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/typhoeus/easy_factory.rb', line 79

def get
  begin
    read_callback_body = request.options.delete(:set_read_callback)

    easy.http_request(
      request.base_url.to_s,
      request.options.fetch(:method, :get),
      sanitize(request.options)
    )

    # this needs to happen after http_request because
    # ethon will set infilesize to zero if form.empty?
    set_read_callback(read_callback_body) if !read_callback_body.nil?
  rescue Ethon::Errors::InvalidOption => e
    help = provide_help(e.message.match(/:\s(\w+)/)[1])
    raise $!, "#{$!}#{help}", $!.backtrace
  end
  set_callback
  easy
end