From b2b94b0f57ead1740c7392599205c7b4994adf8c Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sat, 19 Mar 2016 07:22:08 +0530 Subject: [PATCH] Fix the "--shorten" option The "--shorten" command line option had stopped working since the git.io API changed. 1. The endpoint is now "/create". 2. HTTP links result in a 301 redirect. 3. The resulting shortcode is in the response body. Thanks-To: https://github.com/tjt263 for the hint. --- lib/gist.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/gist.rb b/lib/gist.rb index b2be9b9..79933a1 100644 --- a/lib/gist.rb +++ b/lib/gist.rb @@ -23,7 +23,7 @@ module Gist } GITHUB_API_URL = URI("https://api.github.com/") - GIT_IO_URL = URI("http://git.io") + GIT_IO_URL = URI("https://git.io") GITHUB_BASE_PATH = "" GHE_BASE_PATH = "/api/v3" @@ -263,10 +263,12 @@ def pretty_gist(response) # @param [String] url # @return [String] shortened url, or long url if shortening fails def shorten(url) - request = Net::HTTP::Post.new("/") + request = Net::HTTP::Post.new("/create") request.set_form_data(:url => url) response = http(GIT_IO_URL, request) case response.code + when "200" + URI.join(GIT_IO_URL, response.body) when "201" response['Location'] else