Last active
March 15, 2016 14:25
-
-
Save ktheory/1762136 to your computer and use it in GitHub Desktop.
A ruby helper for making git.io short urls
This file contains hidden or 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
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 = '[email protected]' | |
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 |
This file contains hidden or 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
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