Module: DiscoveryV1

Defined in:
lib/discovery_v1.rb,
lib/discovery_v1/version.rb,
lib/discovery_v1/validation.rb,
lib/discovery_v1/validation/load_schemas.rb,
lib/discovery_v1/validation/validate_object.rb,
lib/discovery_v1/validation/resolve_schema_ref.rb,
lib/discovery_v1/validation/traverse_object_tree.rb

Overview

Unofficial helpers for the Google Discovery V1 API

Defined Under Namespace

Modules: Validation

Constant Summary collapse

VERSION =

The version of this gem

'0.1.0'

Validation collapse

Class Method Summary collapse

Class Method Details

.discovery_serviceGoogle::Apis::DiscoveryV1::DiscoveryService

Create a new Google::Apis::DiscoveryV1::DiscoveryService object

A credential is not needed to use the DiscoveryService.

Examples:

DiscoveryV1.discovery_service

Returns:

  • (Google::Apis::DiscoveryV1::DiscoveryService)

    a new DiscoveryService instance



23
24
25
# File 'lib/discovery_v1.rb', line 23

def discovery_service
  Google::Apis::DiscoveryV1::DiscoveryService.new
end

.object_schema_names(rest_description:, 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:

  • rest_description (Google::Apis::DiscoveryV1::RestDescription)

    the Google Discovery V1 API rest description

  • 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



63
64
65
# File 'lib/discovery_v1.rb', line 63

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

.validate_object(rest_description:, 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:

  • rest_description (Google::Apis::DiscoveryV1::RestDescription)

    the Google Discovery V1 API rest description

  • 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.rb', line 48

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