Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ruby script to shorten a url by TinyURL.(ver.2)
#!/usr/local/bin/ruby
# coding:utf-8
#*************************************
# TinyURL API で ロング URL を短縮する
#*************************************
#
require 'cgi'
require 'net/http'
require 'open-uri'
class TinyurlShorten
SERVER = "tinyurl.com"
PATH = "/api-create.php"
def initialize(arg)
@url_long = arg
end
def shorten
puts "URL(LONG) : #{@url_long}"
query = "url=#{URI.encode(@url_long)}"
url_short = Net::HTTP.get(SERVER, "#{PATH}?#{query}")
puts "URL(SHORT): #{url_short}" # => http://tinyurl.com/j3nceqk
end
end
exit 0 unless __FILE__ == $0
exit 0 unless arg = ARGV.shift
TinyurlShorten.new(arg).shorten
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.