Class: Blinkr::TyphoeusWrapper

Inherits:
Object
  • Object
show all
Includes:
HttpUtils
Defined in:
lib/blinkr/typhoeus_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HttpUtils

#retry?, #sanitize

Constructor Details

#initialize(config, context) ⇒ TyphoeusWrapper

Returns a new instance of TyphoeusWrapper.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/blinkr/typhoeus_wrapper.rb', line 13

def initialize(config, context)
  @config = config.validate
  # Configure Typhoeus a bit
  Typhoeus::Config.verbose = true if config.vverbose
  Typhoeus::Config.cache = Blinkr::Cache.new
  @hydra = Typhoeus::Hydra.new(:maxconnects => (@config.maxconnects || 30),
                               :max_total_connections => (@config.maxconnects || 30),
                               :pipelining => false,
                               :max_concurrency => (@config.maxconnects || 30))
  Ethon.logger = Logger.new STDOUT if config.vverbose
  Ethon::Curl.set_option(:max_host_connections, 5, @hydra.multi.handle, :multi)
  @count = 0
  @context = context
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



11
12
13
# File 'lib/blinkr/typhoeus_wrapper.rb', line 11

def count
  @count
end

#hydraObject (readonly)

Returns the value of attribute hydra.



11
12
13
# File 'lib/blinkr/typhoeus_wrapper.rb', line 11

def hydra
  @hydra
end

Instance Method Details

#debug(url) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/blinkr/typhoeus_wrapper.rb', line 39

def debug(url)
  process(url, @config.max_retrys) do |resp|
    puts "\n++++++++++"
    puts "+ Blinkr +"
    puts "++++++++++"
    puts "\nRequest"
    puts "======="
    puts "Method: #{resp.request.options[:method]}"
    puts "Max redirects: #{resp.request.options[:maxredirs]}"
    puts "Follow location header: #{resp.request.options[:followlocation]}"
    puts "Timeout (s): #{resp.request.options[:timeout] || 'none'}"
    puts "Connection timeout (s): #{resp.request.options[:connecttimeout] || 'none'}"
    puts "\nHeaders"
    puts "-------"
    unless resp.request.options[:headers].nil?
      resp.request.options[:headers].each do |name, value|
        puts "#{name}: #{value}"
      end
    end
    puts "\nResponse"
    puts "========"
    puts "Status Code: #{resp.code}"
    puts "Status Message: #{resp.status_message}"
    puts "Message: #{resp.return_message}" unless resp.return_message.nil? || resp.return_message == 'No error'
    puts "\nHeaders"
    puts "-------"
    puts resp.response_headers
  end
  @hydra.run
end

#nameObject



70
71
72
# File 'lib/blinkr/typhoeus_wrapper.rb', line 70

def name
  'typhoeus'
end

#process(url, limit, opts = {}, &block) ⇒ Object



35
36
37
# File 'lib/blinkr/typhoeus_wrapper.rb', line 35

def process(url, limit, opts = {}, &block)
  _process url, limit, limit, opts, &block
end

#process_all(urls, limit, opts = {}, &block) ⇒ Object



28
29
30
31
32
33
# File 'lib/blinkr/typhoeus_wrapper.rb', line 28

def process_all(urls, limit, opts = {}, &block)
  urls.each do |url|
    process url, limit, opts, &block
  end
  @hydra.run
end