From e88fdbfef65b2f0e297cf05ce5191ba49035d493 Mon Sep 17 00:00:00 2001 From: "mattpok@google.com" Date: Wed, 18 Aug 2010 21:39:44 +0000 Subject: [PATCH] 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 --- .../api_client/transport/http_transport.rb | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) 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