Skip to content

Instantly share code, notes, and snippets.

@clauda
Created October 23, 2012 19:19
Show Gist options
  • Save clauda/3940988 to your computer and use it in GitHub Desktop.
Save clauda/3940988 to your computer and use it in GitHub Desktop.
bitly lib
class Bitly
def self.shorten url
Net::HTTP.start("api.bit.ly", 80) do |http|
request = http.get("/v3/shorten?#{required_params.merge(:longUrl => url).to_query}")
response = JSON.parse(request.body)
return response['data']['url'] if response['status_code'] == 200
end
end
def self.required_params
{ :login => 'YOUR LOGIN', :apiKey => 'YOUR API KEY' }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment