Class: Hwacha
- Inherits:
-
Object
- Object
- Hwacha
- Defined in:
- lib/hwacha.rb,
lib/hwacha/config.rb,
lib/hwacha/version.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
- VERSION =
"1.0.2"
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #build_hydra ⇒ Object
- #check(urls) ⇒ Object (also: #fire)
- #find_existing(urls) ⇒ Object (also: #strike_true)
-
#initialize(max_concurrent_requests = 20) {|config| ... } ⇒ Hwacha
constructor
A new instance of Hwacha.
Constructor Details
#initialize(max_concurrent_requests = 20) {|config| ... } ⇒ Hwacha
Returns a new instance of Hwacha.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/hwacha.rb', line 8 def initialize(max_concurrent_requests=20) config = Hwacha::Config.new # support the simple legacy API config.max_concurrent_requests = max_concurrent_requests # the nice configuration object API yield config if block_given? @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/hwacha.rb', line 6 def config @config end |
Instance Method Details
#build_hydra ⇒ Object
44 45 46 |
# File 'lib/hwacha.rb', line 44 def build_hydra Typhoeus::Hydra.new(config.) end |
#check(urls) ⇒ Object Also known as: fire
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hwacha.rb', line 20 def check(urls) hydra = build_hydra Array(urls).each do |url| request = Typhoeus::Request.new(url, config.) request.on_complete do |response| yield response.effective_url, response end hydra.queue request end hydra.run end |
#find_existing(urls) ⇒ Object Also known as: strike_true
34 35 36 37 38 |
# File 'lib/hwacha.rb', line 34 def find_existing(urls) check(urls) do |url, response| yield url if response.success? end end |