Service Usage V1 API - Class Google::Cloud::ServiceUsage::V1::ServiceUsage::Client (v1.1.0)

Reference documentation and code samples for the Service Usage V1 API class Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.

Client for the ServiceUsage service.

Enables services that service consumers want to use on Google Cloud Platform, lists the available or enabled services, or disables services that service consumers no longer use.

See Service Usage API

Inherits

  • Object

Methods

.configure

def self.configure() { |config| ... } -> Client::Configuration

Configure the ServiceUsage Client class.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter
Example
# Modify the configuration for all ServiceUsage clients
::Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.configure do |config|
  config.timeout = 10.0
end

#batch_enable_services

def batch_enable_services(request, options = nil) -> ::Gapic::Operation
def batch_enable_services(parent: nil, service_ids: nil) -> ::Gapic::Operation

Enable multiple services on a project. The operation is atomic: if enabling any service fails, then the entire batch fails, and no state changes occur. To enable a single service, use the EnableService method instead.

Overloads
def batch_enable_services(request, options = nil) -> ::Gapic::Operation
Pass arguments to batch_enable_services via a request object, either of type BatchEnableServicesRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def batch_enable_services(parent: nil, service_ids: nil) -> ::Gapic::Operation
Pass arguments to batch_enable_services via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Parent to enable services on.

    An example name would be: projects/123 where 123 is the project number.

    The BatchEnableServices method currently only supports projects.

  • service_ids (::Array<::String>) — The identifiers of the services to enable on the project.

    A valid identifier would be: serviceusage.googleapis.com

    Enabling services requires that each service is public or is shared with the user enabling the service.

    A single request can enable a maximum of 20 services at a time. If more than 20 services are specified, the request will fail, and no state changes will occur.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)
Returns
  • (::Gapic::Operation)
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/service_usage/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest.new

# Call the batch_enable_services method.
result = client.batch_enable_services request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

#batch_get_services

def batch_get_services(request, options = nil) -> ::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse
def batch_get_services(parent: nil, names: nil) -> ::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse

Returns the service configurations and enabled states for a given list of services.

Overloads
def batch_get_services(request, options = nil) -> ::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse
Pass arguments to batch_get_services via a request object, either of type BatchGetServicesRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def batch_get_services(parent: nil, names: nil) -> ::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse
Pass arguments to batch_get_services via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Parent to retrieve services from. If this is set, the parent of all of the services specified in names must match this field. An example name would be: projects/123 where 123 is the project number. The BatchGetServices method currently only supports projects.
  • names (::Array<::String>) — Names of the services to retrieve.

    An example name would be: projects/123/services/serviceusage.googleapis.com where 123 is the project number. A single request can get a maximum of 30 services at a time.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/service_usage/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest.new

# Call the batch_get_services method.
result = client.batch_get_services request

# The returned object is of type Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse.
p result

#configure

def configure() { |config| ... } -> Client::Configuration

Configure the ServiceUsage Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on Client.configure.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter

#disable_service

def disable_service(request, options = nil) -> ::Gapic::Operation
def disable_service(name: nil, disable_dependent_services: nil, check_if_service_has_usage: nil) -> ::Gapic::Operation

Disable a service so that it can no longer be used with a project. This prevents unintended usage that may cause unexpected billing charges or security leaks.

It is not valid to call the disable method on a service that is not currently enabled. Callers will receive a FAILED_PRECONDITION status if the target service is not currently enabled.

Overloads
def disable_service(request, options = nil) -> ::Gapic::Operation
Pass arguments to disable_service via a request object, either of type DisableServiceRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::ServiceUsage::V1::DisableServiceRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def disable_service(name: nil, disable_dependent_services: nil, check_if_service_has_usage: nil) -> ::Gapic::Operation
Pass arguments to disable_service via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • name (::String) — Name of the consumer and service to disable the service on.

    The enable and disable methods currently only support projects.

    An example name would be: projects/123/services/serviceusage.googleapis.com where 123 is the project number.

  • disable_dependent_services (::Boolean) — Indicates if services that are enabled and which depend on this service should also be disabled. If not set, an error will be generated if any enabled services depend on the service to be disabled. When set, the service, and any enabled services that depend on it, will be disabled together.
  • check_if_service_has_usage (::Google::Cloud::ServiceUsage::V1::DisableServiceRequest::CheckIfServiceHasUsage) — Defines the behavior for checking service usage when disabling a service.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)
