Accidental Technologist

Musings about Entrepreneurship, Technology and Software Development

  • Home
  • About
  • Still River Software
  • Privacy Policy

Powered by Genesis

Use TinyURL from Ruby

June 6, 2013 by Rob Bazinet Leave a Comment

Tweet

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!

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Filed Under: Ruby Tagged With: httparty, Ruby, tinyurl

Recent Posts

  • Social Media Times Are Changing
  • It has certainly been a long time…
  • How to Fix Rails Flash Rendering When Using Hotwire
  • Hotwire Fix for CORS Error when using Omniauth
  • Fix Installation of Ruby using rbenv on macOS Big Sur

Categories

Services I Love

HatchBox - Easy Rails Deploys Fathom Analytics
Follow @rbazinet

Rob Bazinet
@rbazinet

  • Great little utility https://t.co/6AgboJv6oI
    about 1 day ago
  • Funny watching the hate to show up in my time line for ChatGPT. People getting defensive about it.
    about 4 days ago
  • I just backed The SaaS Playbook, by Rob Walling on @Kickstarter https://t.co/1FpTWN9c9v
    about 5 days ago
  • This looks like an interesting project. I need to dig in a bit. https://t.co/gacEX9AmEn "Phlex — fast, object-orie… https://t.co/4AUL0Z0SBl
    about 5 days ago
  • I attempted to use ChatGPT today and asked a couple questions it couldn’t answer. I thought it was a magical black… https://t.co/uJGw0CgUAv
    about 5 days ago
  • RSS - Posts
  • RSS - Comments
Find me on Mastodon