| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  | # Copyright 2015 Google Inc. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  | # you may not use this file except in compliance with the License. | 
					
						
							|  |  |  | # You may obtain a copy of the License at | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #      http://www.apache.org/licenses/LICENSE-2.0 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  | # distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  | # See the License for the specific language governing permissions and | 
					
						
							|  |  |  | # limitations under the License. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require 'active_support/inflector' | 
					
						
							|  |  |  | require 'google/apis/discovery_v1' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Extend the discovery API classes with additional data needed to make | 
					
						
							|  |  |  | # code generation produce better results | 
					
						
							|  |  |  | module Google | 
					
						
							|  |  |  |   module Apis | 
					
						
							|  |  |  |     module DiscoveryV1 | 
					
						
							|  |  |  |       TYPE_MAP = { | 
					
						
							|  |  |  |         'string' => 'String', | 
					
						
							|  |  |  |         'boolean' => 'Boolean', | 
					
						
							|  |  |  |         'number' => 'Float', | 
					
						
							|  |  |  |         'integer' => 'Fixnum', | 
					
						
							|  |  |  |         'any' => 'Object' | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class JsonSchema | 
					
						
							|  |  |  |         attr_accessor :name | 
					
						
							|  |  |  |         attr_accessor :generated_name | 
					
						
							|  |  |  |         attr_accessor :generated_class_name | 
					
						
							|  |  |  |         attr_accessor :base_ref | 
					
						
							|  |  |  |         attr_accessor :parent | 
					
						
							|  |  |  |         attr_accessor :discriminant | 
					
						
							|  |  |  |         attr_accessor :discriminant_value | 
					
						
							|  |  |  |         attr_accessor :path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def properties | 
					
						
							| 
									
										
										
										
											2017-07-18 16:56:05 +00:00
										 |  |  |           Hash[(@properties || {}).sort] | 
					
						
							| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def qualified_name | 
					
						
							|  |  |  |           parent.qualified_name + '::' + generated_class_name | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def generated_type | 
					
						
							|  |  |  |           case type | 
					
						
							|  |  |  |           when 'string', 'boolean', 'number', 'integer', 'any' | 
					
						
							|  |  |  |             return 'DateTime' if format == 'date-time' | 
					
						
							|  |  |  |             return 'Date' if format == 'date' | 
					
						
							| 
									
										
										
										
											2016-08-17 22:27:23 +00:00
										 |  |  |             return 'Fixnum' if format == 'int64' | 
					
						
							|  |  |  |             return 'Fixnum' if format == 'uint64' | 
					
						
							| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  |             return TYPE_MAP[type] | 
					
						
							|  |  |  |           when 'array' | 
					
						
							| 
									
										
										
										
											2017-10-12 17:57:57 +00:00
										 |  |  |             if items == self | 
					
						
							|  |  |  |               return sprintf('Array<%s>', qualified_name) | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  |             return sprintf('Array<%s>', items.generated_type) | 
					
						
							|  |  |  |           when 'hash' | 
					
						
							| 
									
										
										
										
											2017-10-12 17:57:57 +00:00
										 |  |  |             if additional_properties == self | 
					
						
							|  |  |  |               return sprintf('Hash<String,%s>', qualified_name) | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  |             return sprintf('Hash<String,%s>', additional_properties.generated_type) | 
					
						
							|  |  |  |           when 'object' | 
					
						
							|  |  |  |             return qualified_name | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class RestMethod | 
					
						
							|  |  |  |         attr_accessor :generated_name | 
					
						
							|  |  |  |         attr_accessor :parent | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-18 16:56:05 +00:00
										 |  |  |         def parameters | 
					
						
							|  |  |  |           Hash[(@parameters || {}).sort] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  |         def path_parameters | 
					
						
							|  |  |  |           return [] if parameter_order.nil? || parameters.nil? | 
					
						
							|  |  |  |           parameter_order.map { |name| parameters[name] }.select { |param| param.location == 'path' } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def query_parameters | 
					
						
							|  |  |  |           return [] if parameters.nil? | 
					
						
							|  |  |  |           parameters.values.select { |param| param.location == 'query' } | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-12 17:57:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 00:05:05 +00:00
										 |  |  |         def required_parameters | 
					
						
							|  |  |  |           return [] if parameter_order.nil? || parameters.nil? | 
					
						
							|  |  |  |           parameter_order.map { |name| parameters[name] }.select { |param| param.location == 'path' || param.required } | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-12 17:57:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 00:05:05 +00:00
										 |  |  |         def optional_query_parameters | 
					
						
							|  |  |  |           query_parameters.select { |param| param.required != true } | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-12 17:57:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class RestResource | 
					
						
							|  |  |  |         attr_accessor :parent | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-18 16:56:05 +00:00
										 |  |  |         def api_methods | 
					
						
							|  |  |  |           Hash[(@api_methods || {}).sort] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def resources | 
					
						
							|  |  |  |           Hash[(@resources || {}).sort] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  |         def all_methods | 
					
						
							|  |  |  |           m = [] | 
					
						
							|  |  |  |           m << api_methods.values unless api_methods.nil? | 
					
						
							|  |  |  |           m << resources.map { |_k, r| r.all_methods } unless resources.nil? | 
					
						
							|  |  |  |           m.flatten | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class RestDescription | 
					
						
							| 
									
										
										
										
											2016-01-14 18:48:40 +00:00
										 |  |  |         attr_accessor :force_alt_json | 
					
						
							|  |  |  |         alias_method :force_alt_json?, :force_alt_json | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-18 16:56:05 +00:00
										 |  |  |         # Don't expose these in the API directly. | 
					
						
							|  |  |  |         PARAMETER_BLACKLIST = %w(alt access_token bearer_token oauth_token pp prettyPrint
 | 
					
						
							|  |  |  |                                  $.xgafv callback upload_protocol uploadType) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  |         def version | 
					
						
							|  |  |  |           ActiveSupport::Inflector.camelize(@version.gsub(/\W/, '-')).gsub(/-/, '_') | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def name | 
					
						
							|  |  |  |           ActiveSupport::Inflector.camelize(@name) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def module_name | 
					
						
							|  |  |  |           name + version | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def qualified_name | 
					
						
							|  |  |  |           sprintf('Google::Apis::%s', module_name) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def service_name | 
					
						
							|  |  |  |           class_name = (canonical_name || name).gsub(/\W/, '') | 
					
						
							|  |  |  |           ActiveSupport::Inflector.camelize(sprintf('%sService', class_name)) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-18 16:56:05 +00:00
										 |  |  |         def api_methods | 
					
						
							|  |  |  |           Hash[(@api_methods || {}).sort] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def resources | 
					
						
							|  |  |  |           Hash[(@resources || {}).sort] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  |         def all_methods | 
					
						
							|  |  |  |           m = [] | 
					
						
							|  |  |  |           m << api_methods.values unless api_methods.nil? | 
					
						
							|  |  |  |           m << resources.map { |_k, r| r.all_methods } unless resources.nil? | 
					
						
							|  |  |  |           m.flatten | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-18 16:56:05 +00:00
										 |  |  |         def parameters | 
					
						
							| 
									
										
										
										
											2019-03-20 21:58:19 +00:00
										 |  |  |           Hash[(@parameters || {}).sort].delete_if { |k, _v| PARAMETER_BLACKLIST.include?(k) } | 
					
						
							| 
									
										
										
										
											2017-07-18 16:56:05 +00:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def schemas | 
					
						
							|  |  |  |           Hash[(@schemas || {}).sort] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  |         class Auth | 
					
						
							|  |  |  |           class Oauth2 | 
					
						
							|  |  |  |             class Scope | 
					
						
							|  |  |  |               attr_accessor :constant | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2017-07-18 16:56:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             def scopes | 
					
						
							|  |  |  |               Hash[(@scopes || {}).sort] | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2015-04-17 00:28:38 +00:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |