Skip to content

Instantly share code, notes, and snippets.

@cbartlett
Forked from jehiah/bitly.rb
Created November 7, 2013 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbartlett/7361541 to your computer and use it in GitHub Desktop.
Save cbartlett/7361541 to your computer and use it in GitHub Desktop.
# Bit.ly API implementation - thanks to Richard Johansso http://gist.github.com/112191
require 'httparty'
class Api::Bitly
include HTTParty
base_uri 'api.bit.ly'
format :json
# Usage: Bitly.shorten("http://example.com")
def self.shorten(url)
response = get('/v3/shorten', :query => required_params.merge(:longUrl => url ))
response['data']["url"]
end
# Usage: Bitly.stats("http://bit.ly/18LNRV")
def self.clicks(url)
response = get('/v3/clicks', :query => required_params.merge(:shortUrl => url))
response['data']['clicks'][0]['user_clicks']
end
# your bit.ly api key can be found at http://bit.ly/a/your_api_key
def self.required_params
{:version => "2.0.1", :login => "LOGIN", :apiKey => 'API_KEY'}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment