add parser configuration to http transport, will add tests next commit

git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@18 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
mattpok@google.com 2010-08-18 21:39:44 +00:00
parent 89b0e1c31a
commit e88fdbfef6
1 changed files with 49 additions and 1 deletions

View File

@ -14,8 +14,56 @@
module Google #:nodoc: module Google #:nodoc:
class APIClient #:nodoc: class APIClient #:nodoc:
##
# Factory for HTTP backed client requests.
class HTTPTransport class HTTPTransport
##
# The default transport configuration values. These may be overridden
# simply by passing in the same key to the constructor.
DEFAULTS = {
:parser => :json_parser
}
##
# The default implementations of various parsers. These may be overriden
# simply by passing the same key to the constructor.
PARSERS = {
:json_parser => JSONParser.new
}
##
# Creates a new HTTP request factory.
#
# @param [Hash] options
# @return [Google::APIClient::Discovery] The HTTP request factory.
def initialize(options={})
@options = DEFAULTS.clone
@options.merge!(options)
# first check if user passed a parser then fallback on appropriate default
@parser = @options[@options[:parser]] || PARSERS[@options[:parser]]
unless @parser
raise ArgumentError,
'Invalid :parser configuration.'
end
end
##
# Returns configuration of the transport.
#
# @return [Hash] The configuration options.
def options
return @options
end
##
# Returns the parser used by the transport.
#
# @return The handle to the parser.
def parser
return @parser
end
end end
end end
end end