Returns
  • (::Gapic::Operation)
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/service_usage/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ServiceUsage::V1::DisableServiceRequest.new

# Call the disable_service method.
result = client.disable_service request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

#enable_service

def enable_service(request, options = nil) -> ::Gapic::Operation
def enable_service(name: nil) -> ::Gapic::Operation

Enable a service so that it can be used with a project.

Overloads
def enable_service(request, options = nil) -> ::Gapic::Operation
Pass arguments to enable_service via a request object, either of type EnableServiceRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::ServiceUsage::V1::EnableServiceRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def enable_service(name: nil) -> ::Gapic::Operation
Pass arguments to enable_service via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Name of the consumer and service to enable the service on.

    The EnableService and DisableService methods currently only support projects.

    Enabling a service requires that the service is public or is shared with the user enabling the service.

    An example name would be: projects/123/services/serviceusage.googleapis.com where 123 is the project number.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)
Returns
  • (::Gapic::Operation)
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/service_usage/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ServiceUsage::V1::EnableServiceRequest.new

# Call the enable_service method.
result = client.enable_service request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

#get_service

def get_service(request, options = nil) -> ::Google::Cloud::ServiceUsage::V1::Service
def get_service(name: nil) -> ::Google::Cloud::ServiceUsage::V1::Service

Returns the service configuration and enabled state for a given service.

Overloads
def get_service(request, options = nil) -> ::Google::Cloud::ServiceUsage::V1::Service
Pass arguments to get_service via a request object, either of type GetServiceRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::ServiceUsage::V1::GetServiceRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def get_service(name: nil) -> ::Google::Cloud::ServiceUsage::V1::Service
Pass arguments to get_service via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Name of the consumer and service to get the ConsumerState for.

    An example name would be: projects/123/services/serviceusage.googleapis.com where 123 is the project number.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/service_usage/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ServiceUsage::V1::GetServiceRequest.new

# Call the get_service method.
result = client.get_service request

# The returned object is of type Google::Cloud::ServiceUsage::V1::Service.
p result

#initialize

def initialize() { |config| ... } -> Client

Create a new ServiceUsage client object.

Yields
  • (config) — Configure the ServiceUsage client.
Yield Parameter
Returns
  • (Client) — a new instance of Client
Example
# Create a client using the default configuration
client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.new do |config|
  config.timeout = 10.0
end

#list_services

def list_services(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::ServiceUsage::V1::Service>
def list_services(parent: nil, page_size: nil, page_token: nil, filter: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::ServiceUsage::V1::Service>

List all services available to the specified project, and the current state of those services with respect to the project. The list includes all public services, all services for which the calling user has the servicemanagement.services.bind permission, and all services that have already been enabled on the project. The list can be filtered to only include services in a specific state, for example to only include services enabled on the project.

WARNING: If you need to query enabled services frequently or across an organization, you should use Cloud Asset Inventory API, which provides higher throughput and richer filtering capability.

Overloads
def list_services(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::ServiceUsage::V1::Service>
Pass arguments to list_services via a request object, either of type ListServicesRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::ServiceUsage::V1::ListServicesRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def list_services(parent: nil, page_size: nil, page_token: nil, filter: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::ServiceUsage::V1::Service>
Pass arguments to list_services via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Parent to search for services on.

    An example name would be: projects/123 where 123 is the project number.

  • page_size (::Integer) — Requested size of the next page of data. Requested page size cannot exceed 200. If not set, the default page size is 50.
  • page_token (::String) — Token identifying which result to start with, which is returned by a previous list call.
  • filter (::String) — Only list services that conform to the given filter. The allowed filter strings are state:ENABLED and state:DISABLED.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Returns
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/service_usage/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ServiceUsage::V1::ListServicesRequest.new

# Call the list_services method.
result = client.list_services request

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Cloud::ServiceUsage::V1::Service.
  p item
end

#logger

def logger() -> Logger

The logger used for request/response debug logging.

Returns
  • (Logger)

#operations_client

def operations_client() -> ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Operations

Get the associated client for long-running operations.

#universe_domain

def universe_domain() -> String

The effective universe domain

Returns
  • (String)