Module: EventMachine::ShortURL

Defined in:
lib/em-shorturl.rb,
lib/em-shorturl/bitly.rb,
lib/em-shorturl/google.rb,
lib/em-shorturl/tinyurl.rb,
lib/em-shorturl/version.rb

Overview

The ShortURL module for EventMachine adds an asynchronous interface to shortening urls using several publically available URL shortening services. Several drivers may be provided, and the top level module provides a uniform and easy interface to using any of these services.

Defined Under Namespace

Classes: Bitly, Google, TinyURL

Constant Summary collapse

DEFAULT_DRIVER =
:google
DRIVERS =
{
    :google => ShortURL::Google,
    :tinyurl => ShortURL::TinyURL,
    :bitly => ShortURL::Bitly
}
VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.shorten(url, driver = DEFAULT_DRIVER, account = {}) ⇒ Object

Takes a URL and returns the driver instance, which should then have its callback and errback attributes set. Optionally accepts driver and account. driver is a symbol which maps to a driver class and account is a driver-specific hash of account information.

Raises KeyError if the driver is not mapped.

Raises:

  • (KeyError)


32
33
34
35
36
37
# File 'lib/em-shorturl.rb', line 32

def self.shorten(url, driver=DEFAULT_DRIVER, ={})
    raise KeyError, "Driver does not exist" unless DRIVERS[driver]

    r = DRIVERS[driver].new()
    r.shorten(url)
end