Class: Google::Apis::DiscoveryV1::RestDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/discovery_v1/google_extensions/rest_description.rb

Overview

Extensions to the Google::Apis::DiscoveryV1::RestDescription class

Examples:

require 'discovery_v1/google_extensions'
rest_description = DiscoveryV1.discovery_service.get_rest_api('sheets', 'v4')
schema = 'batch_update_spreadsheet_request'

# This is a valid object for the schema -- you'll probably have something
# more interesting
object = { 'requests' => [] }

# These are the extensions:
rest_description.validate_object(schema_name:, object: { 'requests' => [] })
rest_description.object_schema_names #=> ["add_banding_request", "add_banding_response", ...]

Instance Method Summary collapse

Instance Method Details

#object_schema_names(logger: Logger.new(nil)) ⇒ Array<String>

List the names of the schemas available to use in the Google Discovery V1 API

Examples:

List the name of the schemas available

rest_description = DiscoveryV1.discovery_service.get_rest_api('sheets', 'v4')
DiscoveryV1.api_object_schema_names #=> ["add_banding_request", "add_banding_response", ...]

Parameters:

  • logger (Logger) (defaults to: Logger.new(nil))

    the logger to use for logging error, info, and debug message

Returns:

  • (Array<String>)

    the names of the schemas available



62
63
64
# File 'lib/discovery_v1/google_extensions/rest_description.rb', line 62

def object_schema_names(logger: Logger.new(nil))
  ::DiscoveryV1::Validation::LoadSchemas.new(rest_description: self, logger:).call.keys.sort
end

#validate_object(schema_name:, object:, logger: Logger.new(nil)) ⇒ void

This method returns an undefined value.

Validate the object using the named JSON schema

The JSON schemas are loaded from the Google Disocvery API. The schemas names are returned by ‘DiscoveryV1.api_object_schema_names`.

Examples:

schema_name = 'batch_update_spreadsheet_request'
object = { 'requests' => [] }
DiscoveryV1.validate_api_object(schema_name:, object:)

Parameters:

  • schema_name (String)

    the name of the schema to validate against

  • object (Object)

    the object to validate

  • logger (Logger) (defaults to: Logger.new(nil))

    the logger to use for logging error, info, and debug message

Raises:

  • (RuntimeError)

    if the object does not conform to the schema



48
49
50
# File 'lib/discovery_v1/google_extensions/rest_description.rb', line 48

def validate_object(schema_name:, object:, logger: Logger.new(nil))
  ::DiscoveryV1::Validation::ValidateObject.new(rest_description: self, logger:).call(schema_name:, object:)
end