Class: Blinkr::TyphoeusWrapper
- Inherits:
-
Object
- Object
- Blinkr::TyphoeusWrapper
- Includes:
- HttpUtils
- Defined in:
- lib/blinkr/typhoeus_wrapper.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#hydra ⇒ Object
readonly
Returns the value of attribute hydra.
Instance Method Summary collapse
- #debug(url) ⇒ Object
-
#initialize(config, context) ⇒ TyphoeusWrapper
constructor
A new instance of TyphoeusWrapper.
- #name ⇒ Object
- #process(url, limit, opts = {}, &block) ⇒ Object
- #process_all(urls, limit, opts = {}, &block) ⇒ Object
Methods included from HttpUtils
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
#count ⇒ Object (readonly)
Returns the value of attribute count.
11 12 13 |
# File 'lib/blinkr/typhoeus_wrapper.rb', line 11 def count @count end |
#hydra ⇒ Object (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.[:method]}" puts "Max redirects: #{resp.request.[:maxredirs]}" puts "Follow location header: #{resp.request.[:followlocation]}" puts "Timeout (s): #{resp.request.[:timeout] || 'none'}" puts "Connection timeout (s): #{resp.request.[:connecttimeout] || 'none'}" puts "\nHeaders" puts "-------" unless resp.request.[:headers].nil? resp.request.[:headers].each do |name, value| puts "#{name}: #{value}" end end puts "\nResponse" puts "========" puts "Status Code: #{resp.code}" puts "Status Message: #{resp.}" puts "Message: #{resp.}" unless resp..nil? || resp. == 'No error' puts "\nHeaders" puts "-------" puts resp.response_headers end @hydra.run end |
#name ⇒ Object
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 |