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
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/blinkr/typhoeus_wrapper.rb', line 11 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), :max_concurrency => (@config.maxconnects || 30)) @count = 0 @context = context end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
9 10 11 |
# File 'lib/blinkr/typhoeus_wrapper.rb', line 9 def count @count end |
#hydra ⇒ Object (readonly)
Returns the value of attribute hydra.
9 10 11 |
# File 'lib/blinkr/typhoeus_wrapper.rb', line 9 def hydra @hydra end |
Instance Method Details
#debug(url) ⇒ Object
34 35 36 37 38 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 |
# File 'lib/blinkr/typhoeus_wrapper.rb', line 34 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.[: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.status_message}" puts "Message: #{resp.return_message}" unless resp..nil? || resp. == 'No error' puts "\nHeaders" puts "-------" puts resp.response_headers end @hydra.run end |
#name ⇒ Object
65 66 67 |
# File 'lib/blinkr/typhoeus_wrapper.rb', line 65 def name 'typhoeus' end |
#process(url, limit, opts = {}, &block) ⇒ Object
30 31 32 |
# File 'lib/blinkr/typhoeus_wrapper.rb', line 30 def process(url, limit, opts = {}, &block) _process url, limit, limit, opts, &block end |
#process_all(urls, limit, opts = {}, &block) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/blinkr/typhoeus_wrapper.rb', line 23 def process_all(urls, limit, opts = {}, &block) urls.each do |url| process url, limit, opts, &block end @hydra.run end |