diff --git a/lib/gitlab/request.rb b/lib/gitlab/request.rb index 64a8f6b4c..ac1d45720 100644 --- a/lib/gitlab/request.rb +++ b/lib/gitlab/request.rb @@ -9,7 +9,7 @@ class Request headers 'Accept' => 'application/json' parser Proc.new { |body, _| parse(body) } - attr_accessor :private_token + attr_accessor :private_token, :endpoint # Converts the response body to an ObjectifiedHash. def self.parse(body) @@ -36,25 +36,25 @@ def self.decode(response) def get(path, options={}) set_httparty_config(options) set_private_token_header(options) - validate self.class.get(path, options) + validate self.class.get(@endpoint + path, options) end def post(path, options={}) set_httparty_config(options) set_private_token_header(options, path) - validate self.class.post(path, options) + validate self.class.post(@endpoint + path, options) end def put(path, options={}) set_httparty_config(options) set_private_token_header(options) - validate self.class.put(path, options) + validate self.class.put(@endpoint + path, options) end def delete(path, options={}) set_httparty_config(options) set_private_token_header(options) - validate self.class.delete(path, options) + validate self.class.delete(@endpoint + path, options) end # Checks the response code for common errors. @@ -80,8 +80,8 @@ def validate(response) def set_request_defaults(endpoint, private_token, sudo=nil) raise Error::MissingCredentials.new("Please set an endpoint to API") unless endpoint @private_token = private_token + @endpoint = endpoint - self.class.base_uri endpoint self.class.default_params :sudo => sudo self.class.default_params.delete(:sudo) if sudo.nil? end diff --git a/spec/gitlab/request_spec.rb b/spec/gitlab/request_spec.rb index 869c2e964..e699dde87 100644 --- a/spec/gitlab/request_spec.rb +++ b/spec/gitlab/request_spec.rb @@ -34,9 +34,10 @@ end context "when endpoint is set" do - it "should set base_uri" do - Gitlab::Request.new.set_request_defaults('http://rabbit-hole.example.org', 1234000) - expect(Gitlab::Request.base_uri).to eq("http://rabbit-hole.example.org") + it "should set instance variable 'endpoint'" do + request = Gitlab::Request.new + request.set_request_defaults('http://rabbit-hole.example.org', 1234000) + expect(request.instance_variable_get(:@endpoint)).to eq("http://rabbit-hole.example.org") end it "should set default_params" do