Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Allows you to resolve redirecting urls (i.e. from url-shortening services like bit.ly) with Net::HTTP and find out their destination url as well as the body

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 redirect_follower.gemspec
README.rdoc

RedirectFollower

Allows you to resolve redirecting urls (i.e. from url-shortening services like bit.ly) and find out their destination url as well as the body.

The code is mostly ripped from John Nunemaker's blog post “Following Redirects with Net/HTTP” (railstips.org/blog/archives/2009/03/04/following-redirects-with-nethttp/), but wrapped into a Rubygem and with automatic resolving

Install with:

gem install redirect_follower

Then, either shorthand for the destination url only or for the full response:

$ irb
> require 'redirect_follower'
> RedirectFollower('http://is.gd/bNZYZ') # Just find out the destination url
=> 'http://www.taschen.com/pages/en/catalogue/classics/all/06724/facts.byrne_six_books_of_euclid.htm'

> redirect = RedirectFollower.new('http://is.gd/bNZYZ')
> redirect.url 
=> 'http://www.taschen.com/pages/en/catalogue/classics/all/06724/facts.byrne_six_books_of_euclid.htm'
> redirect.body
=> 'a load of html...'
> redirect.response.body 
=> 'a load of html...' # Same as redirect.body
> redirect.response
=> # Full response object from Net::HTTP

Limiting the amount of redirects can be achieved by giving a second parameter to either methods:

RedirectFollower('is.gd/bNZYZ', 2) will only follow two redirects before raising RedirectFollower::TooManyRedirects. Same thing for RedirectFollower.new('is.gd/bNZYZ', 2). The default amount of redirects is 5.

You can also check out my introductory blog post at colszowka.heroku.com/2010/04/30/redirectfollower-rubygem

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 Christoph Olszowka. See LICENSE for details.

Something went wrong with that request. Please try again.