diff --git a/lib/gitlab/configuration.rb b/lib/gitlab/configuration.rb index e56451920..b36ed5a7d 100644 --- a/lib/gitlab/configuration.rb +++ b/lib/gitlab/configuration.rb @@ -2,7 +2,7 @@ module Gitlab # Defines constants and methods related to configuration. module Configuration # An array of valid keys in the options hash when configuring a Gitlab::API. - VALID_OPTIONS_KEYS = [:endpoint, :private_token, :user_agent, :sudo].freeze + VALID_OPTIONS_KEYS = [:endpoint, :private_token, :user_agent, :sudo, :httparty].freeze # The user agent that will be sent to the API endpoint if none is set. DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}".freeze diff --git a/lib/gitlab/request.rb b/lib/gitlab/request.rb index 31ec98bbc..64a8f6b4c 100644 --- a/lib/gitlab/request.rb +++ b/lib/gitlab/request.rb @@ -34,21 +34,25 @@ def self.decode(response) end def get(path, options={}) + set_httparty_config(options) set_private_token_header(options) validate self.class.get(path, options) end def post(path, options={}) + set_httparty_config(options) set_private_token_header(options, path) validate self.class.post(path, options) end def put(path, options={}) + set_httparty_config(options) set_private_token_header(options) validate self.class.put(path, options) end def delete(path, options={}) + set_httparty_config(options) set_private_token_header(options) validate self.class.delete(path, options) end @@ -93,6 +97,14 @@ def set_private_token_header(options, path=nil) end end + # Set HTTParty configuration + # @see https://github.com/jnunemaker/httparty + def set_httparty_config(options) + if self.httparty + options.merge!(self.httparty) + end + end + def error_message(response) "Server responded with code #{response.code}, message: #{response.parsed_response.message}. " \ "Request URI: #{response.request.base_uri}#{response.request.path}"