Skip to content

Instantly share code, notes, and snippets.

@takatoh
Created April 8, 2012 14:12
Show Gist options
  • Save takatoh/2337518 to your computer and use it in GitHub Desktop.
Save takatoh/2337518 to your computer and use it in GitHub Desktop.
Shorten URL by p.tl
#! ruby
#
# Shorten URL by p.tl
#
require 'rubygems'
require 'uri'
require 'open-uri'
require 'json'
params = {
"url" => URI.encode(ARGV.shift),
"key" => your_api_key
}
url = "http://p.tl/api/api_simple.php" + "?" + params.map{|k,v| k + "=" + v}.join("&")
data = JSON.parse(open(url).read)
puts data["short_url"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment