Skip to content

Instantly share code, notes, and snippets.

@ktheory
Last active March 15, 2016 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktheory/1762136 to your computer and use it in GitHub Desktop.
Save ktheory/1762136 to your computer and use it in GitHub Desktop.
A ruby helper for making git.io short urls
Gem::Specification.new do |s|
s.name = 'git_io'
s.version = '1.0.0'
s.platform = Gem::Platform::RUBY
s.author = 'Aaron Suggs'
s.email = 'aaron@ktheory.com'
s.summary = 'Shorten urls with git.io'
s.description = 'GitIo.shorten(url)'
s.homepage = 'https://gist.github.com/1762136'
s.files = ['git_io.rb']
s.require_path = '.'
end
require 'net/https'
require 'uri'
module GitIo
BASE_URI = URI.parse("https://git.io/")
def self.shorten(url)
response = Net::HTTP.post_form(BASE_URI, :url => url)
case response.code
when "201"
response['Location']
else
raise response.body
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment