I recently found myself needing to use TinyURL on a client project. ?I did a bit of scouring the web for some Ruby code to solve the problem but with little success. ?Much to my surprise they don’t have an available API, but they do have a way to access over HTTP.
This is a simple Ruby class to use TinyURL. ?Note: this depends on HTTParty, so add to your project.
class Tinyurl
include HTTParty
base_uri 'tinyurl.com'
def shorten(url)
self.class.get("/api-create.php?url=#{url}")
end
end
You can find the Gist on Github. Hopefully you find this code useful. Enjoy!