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:
parent
89b0e1c31a
commit
e88fdbfef6
|
@ -14,8 +14,56 @@
|
|||
|
||||
module Google #:nodoc:
|
||||
class APIClient #:nodoc:
|
||||
##
|
||||
# Factory for HTTP backed client requests.
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue