Created
June 9, 2009 12:51
-
-
Save thinkcreate/126460 to your computer and use it in GitHub Desktop.
Bitly client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bitly | |
include HTTParty | |
base_uri 'api.bit.ly' | |
default_params :version=>'2.0.1' | |
format :json | |
def initialize(login, key) | |
@auth = {:login => login, :apiKey => key} | |
end | |
def shorten(url) | |
options = {:longUrl => url}.merge(@auth) | |
self.class.get('/shorten', :query => options)['results'].values.first['shortUrl'] | |
end | |
end | |
=begin | |
Usage: | |
bitly = Bitly.new('login','key') | |
bitly.shorten('http://railstips.org/2009/6/8/what-is-the-simplest-thing-that-could-possibly-work') #=> "http://bit.ly/EUrKW" | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment