Class: EventMachine::ShortURL::TinyURL

Inherits:
Object
  • Object
show all
Includes:
Deferrable
Defined in:
lib/em-shorturl/tinyurl.rb

Constant Summary collapse

API_URL =

TinyURL API URL

'http://tinyurl.com/api-create.php'

Instance Method Summary collapse

Constructor Details

#initialize(account = {}) ⇒ TinyURL

TinyURL has no accounts or users, so while the class accepts an account parameter, it is unused.



16
17
18
# File 'lib/em-shorturl/tinyurl.rb', line 16

def initialize(={})
    @deferrable_args = [self]
end

Instance Method Details

#shorten(url) ⇒ Object

Shortens the given URL, returning self. The shortened URL is passed to the success callback as the first parameter.



25
26
27
28
29
30
31
# File 'lib/em-shorturl/tinyurl.rb', line 25

def shorten(url)
    params = { :query => { :url => url } }
    request = EM::HttpRequest.new(API_URL).post(params)
    request.callback(&method(:on_success))
    request.errback(&method(:on_error))
    self
end