Created
November 22, 2011 14:41
-
-
Save rriemann/1385806 to your computer and use it in GitHub Desktop.
Make usage ur1.ca url shortener within KDE Klipper or from command line
This file contains 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
#!/usr/bin/env ruby | |
# kate: remove-trailing-space on; replace-trailing-space-save on; indent-width 2; indent-mode ruby; syntax ruby; | |
# ur1.rb | |
require 'net/http' | |
require 'cgi' | |
require 'uri' | |
URL = URI.parse "http://ur1.ca/" | |
raise if ARGV.size == 0 | |
longurl = ARGV[0] | |
http = Net::HTTP.new URL.host, URL.port | |
query_string = "longurl=#{CGI.escape longurl}" | |
response, body = http.start do |http| | |
http.post URL.path, query_string | |
end | |
abort "error (wrong response code)" unless response.code == '200' | |
puts (body[/<p class="success">Your ur1 is: <a href="(.+)"/,1] or "error (no url returned)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment