Skip to content

Commit

Permalink
fix old style gist url not found issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sp3c73r2038 committed Sep 20, 2013
1 parent f75547f commit cbf4b65
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions plugins/gist_tag.rb
Expand Up @@ -46,7 +46,7 @@ def script_url_for(gist_id, filename)
end

def get_gist_url_for(gist, file)
"https://raw.github.com/gist/#{gist}/#{file}"
"https://gist.github.com/raw/#{gist}/#{file}"
end

def cache(gist, file, data)
Expand All @@ -72,7 +72,29 @@ def get_cache_file_for(gist, file)

def get_gist_from_web(gist, file)
gist_url = get_gist_url_for gist, file
raw_uri = URI.parse gist_url
data = get_web_content gist_url
data = handle_gist_redirecting data
if data.code.to_i != 200
raise RuntimeError, "Gist replied with #{data.code} for #{gist_url}"
end
data = data.body
cache gist, file, data unless @cache_disabled
data
end

def handle_gist_redirecting(data)
if data.code.to_i == 302
redirected_url = data.header['Location']
data = get_web_content redirected_url
if data.code.to_i != 200
raise RuntimeError, "Gist replied with #{data.code} for #{gist_url}"
end
end
data
end

def get_web_content(url)
raw_uri = URI.parse url
proxy = ENV['http_proxy']
if proxy
proxy_uri = URI.parse(proxy)
Expand All @@ -84,12 +106,6 @@ def get_gist_from_web(gist, file)
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new raw_uri.request_uri
data = https.request request
if data.code.to_i != 200
raise RuntimeError, "Gist replied with #{data.code} for #{gist_url}"
end
data = data.body
cache gist, file, data unless @cache_disabled
data
end
end

Expand Down

0 comments on commit cbf4b65

Please sign in to comment.