udpate ruby api client to support user-agent

This commit is contained in:
William Cheng 2015-03-19 17:09:27 +08:00
parent c109c11bea
commit 02283fae46
2 changed files with 5 additions and 4 deletions

View File

@ -3,7 +3,7 @@ module Swagger
class Configuration class Configuration
require 'swagger/version' require 'swagger/version'
attr_accessor :format, :api_key, :username, :password, :auth_token, :scheme, :host, :base_path, :user_agent, :logger, :inject_format, :force_ending_format, :camelize_params attr_accessor :format, :api_key, :username, :password, :auth_token, :scheme, :host, :base_path, :user_agent, :logger, :inject_format, :force_ending_format, :camelize_params, :user_agent
# Defaults go in here.. # Defaults go in here..
def initialize def initialize
@ -11,7 +11,7 @@ module Swagger
@scheme = 'http' @scheme = 'http'
@host = 'api.wordnik.com' @host = 'api.wordnik.com'
@base_path = '/v4' @base_path = '/v4'
@user_agent = "ruby-#{Swagger::VERSION}" @user_agent = "ruby-swagger-#{Swagger::VERSION}"
@inject_format = true @inject_format = true
@force_ending_format = false @force_ending_format = false
@camelize_params = true @camelize_params = true
@ -19,4 +19,4 @@ module Swagger
end end
end end

View File

@ -19,7 +19,8 @@ module Swagger
# Set default headers # Set default headers
default_headers = { default_headers = {
'Content-Type' => "application/#{attributes[:format].downcase}", 'Content-Type' => "application/#{attributes[:format].downcase}",
:api_key => Swagger.configuration.api_key :api_key => Swagger.configuration.api_key,
'User-Agent' => Swagger.configuration.user_agent
} }
# api_key from headers hash trumps the default, even if its value is blank # api_key from headers hash trumps the default, even if its value is blank