lib/gitlab/request.rb in gitlab-4.0.0 vs lib/gitlab/request.rb in gitlab-4.1.0

- old
+ new

@@ -4,11 +4,11 @@ module Gitlab # @private class Request include HTTParty format :json - headers 'Accept' => 'application/json' + headers 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' parser proc { |body, _| parse(body) } attr_accessor :private_token, :endpoint # Converts the response body to an ObjectifiedHash. @@ -43,11 +43,11 @@ validate self.class.get(@endpoint + path, options) end def post(path, options={}) set_httparty_config(options) - set_authorization_header(options, path) + set_authorization_header(options) validate self.class.post(@endpoint + path, options) end def put(path, options={}) set_httparty_config(options) @@ -94,12 +94,15 @@ end private # Sets a PRIVATE-TOKEN or Authorization header for requests. + # + # @param [Hash] options A customizable set of options. + # @option options [Boolean] :unauthenticated true if the API call does not require user authentication. # @raise [Error::MissingCredentials] if private_token and auth_token are not set. - def set_authorization_header(options, path=nil) - unless path == '/session' + def set_authorization_header(options) + unless options[:unauthenticated] raise Error::MissingCredentials.new("Please provide a private_token or auth_token for user") unless @private_token if @private_token.length <= 20 options[:headers] = { 'PRIVATE-TOKEN' => @private_token } else options[:headers] = { 'Authorization' => "Bearer #{@private_token}" }