Skip to content

Commit

Permalink
Use endpoint instance var instead of base_uri class method. Fixes #94.
Browse files Browse the repository at this point in the history
  • Loading branch information
asedge committed Dec 18, 2014
1 parent 1ec8b38 commit 51611fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions lib/gitlab/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions spec/gitlab/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 51611fe

Please sign in to comment.