Skip to content

Commit

Permalink
feat(v1): exposed GetProcessorType (#446)
Browse files Browse the repository at this point in the history
* feat: exposed GetProcessorType to v1

PiperOrigin-RevId: 502624243

Source-Link: googleapis/googleapis@bd5f934

Source-Link: googleapis/googleapis-gen@7ae8a3a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiN2FlOGEzYTk3NTVmNjYxY2U4OTg5ZTlkY2IxNDVkMmRmZjc3ZDg2NCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored Jan 17, 2023
1 parent 2442a0f commit cd82f8d
Show file tree
Hide file tree
Showing 17 changed files with 856 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
FetchProcessorTypesRequest,
FetchProcessorTypesResponse,
GetProcessorRequest,
GetProcessorTypeRequest,
GetProcessorVersionRequest,
HumanReviewStatus,
ListProcessorsRequest,
Expand Down Expand Up @@ -116,6 +117,7 @@
"FetchProcessorTypesRequest",
"FetchProcessorTypesResponse",
"GetProcessorRequest",
"GetProcessorTypeRequest",
"GetProcessorVersionRequest",
"HumanReviewStatus",
"ListProcessorsRequest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
FetchProcessorTypesRequest,
FetchProcessorTypesResponse,
GetProcessorRequest,
GetProcessorTypeRequest,
GetProcessorVersionRequest,
HumanReviewStatus,
ListProcessorsRequest,
Expand Down Expand Up @@ -112,6 +113,7 @@
"GcsDocuments",
"GcsPrefix",
"GetProcessorRequest",
"GetProcessorTypeRequest",
"GetProcessorVersionRequest",
"HumanReviewStatus",
"ListProcessorTypesRequest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"get_processor"
]
},
"GetProcessorType": {
"methods": [
"get_processor_type"
]
},
"GetProcessorVersion": {
"methods": [
"get_processor_version"
Expand Down Expand Up @@ -145,6 +150,11 @@
"get_processor"
]
},
"GetProcessorType": {
"methods": [
"get_processor_type"
]
},
"GetProcessorVersion": {
"methods": [
"get_processor_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
except AttributeError: # pragma: NO COVER
OptionalRetry = Union[retries.Retry, object] # type: ignore

from google.api import launch_stage_pb2 # type: ignore
from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.location import locations_pb2 # type: ignore
Expand Down Expand Up @@ -746,6 +747,111 @@ async def sample_list_processor_types():
# Done; return the response.
return response

async def get_processor_type(
self,
request: Optional[
Union[document_processor_service.GetProcessorTypeRequest, dict]
] = None,
*,
name: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> processor_type.ProcessorType:
r"""Gets a processor type detail.
.. code-block:: python
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import documentai_v1
async def sample_get_processor_type():
# Create a client
client = documentai_v1.DocumentProcessorServiceAsyncClient()
# Initialize request argument(s)
request = documentai_v1.GetProcessorTypeRequest(
name="name_value",
)
# Make the request
response = await client.get_processor_type(request=request)
# Handle the response
print(response)
Args:
request (Optional[Union[google.cloud.documentai_v1.types.GetProcessorTypeRequest, dict]]):
The request object. Request message for get processor.
name (:class:`str`):
Required. The processor type resource
name.
This corresponds to the ``name`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.cloud.documentai_v1.types.ProcessorType:
A processor type is responsible for
performing a certain document
understanding task on a certain type of
document.
"""
# Create or coerce a protobuf request object.
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

request = document_processor_service.GetProcessorTypeRequest(request)

# If we have keyword arguments corresponding to fields on the
# request, apply these.
if name is not None:
request.name = name

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_processor_type,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
)

# Send the request.
response = await rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Done; return the response.
return response

async def list_processors(
self,
request: Optional[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
except AttributeError: # pragma: NO COVER
OptionalRetry = Union[retries.Retry, object] # type: ignore

from google.api import launch_stage_pb2 # type: ignore
from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.location import locations_pb2 # type: ignore
Expand Down Expand Up @@ -1000,6 +1001,111 @@ def sample_list_processor_types():
# Done; return the response.
return response

def get_processor_type(
self,
request: Optional[
Union[document_processor_service.GetProcessorTypeRequest, dict]
] = None,
*,
name: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> processor_type.ProcessorType:
r"""Gets a processor type detail.
.. code-block:: python
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import documentai_v1
def sample_get_processor_type():
# Create a client
client = documentai_v1.DocumentProcessorServiceClient()
# Initialize request argument(s)
request = documentai_v1.GetProcessorTypeRequest(
name="name_value",
)
# Make the request
response = client.get_processor_type(request=request)
# Handle the response
print(response)
Args:
request (Union[google.cloud.documentai_v1.types.GetProcessorTypeRequest, dict]):
The request object. Request message for get processor.
name (str):
Required. The processor type resource
name.
This corresponds to the ``name`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.cloud.documentai_v1.types.ProcessorType:
A processor type is responsible for
performing a certain document
understanding task on a certain type of
document.
"""
# Create or coerce a protobuf request object.
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

# Minor optimization to avoid making a copy if the user passes
# in a document_processor_service.GetProcessorTypeRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, document_processor_service.GetProcessorTypeRequest):
request = document_processor_service.GetProcessorTypeRequest(request)
# If we have keyword arguments corresponding to fields on the
# request, apply these.
if name is not None:
request.name = name

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._transport._wrapped_methods[self._transport.get_processor_type]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
)

# Send the request.
response = rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Done; return the response.
return response

def list_processors(
self,
request: Optional[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from google.cloud.documentai_v1.types import document_processor_service
from google.cloud.documentai_v1.types import processor
from google.cloud.documentai_v1.types import processor as gcd_processor
from google.cloud.documentai_v1.types import processor_type

DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=package_version.__version__
Expand Down Expand Up @@ -166,6 +167,11 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=None,
client_info=client_info,
),
self.get_processor_type: gapic_v1.method.wrap_method(
self.get_processor_type,
default_timeout=None,
client_info=client_info,
),
self.list_processors: gapic_v1.method.wrap_method(
self.list_processors,
default_timeout=None,
Expand Down Expand Up @@ -302,6 +308,15 @@ def list_processor_types(
]:
raise NotImplementedError()

@property
def get_processor_type(
self,
) -> Callable[
[document_processor_service.GetProcessorTypeRequest],
Union[processor_type.ProcessorType, Awaitable[processor_type.ProcessorType]],
]:
raise NotImplementedError()

@property
def list_processors(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from google.cloud.documentai_v1.types import document_processor_service
from google.cloud.documentai_v1.types import processor
from google.cloud.documentai_v1.types import processor as gcd_processor
from google.cloud.documentai_v1.types import processor_type

from .base import DEFAULT_CLIENT_INFO, DocumentProcessorServiceTransport

Expand Down Expand Up @@ -368,6 +369,35 @@ def list_processor_types(
)
return self._stubs["list_processor_types"]

@property
def get_processor_type(
self,
) -> Callable[
[document_processor_service.GetProcessorTypeRequest],
processor_type.ProcessorType,
]:
r"""Return a callable for the get processor type method over gRPC.
Gets a processor type detail.
Returns:
Callable[[~.GetProcessorTypeRequest],
~.ProcessorType]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "get_processor_type" not in self._stubs:
self._stubs["get_processor_type"] = self.grpc_channel.unary_unary(
"/google.cloud.documentai.v1.DocumentProcessorService/GetProcessorType",
request_serializer=document_processor_service.GetProcessorTypeRequest.serialize,
response_deserializer=processor_type.ProcessorType.deserialize,
)
return self._stubs["get_processor_type"]

@property
def list_processors(
self,
Expand Down
Loading

0 comments on commit cd82f8d

Please sign in to comment.