Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Read GitHub Enterprise URL from ENV

you must run `--login` if you use GHE:
	$ GHE_URL=<your_ghe_url> jist --login
  • Loading branch information...
commit 528e8976ff3edf0d6eb6800baad94882023f6bad 1 parent 471e600
@kui kui authored
Showing with 7 additions and 4 deletions.
  1. +7 −4 lib/jist.rb
View
11 lib/jist.rb
@@ -19,6 +19,9 @@ module Jist
GITHUB_API_URL = URI("https://api.github.com/")
GIT_IO_URL = URI("http://git.io")
+ GHE_URL = ENV.key?("GHE_URL") ? URI(ENV["GHE_URL"]) : nil
+ API_URL = GHE_URL || GITHUB_API_URL
+ API_BASE_PATH = GHE_URL ? "/api/v3" : ""
# Exception tag for errors raised while gisting.
module Error;
@@ -81,7 +84,7 @@ def multi_gist(files, options={})
access_token = (options[:access_token] || File.read(File.expand_path("~/.jist")) rescue nil)
end
- url = "/gists"
+ url = "#{API_BASE_PATH}/gists"
url << "/" << CGI.escape(existing_gist) if existing_gist.to_s != ''
url << "?access_token=" << CGI.escape(access_token) if access_token.to_s != ''
@@ -92,7 +95,7 @@ def multi_gist(files, options={})
retried = false
begin
- response = http(GITHUB_API_URL, request)
+ response = http(API_URL, request)
if Net::HTTPSuccess === response
on_success(response.body, options)
else
@@ -144,7 +147,7 @@ def login!
end
puts ""
- request = Net::HTTP::Post.new("/authorizations")
+ request = Net::HTTP::Post.new("#{API_BASE_PATH}/authorizations")
request.body = JSON.dump({
:scopes => [:gist],
:note => "The jist gem",
@@ -153,7 +156,7 @@ def login!
request.content_type = 'application/json'
request.basic_auth(username, password)
- response = http(GITHUB_API_URL, request)
+ response = http(API_URL, request)
if Net::HTTPCreated === response
File.open(File.expand_path("~/.jist"), 'w') do |f|
Please sign in to comment.
Something went wrong with that request. Please try again.