Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

You don't need a library for everything. For example, git.io :)

View example.rb
1 2 3
Git.io.generate 'https://gist.github.com/gists/1355677'
Git.io.generate 'https://github.com/gimi', 'gimi'
Git.io.recognize 'http://git.io/gimi'
View example.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
require 'net/http'
 
module Git
module IO
URL = URI 'http://git.io'
 
class Error < RuntimeError; end
 
instance_eval do
def generate(url, code = nil)
handle_response Net::HTTP.post_form(URL, 'url' => url, 'code' => code), Net::HTTPSuccess
end
 
def recognize(url)
raise Error, 'Invalid git.io short url' unless %r/^#{URL}/ === url
handle_response Net::HTTP.get_response(URI(url)), Net::HTTPRedirection
end
 
private
 
def handle_response(response, expected_response_type)
if expected_response_type === response
response['Location']
else
raise Error, response.body
end
end
end
end
 
def self.io; IO end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.