Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [google-maps-places] add AutoComplete API #12329

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/google-maps-places/google/maps/places/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from google.maps.places_v1.types.photo import Photo
from google.maps.places_v1.types.place import Place, PriceLevel
from google.maps.places_v1.types.places_service import (
AutocompletePlacesRequest,
AutocompletePlacesResponse,
GetPhotoMediaRequest,
GetPlaceRequest,
PhotoMedia,
Expand All @@ -48,6 +50,8 @@
"Photo",
"Place",
"PriceLevel",
"AutocompletePlacesRequest",
"AutocompletePlacesResponse",
"GetPhotoMediaRequest",
"GetPlaceRequest",
"PhotoMedia",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from .types.photo import Photo
from .types.place import Place, PriceLevel
from .types.places_service import (
AutocompletePlacesRequest,
AutocompletePlacesResponse,
GetPhotoMediaRequest,
GetPlaceRequest,
PhotoMedia,
Expand All @@ -39,6 +41,8 @@
__all__ = (
"PlacesAsyncClient",
"AuthorAttribution",
"AutocompletePlacesRequest",
"AutocompletePlacesResponse",
"Circle",
"EVChargeOptions",
"EVConnectorType",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"grpc": {
"libraryClient": "PlacesClient",
"rpcs": {
"AutocompletePlaces": {
"methods": [
"autocomplete_places"
]
},
"GetPhotoMedia": {
"methods": [
"get_photo_media"
Expand All @@ -35,6 +40,11 @@
"grpc-async": {
"libraryClient": "PlacesAsyncClient",
"rpcs": {
"AutocompletePlaces": {
"methods": [
"autocomplete_places"
]
},
"GetPhotoMedia": {
"methods": [
"get_photo_media"
Expand All @@ -60,6 +70,11 @@
"rest": {
"libraryClient": "PlacesClient",
"rpcs": {
"AutocompletePlaces": {
"methods": [
"autocomplete_places"
]
},
"GetPhotoMedia": {
"methods": [
"get_photo_media"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ async def get_place(
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> place.Place:
r"""Get place details with a place id (in a name) string.
r"""Get the details of a place based on its resource name, which is
a string in the ``places/{place_id}`` format.

.. code-block:: python

Expand Down Expand Up @@ -563,12 +564,11 @@ async def sample_get_place():

Args:
request (Optional[Union[google.maps.places_v1.types.GetPlaceRequest, dict]]):
The request object. Request for fetching a Place with a
place id (in a name) string.
The request object. Request for fetching a Place based on its resource name,
which is a string in the ``places/{place_id}`` format.
name (:class:`str`):
Required. A place ID returned in a Place (with "places/"
prefix), or equivalently the name in the same Place.
Format: ``places/{place_id}``.
Required. The resource name of a place, in the
``places/{place_id}`` format.

This corresponds to the ``name`` field
on the ``request`` instance; if ``request`` is provided, this
Expand Down Expand Up @@ -630,6 +630,82 @@ async def sample_get_place():
# Done; return the response.
return response

async def autocomplete_places(
self,
request: Optional[Union[places_service.AutocompletePlacesRequest, dict]] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> places_service.AutocompletePlacesResponse:
r"""Returns predictions for the given input.

.. 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.maps import places_v1

async def sample_autocomplete_places():
# Create a client
client = places_v1.PlacesAsyncClient()

# Initialize request argument(s)
request = places_v1.AutocompletePlacesRequest(
input="input_value",
)

# Make the request
response = await client.autocomplete_places(request=request)

# Handle the response
print(response)

Args:
request (Optional[Union[google.maps.places_v1.types.AutocompletePlacesRequest, dict]]):
The request object. Request proto for AutocompletePlaces.
retry (google.api_core.retry_async.AsyncRetry): 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.maps.places_v1.types.AutocompletePlacesResponse:
Response proto for
AutocompletePlaces.

"""
# Create or coerce a protobuf request object.
request = places_service.AutocompletePlacesRequest(request)

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

# Validate the universe domain.
self._client._validate_universe_domain()

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

# Done; return the response.
return response

async def __aenter__(self) -> "PlacesAsyncClient":
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,8 @@ def get_place(
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> place.Place:
r"""Get place details with a place id (in a name) string.
r"""Get the details of a place based on its resource name, which is
a string in the ``places/{place_id}`` format.

.. code-block:: python

Expand Down Expand Up @@ -1023,12 +1024,11 @@ def sample_get_place():

Args:
request (Union[google.maps.places_v1.types.GetPlaceRequest, dict]):
The request object. Request for fetching a Place with a
place id (in a name) string.
The request object. Request for fetching a Place based on its resource name,
which is a string in the ``places/{place_id}`` format.
name (str):
Required. A place ID returned in a Place (with "places/"
prefix), or equivalently the name in the same Place.
Format: ``places/{place_id}``.
Required. The resource name of a place, in the
``places/{place_id}`` format.

This corresponds to the ``name`` field
on the ``request`` instance; if ``request`` is provided, this
Expand Down Expand Up @@ -1090,6 +1090,83 @@ def sample_get_place():
# Done; return the response.
return response

def autocomplete_places(
self,
request: Optional[Union[places_service.AutocompletePlacesRequest, dict]] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> places_service.AutocompletePlacesResponse:
r"""Returns predictions for the given input.

.. 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.maps import places_v1

def sample_autocomplete_places():
# Create a client
client = places_v1.PlacesClient()

# Initialize request argument(s)
request = places_v1.AutocompletePlacesRequest(
input="input_value",
)

# Make the request
response = client.autocomplete_places(request=request)

# Handle the response
print(response)

Args:
request (Union[google.maps.places_v1.types.AutocompletePlacesRequest, dict]):
The request object. Request proto for AutocompletePlaces.
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.maps.places_v1.types.AutocompletePlacesResponse:
Response proto for
AutocompletePlaces.

"""
# Create or coerce a protobuf request object.
# Minor optimization to avoid making a copy if the user passes
# in a places_service.AutocompletePlacesRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, places_service.AutocompletePlacesRequest):
request = places_service.AutocompletePlacesRequest(request)

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

# Validate the universe domain.
self._validate_universe_domain()

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

# Done; return the response.
return response

def __enter__(self) -> "PlacesClient":
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=None,
client_info=client_info,
),
self.autocomplete_places: gapic_v1.method.wrap_method(
self.autocomplete_places,
default_timeout=None,
client_info=client_info,
),
}

def close(self):
Expand Down Expand Up @@ -198,6 +203,18 @@ def get_place(
]:
raise NotImplementedError()

@property
def autocomplete_places(
self,
) -> Callable[
[places_service.AutocompletePlacesRequest],
Union[
places_service.AutocompletePlacesResponse,
Awaitable[places_service.AutocompletePlacesResponse],
],
]:
raise NotImplementedError()

@property
def kind(self) -> str:
raise NotImplementedError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ def get_photo_media(
def get_place(self) -> Callable[[places_service.GetPlaceRequest], place.Place]:
r"""Return a callable for the get place method over gRPC.

Get place details with a place id (in a name) string.
Get the details of a place based on its resource name, which is
a string in the ``places/{place_id}`` format.

Returns:
Callable[[~.GetPlaceRequest],
Expand All @@ -338,6 +339,35 @@ def get_place(self) -> Callable[[places_service.GetPlaceRequest], place.Place]:
)
return self._stubs["get_place"]

@property
def autocomplete_places(
self,
) -> Callable[
[places_service.AutocompletePlacesRequest],
places_service.AutocompletePlacesResponse,
]:
r"""Return a callable for the autocomplete places method over gRPC.

Returns predictions for the given input.

Returns:
Callable[[~.AutocompletePlacesRequest],
~.AutocompletePlacesResponse]:
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 "autocomplete_places" not in self._stubs:
self._stubs["autocomplete_places"] = self.grpc_channel.unary_unary(
"/google.maps.places.v1.Places/AutocompletePlaces",
request_serializer=places_service.AutocompletePlacesRequest.serialize,
response_deserializer=places_service.AutocompletePlacesResponse.deserialize,
)
return self._stubs["autocomplete_places"]

def close(self):
self.grpc_channel.close()

Expand Down