Embiggen Versions Save

A Ruby library to expand shortened URLs

v1.4.0

6 years ago

v1.1.0

8 years ago
  • Extract the list of default shorteners into a separate text file, shorteners.txt and speed up identification of shortened links.

Thanks to @AvnerCohen for these contributions.

v1.0.0

8 years ago

Simplify Embiggen's API by exposing a single expand method (rather than two separate expand and expand! methods).

This means that Embiggen will no longer return sum types on expand (encapsulating errors and exceptions) but raise exceptions if any of the following situations occur:

  • Embiggen::TooManyRedirects: when a URI redirects more than the configured number of times;
  • Embiggen::BadShortenedURI: when a URI appears to be shortened but following it does not result in a valid redirect;
  • Embiggen::NetworkError: when an error occurs during expansion (e.g. a network timeout, connection reset, unreachable host, etc.).

All of the above inherit from Embiggen::Error and have a uri method for determining the problematic URI.

If you're upgrading from the 0.x line of Embiggen, this means you will now need to catch the above errors to preserve the same behaviour.

The other API change is in the list of shorteners used by Embiggen to determine whether to follow a link or not: Embiggen::Configuration.shorteners is now an object which has an include? method that takes a single URI and returns true if it is shortened.

By default, this object is an instance of Embiggen::ShortenerList and contains a set of domains and returns true on include? if a URI's host matches one of the set.

shorteners = Embiggen::ShortenerList.new(%w(bit.ly example.com))
shorteners.include?(URI('http://bit.ly/foo')) #=> true
shorteners.include?(URI('http://example.com/bar')) #=> true
shorteners.include?(URI('http://notashortener.com/baz')) #=> false

This means you can plug in your own implementations, e.g. to query Bitly's API or to expand all URIs regardless of domain.

Install the latest version from RubyGems like so:

$ gem install embiggen -v '~> 1.0'

Or, add to your Gemfile like so:

gem 'embiggen', '~> 1.0'