Module: Typhoeus

Defined in:
lib/typhoeus.rb,
lib/typhoeus/easy.rb,
lib/typhoeus/hydra.rb,
lib/typhoeus/multi.rb,
lib/typhoeus/filter.rb,
lib/typhoeus/remote.rb,
lib/typhoeus/request.rb,
lib/typhoeus/response.rb,
lib/typhoeus/remote_method.rb,
lib/typhoeus/remote_proxy_object.rb

Defined Under Namespace

Modules: ClassMethods Classes: Easy, Filter, Hydra, HydraMock, MockExpectedError, Multi, RemoteMethod, RemoteProxyObject, Request, Response

Constant Summary collapse

VERSION =
"0.1.14"
USER_AGENT =
"Typhoeus - http://github.com/pauldix/typhoeus/tree/master"

Class Method Summary collapse

Class Method Details

.add_easy_request(easy_object) ⇒ Object



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

def self.add_easy_request(easy_object)
  Thread.current[:curl_multi] ||= Typhoeus::Multi.new
  Thread.current[:curl_multi].add(easy_object)
end

.easy_object_poolObject



19
20
21
# File 'lib/typhoeus.rb', line 19

def self.easy_object_pool
  @easy_objects ||= []
end

.get_easy_objectObject



34
35
36
37
38
39
40
# File 'lib/typhoeus.rb', line 34

def self.get_easy_object
  if easy_object_pool.empty?
    Typhoeus::Easy.new
  else
    easy_object_pool.pop
  end
end

.included(base) ⇒ Object



4
5
6
# File 'lib/typhoeus/remote.rb', line 4

def self.included(base)
  base.extend ClassMethods
end

.init_easy_object_poolObject



23
24
25
26
27
# File 'lib/typhoeus.rb', line 23

def self.init_easy_object_pool
  20.times do
    easy_object_pool << Typhoeus::Easy.new
  end
end

.perform_easy_requestsObject



47
48
49
50
51
52
53
54
# File 'lib/typhoeus.rb', line 47

def self.perform_easy_requests
  multi = Thread.current[:curl_multi]
  start_time = Time.now
  multi.easy_handles.each do |easy|
    easy.start_time = start_time
  end
  multi.perform
end

.release_easy_object(easy) ⇒ Object



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

def self.release_easy_object(easy)
  easy.reset
  easy_object_pool << easy
end