Hwacha! Harness the power of Typhoeus to quickly check webpage responses.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.gitignore
.ruby-version
.travis.yml
Gemfile
Gemfile.lock
LICENSE
README.md
Rakefile
hwacha.gemspec Add integration specs that test actual web visits Jan 13, 2014

README.md

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