Skip to content

Commit

Permalink
Merge pull request #67 from barraq/master
Browse files Browse the repository at this point in the history
introduce HTTParty-configuration, fix #61
  • Loading branch information
jvanbaarsen committed Sep 30, 2014
2 parents 38ad27f + 40295b8 commit e9107e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/gitlab/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/gitlab/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit e9107e0

Please sign in to comment.