Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
You don't need a library for everything. For example, git.io :)
Git.io.generate 'https://gist.github.com/gists/1355677'
Git.io.generate 'https://github.com/gimi', 'gimi'
Git.io.recognize 'http://git.io/gimi'
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.