Skip to content

Commit

Permalink
feat(document_ai-v1beta3): Add support for ImportProcessorVersion (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
gcf-owl-bot[bot] authored Mar 21, 2023
1 parent 2d0ab7e commit 9a4e67c
Show file tree
Hide file tree
Showing 12 changed files with 513 additions and 0 deletions.
1 change: 1 addition & 0 deletions google-cloud-document_ai-v1beta3/.owlbot-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"snippets/document_processor_service/get_processor.rb",
"snippets/document_processor_service/get_processor_type.rb",
"snippets/document_processor_service/get_processor_version.rb",
"snippets/document_processor_service/import_processor_version.rb",
"snippets/document_processor_service/list_evaluations.rb",
"snippets/document_processor_service/list_processor_types.rb",
"snippets/document_processor_service/list_processor_versions.rb",
Expand Down
5 changes: 5 additions & 0 deletions google-cloud-document_ai-v1beta3/gapic_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
"methods": [
"list_evaluations"
]
},
"ImportProcessorVersion": {
"methods": [
"import_processor_version"
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,103 @@ def list_evaluations request, options = nil
raise ::Google::Cloud::Error.from_error(e)
end

##
# Imports a processor version from source processor version.
#
# @overload import_processor_version(request, options = nil)
# Pass arguments to `import_processor_version` via a request object, either of type
# {::Google::Cloud::DocumentAI::V1beta3::ImportProcessorVersionRequest} or an equivalent Hash.
#
# @param request [::Google::Cloud::DocumentAI::V1beta3::ImportProcessorVersionRequest, ::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.
# @param options [::Gapic::CallOptions, ::Hash]
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
#
# @overload import_processor_version(processor_version_source: nil, parent: nil)
# Pass arguments to `import_processor_version` 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).
#
# @param processor_version_source [::String]
# The source processor version to import from.
# @param parent [::String]
# Required. The destination processor name to create the processor version
# in. Format:
# `projects/{project}/locations/{location}/processors/{processor}`
#
# @yield [response, operation] Access the result along with the RPC operation
# @yieldparam response [::Gapic::Operation]
# @yieldparam operation [::GRPC::ActiveCall::Operation]
#
# @return [::Gapic::Operation]
#
# @raise [::Google::Cloud::Error] if the RPC is aborted.
#
# @example Basic example
# require "google/cloud/document_ai/v1beta3"
#
# # Create a client object. The client can be reused for multiple calls.
# client = Google::Cloud::DocumentAI::V1beta3::DocumentProcessorService::Client.new
#
# # Create a request. To set request fields, pass in keyword arguments.
# request = Google::Cloud::DocumentAI::V1beta3::ImportProcessorVersionRequest.new
#
# # Call the import_processor_version method.
# result = client.import_processor_version 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
#
def import_processor_version request, options = nil
raise ::ArgumentError, "request must be provided" if request.nil?

request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::DocumentAI::V1beta3::ImportProcessorVersionRequest

# Converts hash and nil to an options object
options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

# Customize the options with defaults
metadata = @config.rpcs.import_processor_version.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::DocumentAI::V1beta3::VERSION
metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

header_params = {}
if request.parent
header_params["parent"] = request.parent
end

request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
metadata[:"x-goog-request-params"] ||= request_params_header

options.apply_defaults timeout: @config.rpcs.import_processor_version.timeout,
metadata: metadata,
retry_policy: @config.rpcs.import_processor_version.retry_policy

options.apply_defaults timeout: @config.timeout,
metadata: @config.metadata,
retry_policy: @config.retry_policy

@document_processor_service_stub.call_rpc :import_processor_version, request, options: options do |response, operation|
response = ::Gapic::Operation.new response, @operations_client, options: options
yield response, operation if block_given?
return response
end
rescue ::GRPC::BadStatus => e
raise ::Google::Cloud::Error.from_error(e)
end

##
# Configuration class for the DocumentProcessorService API.
#
Expand Down Expand Up @@ -2547,6 +2644,11 @@ class Rpcs
# @return [::Gapic::Config::Method]
#
attr_reader :list_evaluations
##
# RPC-specific configuration for `import_processor_version`
# @return [::Gapic::Config::Method]
#
attr_reader :import_processor_version

# @private
def initialize parent_rpcs = nil
Expand Down Expand Up @@ -2594,6 +2696,8 @@ def initialize parent_rpcs = nil
@get_evaluation = ::Gapic::Config::Method.new get_evaluation_config
list_evaluations_config = parent_rpcs.list_evaluations if parent_rpcs.respond_to? :list_evaluations
@list_evaluations = ::Gapic::Config::Method.new list_evaluations_config
import_processor_version_config = parent_rpcs.import_processor_version if parent_rpcs.respond_to? :import_processor_version
@import_processor_version = ::Gapic::Config::Method.new import_processor_version_config

yield self if block_given?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,73 @@ def list_evaluations request, options = nil
raise ::Google::Cloud::Error.from_error(e)
end

##
# Imports a processor version from source processor version.
#
# @overload import_processor_version(request, options = nil)
# Pass arguments to `import_processor_version` via a request object, either of type
# {::Google::Cloud::DocumentAI::V1beta3::ImportProcessorVersionRequest} or an equivalent Hash.
#
# @param request [::Google::Cloud::DocumentAI::V1beta3::ImportProcessorVersionRequest, ::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.
# @param options [::Gapic::CallOptions, ::Hash]
# Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
#
# @overload import_processor_version(processor_version_source: nil, parent: nil)
# Pass arguments to `import_processor_version` 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).
#
# @param processor_version_source [::String]
# The source processor version to import from.
# @param parent [::String]
# Required. The destination processor name to create the processor version
# in. Format:
# `projects/{project}/locations/{location}/processors/{processor}`
# @yield [result, operation] Access the result along with the TransportOperation object
# @yieldparam result [::Gapic::Operation]
# @yieldparam operation [::Gapic::Rest::TransportOperation]
#
# @return [::Gapic::Operation]
#
# @raise [::Google::Cloud::Error] if the REST call is aborted.
def import_processor_version request, options = nil
raise ::ArgumentError, "request must be provided" if request.nil?

request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::DocumentAI::V1beta3::ImportProcessorVersionRequest

# Converts hash and nil to an options object
options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

# Customize the options with defaults
call_metadata = @config.rpcs.import_processor_version.metadata.to_h

# Set x-goog-api-client and x-goog-user-project headers
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
lib_name: @config.lib_name, lib_version: @config.lib_version,
gapic_version: ::Google::Cloud::DocumentAI::V1beta3::VERSION,
transports_version_send: [:rest]

call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

options.apply_defaults timeout: @config.rpcs.import_processor_version.timeout,
metadata: call_metadata,
retry_policy: @config.rpcs.import_processor_version.retry_policy

options.apply_defaults timeout: @config.timeout,
metadata: @config.metadata,
retry_policy: @config.retry_policy

@document_processor_service_stub.import_processor_version request, options do |result, operation|
result = ::Gapic::Operation.new result, @operations_client, options: options
yield result, operation if block_given?
return result
end
rescue ::Gapic::Rest::Error => e
raise ::Google::Cloud::Error.from_error(e)
end

##
# Configuration class for the DocumentProcessorService REST API.
#
Expand Down Expand Up @@ -1935,6 +2002,11 @@ class Rpcs
# @return [::Gapic::Config::Method]
#
attr_reader :list_evaluations
##
# RPC-specific configuration for `import_processor_version`
# @return [::Gapic::Config::Method]
#
attr_reader :import_processor_version

# @private
def initialize parent_rpcs = nil
Expand Down Expand Up @@ -1982,6 +2054,8 @@ def initialize parent_rpcs = nil
@get_evaluation = ::Gapic::Config::Method.new get_evaluation_config
list_evaluations_config = parent_rpcs.list_evaluations if parent_rpcs.respond_to? :list_evaluations
@list_evaluations = ::Gapic::Config::Method.new list_evaluations_config
import_processor_version_config = parent_rpcs.import_processor_version if parent_rpcs.respond_to? :import_processor_version
@import_processor_version = ::Gapic::Config::Method.new import_processor_version_config

yield self if block_given?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,44 @@ def list_evaluations request_pb, options = nil
result
end

##
# Baseline implementation for the import_processor_version REST call
#
# @param request_pb [::Google::Cloud::DocumentAI::V1beta3::ImportProcessorVersionRequest]
# A request object representing the call parameters. Required.
# @param options [::Gapic::CallOptions]
# Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
#
# @yield [result, operation] Access the result along with the TransportOperation object
# @yieldparam result [::Google::Longrunning::Operation]
# @yieldparam operation [::Gapic::Rest::TransportOperation]
#
# @return [::Google::Longrunning::Operation]
# A result object deserialized from the server's reply
def import_processor_version request_pb, options = nil
raise ::ArgumentError, "request must be provided" if request_pb.nil?

verb, uri, query_string_params, body = ServiceStub.transcode_import_processor_version_request request_pb
query_string_params = if query_string_params.any?
query_string_params.to_h { |p| p.split("=", 2) }
else
{}
end

response = @client_stub.make_http_request(
verb,
uri: uri,
body: body || "",
params: query_string_params,
options: options
)
operation = ::Gapic::Rest::TransportOperation.new response
result = ::Google::Longrunning::Operation.decode_json response.body, ignore_unknown_fields: true

yield result, operation if block_given?
result
end

##
# @private
#
Expand Down Expand Up @@ -1364,6 +1402,28 @@ def self.transcode_list_evaluations_request request_pb
)
transcoder.transcode request_pb
end

##
# @private
#
# GRPC transcoding helper method for the import_processor_version REST call
#
# @param request_pb [::Google::Cloud::DocumentAI::V1beta3::ImportProcessorVersionRequest]
# A request object representing the call parameters. Required.
# @return [Array(String, [String, nil], Hash{String => String})]
# Uri, Body, Query string parameters
def self.transcode_import_processor_version_request request_pb
transcoder = Gapic::Rest::GrpcTranscoder.new
.with_bindings(
uri_method: :post,
uri_template: "/v1beta3/{parent}/processorVersions:importProcessorVersion",
body: "*",
matches: [
["parent", %r{^projects/[^/]+/locations/[^/]+/processors/[^/]+/?$}, false]
]
)
transcoder.transcode request_pb
end
end
end
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9a4e67c

Please sign in to comment.