Project

hwacha

0.01
No commit activity in last 3 years
No release in over 3 years
Harness the power of Typhoeus to quickly check webpage responses.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
>= 0

Runtime

 Project Readme

Hwacha Build Status Gem Version

Hwacha! Harness the power of Typhoeus to quickly check webpage responses.

Examples

Check a single page.

hwacha = Hwacha.new
hwacha.check('rakeroutes.com') do |url, response|
  if response.success?
    puts "Woo, #{url} looks good!"
  else
    puts "Aww, something that isn't success happened."
  end
end

Configure the maximum number of concurrent requests.

hwacha = Hwacha.new do |config|
  config.max_concurrent_requests = 10 # 20 is the default
end

# a legacy integer argument is also supported
hwacha = Hwacha.new(10)

Follow redirects!

hwacha = Hwacha.new do |config|
  config.follow_redirects = true
end

Check a bunch of pages! Hwacha!

hwacha = Hwacha.new
hwacha.check(array_of_webpage_urls) do |url, response|
  # each url is enqueued in parallel using the powerful Typhoeus library!
  # this block is yielded the url and response object for every response!
end

The yielded response object is straight from Typhoeus.

hwacha.check(array_of_webpage_urls) do |url, response|
  if response.success?
    # hwacha!
  elsif response.timed_out?
    # time makes fools of us all
  elsif response.code == 0
    # misfire!
  else
    # miss! :-(
    # something like 404 in response.code
  end
end

Sometimes you don't want to deal with the response object. Sometimes you just want to fire a bunch of requests and find pages that successfully respond. Ok!

hwacha = Hwacha.new

hwacha.find_existing(array_of_webpage_urls) do |url|
  # this block will be called for all urls that successfully respond!
  # hwacha!
end

Alternative API

More fun, more hwacha.

# fire is an alias for #check
hwacha.fire('rakeroutes.com') do |url, response|
  puts "Checking %s" % url
  if response.success?
    puts "success!"
  else
    puts "failed."
  end
end

# strike_true is an alias for #find_existing
successful = 0
hwacha.strike_true(unknown_pages) do |url|
  successful += 1
end
puts "Hwacha! #{successful} hits!"

# setting config.ricochet will also follow redirects
hwacha = Hwacha.new do |config|
  config.ricochet = true
end

Installation

Add this line to your application's Gemfile:

gem 'hwacha'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hwacha