From c936a261834b710567c1b554a394141eefd4e89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Wed, 18 Jul 2012 22:46:37 +0200 Subject: [PATCH] cleanup prepending "/api/v3" to Enterprise API calls --- lib/hub/github_api.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/hub/github_api.rb b/lib/hub/github_api.rb index 2b013937..6434a8ea 100644 --- a/lib/hub/github_api.rb +++ b/lib/hub/github_api.rb @@ -43,7 +43,7 @@ module Hub def api_host host host = host.downcase - 'github.com' == host ? 'api.github.com' : [host, "/api/v3"].join + 'github.com' == host ? 'api.github.com' : host end # Public: Fetch data for a specific repo. @@ -154,7 +154,7 @@ module Hub url = URI.parse url unless url.respond_to? :host require 'net/https' - req = Net::HTTP.const_get(type).new(url.request_uri) + req = Net::HTTP.const_get(type).new request_uri(url) # TODO: better naming? http = configure_connection(req, url) do |host_url| create_connection host_url @@ -169,6 +169,12 @@ module Hub raise Context::FatalError, "error with #{type.to_s.upcase} #{url} (#{err.message})" end + def request_uri url + str = url.request_uri + str = '/api/v3' << str if url.host != 'api.github.com' + str + end + def configure_connection req, url if ENV['HUB_TEST_HOST'] req['Host'] = url.host @@ -223,7 +229,6 @@ module Hub end def obtain_oauth_token host, user - host = 'api.github.com' == host ? host : [host, "/api/v3"].join # first try to fetch existing authorization res = get "https://#{user}@#{host}/authorizations" res.error! unless res.success? -- GitLab