net_helper

Provides a wrapper around HTTP GET requests. Uses Net::HTTP (under RestClient) by default, but will use Typhoeus if available Will return the raw body (unparsed) for each request.

Usage

Rails2

gem.config 'itrigga-net_helper', :lib => 'net_helper'

Rails3 (bundler)

gem 'itrigga-net_helper', :require => 'net_helper'

Basic example

Itrigga::NetHelper.get :url => "http://www.google.com"

Adding params

Itrigga::NetHelper.get :url => "http://www.google.com", :params => {:p1 => "123"}

Gives url www.google.com?p1=123

Variables

timeout - in seconds (default 5) retries_on_timeout - how many times to try again (default 5) max_redirects - number of redirects to follow (default 3)

The SystemTimer gem will be used for timeout is available.

Itrigga::NetHelper.get :url => "http://www.google.com", :timeout => 300, :max_redirects => 1

Using Typhoeus

The Typhoeus gem needs to be installed (see github.com/dbalatero/typhoeus) Rails2 - gem.config ‘typhoeus’ Rails3 - gem ‘typhoeus’

To enable for all requests set the constant ITNH_HTTP_ENGINE = “Typhoeus” To use on a per request basis

Itrigga::NetHelper.get :url => "http://www.google.com", :http_engine => "Typhoeus"

Contributing to net_helper

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2011 Al Davidson. See LICENSE.txt for further details.