Created
October 23, 2012 19:19
-
-
Save clauda/3940988 to your computer and use it in GitHub Desktop.
bitly lib
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 | |
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