1 # Copyright 2010 Google Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 require 'addressable/template'
18 module Google #:nodoc:
19 class APIClient #:nodoc:
21 # A discovery document handler.
25 # The default discovery configuration values. These may be overrided
26 # simply by passing in the same key to the constructor.
31 # A set of default configuration values specific to each service. These
32 # may be overrided simply by passing in the same key to the constructor.
37 # Creates a new API discovery handler.
39 # @param [Hash] options
40 # <code>:service</code>::
41 # The name of the service.
42 # <code>:service_version</code>::
43 # The version of the service.
44 # <code>:discovery_uri</code>::
45 # The URI of the discovery document.
47 # @return [Google::APIClient::Discovery] The API discovery handler.
48 def initialize(options={})
49 if options[:service] && SERVICE_DEFAULTS[options[:service]]
50 @options = DEFAULTS.merge(SERVICE_DEFAULTS[options[:service]])
52 @options = DEFAULTS.clone
54 @options.merge!(options)
55 if @options[:service] && !@options[:discovery_uri]
56 service_id = @options[:service]
57 service_version = @options[:service_version] || '1.0'
58 @options[:discovery_uri] =
59 "http://www.googleapis.com/discovery/0.1/describe" +
60 "?api=#{service_id}&apiVersion=#{service_version}"
62 unless @options[:discovery_uri]
64 'Missing required configuration value, :discovery_uri.'
66 # Handle any remaining configuration here
70 # Returns the configuration of the handler. Configuration options that
71 # are not recognized by the handler are ignored.
73 # @return [Hash] The configuration options.
79 # Returns the URI of the discovery document.
81 # @return [String] The URI of the discovery document.
83 return @options[:discovery_uri]