diff --git a/lib/google/api_client/transport/http_transport.rb b/lib/google/api_client/transport/http_transport.rb index 823dca714..8293d54a2 100644 --- a/lib/google/api_client/transport/http_transport.rb +++ b/lib/google/api_client/transport/http_transport.rb @@ -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