google-maps-routeoptimization 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/maps/routeoptimization/__init__.py +85 -0
- google/maps/routeoptimization/gapic_version.py +16 -0
- google/maps/routeoptimization/py.typed +2 -0
- google/maps/routeoptimization_v1/__init__.py +83 -0
- google/maps/routeoptimization_v1/gapic_metadata.json +58 -0
- google/maps/routeoptimization_v1/gapic_version.py +16 -0
- google/maps/routeoptimization_v1/py.typed +2 -0
- google/maps/routeoptimization_v1/services/__init__.py +15 -0
- google/maps/routeoptimization_v1/services/route_optimization/__init__.py +22 -0
- google/maps/routeoptimization_v1/services/route_optimization/async_client.py +588 -0
- google/maps/routeoptimization_v1/services/route_optimization/client.py +992 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/__init__.py +36 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/base.py +200 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/grpc.py +381 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/grpc_asyncio.py +408 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/rest.py +631 -0
- google/maps/routeoptimization_v1/types/__init__.py +72 -0
- google/maps/routeoptimization_v1/types/route_optimization_service.py +4029 -0
- google_maps_routeoptimization-0.1.0.dist-info/LICENSE +202 -0
- google_maps_routeoptimization-0.1.0.dist-info/METADATA +137 -0
- google_maps_routeoptimization-0.1.0.dist-info/RECORD +23 -0
- google_maps_routeoptimization-0.1.0.dist-info/WHEEL +5 -0
- google_maps_routeoptimization-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2024 Google LLC
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
from collections import OrderedDict
|
|
17
|
+
from typing import Dict, Type
|
|
18
|
+
|
|
19
|
+
from .base import RouteOptimizationTransport
|
|
20
|
+
from .grpc import RouteOptimizationGrpcTransport
|
|
21
|
+
from .grpc_asyncio import RouteOptimizationGrpcAsyncIOTransport
|
|
22
|
+
from .rest import RouteOptimizationRestInterceptor, RouteOptimizationRestTransport
|
|
23
|
+
|
|
24
|
+
# Compile a registry of transports.
|
|
25
|
+
_transport_registry = OrderedDict() # type: Dict[str, Type[RouteOptimizationTransport]]
|
|
26
|
+
_transport_registry["grpc"] = RouteOptimizationGrpcTransport
|
|
27
|
+
_transport_registry["grpc_asyncio"] = RouteOptimizationGrpcAsyncIOTransport
|
|
28
|
+
_transport_registry["rest"] = RouteOptimizationRestTransport
|
|
29
|
+
|
|
30
|
+
__all__ = (
|
|
31
|
+
"RouteOptimizationTransport",
|
|
32
|
+
"RouteOptimizationGrpcTransport",
|
|
33
|
+
"RouteOptimizationGrpcAsyncIOTransport",
|
|
34
|
+
"RouteOptimizationRestTransport",
|
|
35
|
+
"RouteOptimizationRestInterceptor",
|
|
36
|
+
)
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2024 Google LLC
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
import abc
|
|
17
|
+
from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
|
|
18
|
+
|
|
19
|
+
import google.api_core
|
|
20
|
+
from google.api_core import exceptions as core_exceptions
|
|
21
|
+
from google.api_core import gapic_v1, operations_v1
|
|
22
|
+
from google.api_core import retry as retries
|
|
23
|
+
import google.auth # type: ignore
|
|
24
|
+
from google.auth import credentials as ga_credentials # type: ignore
|
|
25
|
+
from google.longrunning import operations_pb2 # type: ignore
|
|
26
|
+
from google.oauth2 import service_account # type: ignore
|
|
27
|
+
|
|
28
|
+
from google.maps.routeoptimization_v1 import gapic_version as package_version
|
|
29
|
+
from google.maps.routeoptimization_v1.types import route_optimization_service
|
|
30
|
+
|
|
31
|
+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
|
|
32
|
+
gapic_version=package_version.__version__
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class RouteOptimizationTransport(abc.ABC):
|
|
37
|
+
"""Abstract transport class for RouteOptimization."""
|
|
38
|
+
|
|
39
|
+
AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",)
|
|
40
|
+
|
|
41
|
+
DEFAULT_HOST: str = "routeoptimization.googleapis.com"
|
|
42
|
+
|
|
43
|
+
def __init__(
|
|
44
|
+
self,
|
|
45
|
+
*,
|
|
46
|
+
host: str = DEFAULT_HOST,
|
|
47
|
+
credentials: Optional[ga_credentials.Credentials] = None,
|
|
48
|
+
credentials_file: Optional[str] = None,
|
|
49
|
+
scopes: Optional[Sequence[str]] = None,
|
|
50
|
+
quota_project_id: Optional[str] = None,
|
|
51
|
+
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
|
|
52
|
+
always_use_jwt_access: Optional[bool] = False,
|
|
53
|
+
api_audience: Optional[str] = None,
|
|
54
|
+
**kwargs,
|
|
55
|
+
) -> None:
|
|
56
|
+
"""Instantiate the transport.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
host (Optional[str]):
|
|
60
|
+
The hostname to connect to (default: 'routeoptimization.googleapis.com').
|
|
61
|
+
credentials (Optional[google.auth.credentials.Credentials]): The
|
|
62
|
+
authorization credentials to attach to requests. These
|
|
63
|
+
credentials identify the application to the service; if none
|
|
64
|
+
are specified, the client will attempt to ascertain the
|
|
65
|
+
credentials from the environment.
|
|
66
|
+
credentials_file (Optional[str]): A file with credentials that can
|
|
67
|
+
be loaded with :func:`google.auth.load_credentials_from_file`.
|
|
68
|
+
This argument is mutually exclusive with credentials.
|
|
69
|
+
scopes (Optional[Sequence[str]]): A list of scopes.
|
|
70
|
+
quota_project_id (Optional[str]): An optional project to use for billing
|
|
71
|
+
and quota.
|
|
72
|
+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
|
|
73
|
+
The client info used to send a user-agent string along with
|
|
74
|
+
API requests. If ``None``, then default info will be used.
|
|
75
|
+
Generally, you only need to set this if you're developing
|
|
76
|
+
your own client library.
|
|
77
|
+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
|
|
78
|
+
be used for service account credentials.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
|
|
82
|
+
|
|
83
|
+
# Save the scopes.
|
|
84
|
+
self._scopes = scopes
|
|
85
|
+
|
|
86
|
+
# If no credentials are provided, then determine the appropriate
|
|
87
|
+
# defaults.
|
|
88
|
+
if credentials and credentials_file:
|
|
89
|
+
raise core_exceptions.DuplicateCredentialArgs(
|
|
90
|
+
"'credentials_file' and 'credentials' are mutually exclusive"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
if credentials_file is not None:
|
|
94
|
+
credentials, _ = google.auth.load_credentials_from_file(
|
|
95
|
+
credentials_file, **scopes_kwargs, quota_project_id=quota_project_id
|
|
96
|
+
)
|
|
97
|
+
elif credentials is None:
|
|
98
|
+
credentials, _ = google.auth.default(
|
|
99
|
+
**scopes_kwargs, quota_project_id=quota_project_id
|
|
100
|
+
)
|
|
101
|
+
# Don't apply audience if the credentials file passed from user.
|
|
102
|
+
if hasattr(credentials, "with_gdch_audience"):
|
|
103
|
+
credentials = credentials.with_gdch_audience(
|
|
104
|
+
api_audience if api_audience else host
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
# If the credentials are service account credentials, then always try to use self signed JWT.
|
|
108
|
+
if (
|
|
109
|
+
always_use_jwt_access
|
|
110
|
+
and isinstance(credentials, service_account.Credentials)
|
|
111
|
+
and hasattr(service_account.Credentials, "with_always_use_jwt_access")
|
|
112
|
+
):
|
|
113
|
+
credentials = credentials.with_always_use_jwt_access(True)
|
|
114
|
+
|
|
115
|
+
# Save the credentials.
|
|
116
|
+
self._credentials = credentials
|
|
117
|
+
|
|
118
|
+
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
|
|
119
|
+
if ":" not in host:
|
|
120
|
+
host += ":443"
|
|
121
|
+
self._host = host
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def host(self):
|
|
125
|
+
return self._host
|
|
126
|
+
|
|
127
|
+
def _prep_wrapped_messages(self, client_info):
|
|
128
|
+
# Precompute the wrapped methods.
|
|
129
|
+
self._wrapped_methods = {
|
|
130
|
+
self.optimize_tours: gapic_v1.method.wrap_method(
|
|
131
|
+
self.optimize_tours,
|
|
132
|
+
default_retry=retries.Retry(
|
|
133
|
+
initial=1.0,
|
|
134
|
+
maximum=10.0,
|
|
135
|
+
multiplier=1.3,
|
|
136
|
+
predicate=retries.if_exception_type(
|
|
137
|
+
core_exceptions.ServiceUnavailable,
|
|
138
|
+
),
|
|
139
|
+
deadline=3600.0,
|
|
140
|
+
),
|
|
141
|
+
default_timeout=3600.0,
|
|
142
|
+
client_info=client_info,
|
|
143
|
+
),
|
|
144
|
+
self.batch_optimize_tours: gapic_v1.method.wrap_method(
|
|
145
|
+
self.batch_optimize_tours,
|
|
146
|
+
default_timeout=None,
|
|
147
|
+
client_info=client_info,
|
|
148
|
+
),
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
def close(self):
|
|
152
|
+
"""Closes resources associated with the transport.
|
|
153
|
+
|
|
154
|
+
.. warning::
|
|
155
|
+
Only call this method if the transport is NOT shared
|
|
156
|
+
with other clients - this may cause errors in other clients!
|
|
157
|
+
"""
|
|
158
|
+
raise NotImplementedError()
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def operations_client(self):
|
|
162
|
+
"""Return the client designed to process long-running operations."""
|
|
163
|
+
raise NotImplementedError()
|
|
164
|
+
|
|
165
|
+
@property
|
|
166
|
+
def optimize_tours(
|
|
167
|
+
self,
|
|
168
|
+
) -> Callable[
|
|
169
|
+
[route_optimization_service.OptimizeToursRequest],
|
|
170
|
+
Union[
|
|
171
|
+
route_optimization_service.OptimizeToursResponse,
|
|
172
|
+
Awaitable[route_optimization_service.OptimizeToursResponse],
|
|
173
|
+
],
|
|
174
|
+
]:
|
|
175
|
+
raise NotImplementedError()
|
|
176
|
+
|
|
177
|
+
@property
|
|
178
|
+
def batch_optimize_tours(
|
|
179
|
+
self,
|
|
180
|
+
) -> Callable[
|
|
181
|
+
[route_optimization_service.BatchOptimizeToursRequest],
|
|
182
|
+
Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
|
|
183
|
+
]:
|
|
184
|
+
raise NotImplementedError()
|
|
185
|
+
|
|
186
|
+
@property
|
|
187
|
+
def get_operation(
|
|
188
|
+
self,
|
|
189
|
+
) -> Callable[
|
|
190
|
+
[operations_pb2.GetOperationRequest],
|
|
191
|
+
Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
|
|
192
|
+
]:
|
|
193
|
+
raise NotImplementedError()
|
|
194
|
+
|
|
195
|
+
@property
|
|
196
|
+
def kind(self) -> str:
|
|
197
|
+
raise NotImplementedError()
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
__all__ = ("RouteOptimizationTransport",)
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2024 Google LLC
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
from typing import Callable, Dict, Optional, Sequence, Tuple, Union
|
|
17
|
+
import warnings
|
|
18
|
+
|
|
19
|
+
from google.api_core import gapic_v1, grpc_helpers, operations_v1
|
|
20
|
+
import google.auth # type: ignore
|
|
21
|
+
from google.auth import credentials as ga_credentials # type: ignore
|
|
22
|
+
from google.auth.transport.grpc import SslCredentials # type: ignore
|
|
23
|
+
from google.longrunning import operations_pb2 # type: ignore
|
|
24
|
+
import grpc # type: ignore
|
|
25
|
+
|
|
26
|
+
from google.maps.routeoptimization_v1.types import route_optimization_service
|
|
27
|
+
|
|
28
|
+
from .base import DEFAULT_CLIENT_INFO, RouteOptimizationTransport
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class RouteOptimizationGrpcTransport(RouteOptimizationTransport):
|
|
32
|
+
"""gRPC backend transport for RouteOptimization.
|
|
33
|
+
|
|
34
|
+
A service for optimizing vehicle tours.
|
|
35
|
+
|
|
36
|
+
Validity of certain types of fields:
|
|
37
|
+
|
|
38
|
+
- ``google.protobuf.Timestamp``
|
|
39
|
+
|
|
40
|
+
- Times are in Unix time: seconds since
|
|
41
|
+
1970-01-01T00:00:00+00:00.
|
|
42
|
+
- seconds must be in [0, 253402300799], i.e. in
|
|
43
|
+
[1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
|
|
44
|
+
- nanos must be unset or set to 0.
|
|
45
|
+
|
|
46
|
+
- ``google.protobuf.Duration``
|
|
47
|
+
|
|
48
|
+
- seconds must be in [0, 253402300799], i.e. in
|
|
49
|
+
[1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
|
|
50
|
+
- nanos must be unset or set to 0.
|
|
51
|
+
|
|
52
|
+
- ``google.type.LatLng``
|
|
53
|
+
|
|
54
|
+
- latitude must be in [-90.0, 90.0].
|
|
55
|
+
- longitude must be in [-180.0, 180.0].
|
|
56
|
+
- at least one of latitude and longitude must be non-zero.
|
|
57
|
+
|
|
58
|
+
This class defines the same methods as the primary client, so the
|
|
59
|
+
primary client can load the underlying transport implementation
|
|
60
|
+
and call it.
|
|
61
|
+
|
|
62
|
+
It sends protocol buffers over the wire using gRPC (which is built on
|
|
63
|
+
top of HTTP/2); the ``grpcio`` package must be installed.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
_stubs: Dict[str, Callable]
|
|
67
|
+
|
|
68
|
+
def __init__(
|
|
69
|
+
self,
|
|
70
|
+
*,
|
|
71
|
+
host: str = "routeoptimization.googleapis.com",
|
|
72
|
+
credentials: Optional[ga_credentials.Credentials] = None,
|
|
73
|
+
credentials_file: Optional[str] = None,
|
|
74
|
+
scopes: Optional[Sequence[str]] = None,
|
|
75
|
+
channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None,
|
|
76
|
+
api_mtls_endpoint: Optional[str] = None,
|
|
77
|
+
client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
|
|
78
|
+
ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
|
|
79
|
+
client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
|
|
80
|
+
quota_project_id: Optional[str] = None,
|
|
81
|
+
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
|
|
82
|
+
always_use_jwt_access: Optional[bool] = False,
|
|
83
|
+
api_audience: Optional[str] = None,
|
|
84
|
+
) -> None:
|
|
85
|
+
"""Instantiate the transport.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
host (Optional[str]):
|
|
89
|
+
The hostname to connect to (default: 'routeoptimization.googleapis.com').
|
|
90
|
+
credentials (Optional[google.auth.credentials.Credentials]): The
|
|
91
|
+
authorization credentials to attach to requests. These
|
|
92
|
+
credentials identify the application to the service; if none
|
|
93
|
+
are specified, the client will attempt to ascertain the
|
|
94
|
+
credentials from the environment.
|
|
95
|
+
This argument is ignored if a ``channel`` instance is provided.
|
|
96
|
+
credentials_file (Optional[str]): A file with credentials that can
|
|
97
|
+
be loaded with :func:`google.auth.load_credentials_from_file`.
|
|
98
|
+
This argument is ignored if a ``channel`` instance is provided.
|
|
99
|
+
scopes (Optional(Sequence[str])): A list of scopes. This argument is
|
|
100
|
+
ignored if a ``channel`` instance is provided.
|
|
101
|
+
channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]):
|
|
102
|
+
A ``Channel`` instance through which to make calls, or a Callable
|
|
103
|
+
that constructs and returns one. If set to None, ``self.create_channel``
|
|
104
|
+
is used to create the channel. If a Callable is given, it will be called
|
|
105
|
+
with the same arguments as used in ``self.create_channel``.
|
|
106
|
+
api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
|
|
107
|
+
If provided, it overrides the ``host`` argument and tries to create
|
|
108
|
+
a mutual TLS channel with client SSL credentials from
|
|
109
|
+
``client_cert_source`` or application default SSL credentials.
|
|
110
|
+
client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
|
|
111
|
+
Deprecated. A callback to provide client SSL certificate bytes and
|
|
112
|
+
private key bytes, both in PEM format. It is ignored if
|
|
113
|
+
``api_mtls_endpoint`` is None.
|
|
114
|
+
ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
|
|
115
|
+
for the grpc channel. It is ignored if a ``channel`` instance is provided.
|
|
116
|
+
client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
|
|
117
|
+
A callback to provide client certificate bytes and private key bytes,
|
|
118
|
+
both in PEM format. It is used to configure a mutual TLS channel. It is
|
|
119
|
+
ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
|
|
120
|
+
quota_project_id (Optional[str]): An optional project to use for billing
|
|
121
|
+
and quota.
|
|
122
|
+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
|
|
123
|
+
The client info used to send a user-agent string along with
|
|
124
|
+
API requests. If ``None``, then default info will be used.
|
|
125
|
+
Generally, you only need to set this if you're developing
|
|
126
|
+
your own client library.
|
|
127
|
+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
|
|
128
|
+
be used for service account credentials.
|
|
129
|
+
|
|
130
|
+
Raises:
|
|
131
|
+
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
|
|
132
|
+
creation failed for any reason.
|
|
133
|
+
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
|
|
134
|
+
and ``credentials_file`` are passed.
|
|
135
|
+
"""
|
|
136
|
+
self._grpc_channel = None
|
|
137
|
+
self._ssl_channel_credentials = ssl_channel_credentials
|
|
138
|
+
self._stubs: Dict[str, Callable] = {}
|
|
139
|
+
self._operations_client: Optional[operations_v1.OperationsClient] = None
|
|
140
|
+
|
|
141
|
+
if api_mtls_endpoint:
|
|
142
|
+
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
|
|
143
|
+
if client_cert_source:
|
|
144
|
+
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
|
|
145
|
+
|
|
146
|
+
if isinstance(channel, grpc.Channel):
|
|
147
|
+
# Ignore credentials if a channel was passed.
|
|
148
|
+
credentials = False
|
|
149
|
+
# If a channel was explicitly provided, set it.
|
|
150
|
+
self._grpc_channel = channel
|
|
151
|
+
self._ssl_channel_credentials = None
|
|
152
|
+
|
|
153
|
+
else:
|
|
154
|
+
if api_mtls_endpoint:
|
|
155
|
+
host = api_mtls_endpoint
|
|
156
|
+
|
|
157
|
+
# Create SSL credentials with client_cert_source or application
|
|
158
|
+
# default SSL credentials.
|
|
159
|
+
if client_cert_source:
|
|
160
|
+
cert, key = client_cert_source()
|
|
161
|
+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
|
|
162
|
+
certificate_chain=cert, private_key=key
|
|
163
|
+
)
|
|
164
|
+
else:
|
|
165
|
+
self._ssl_channel_credentials = SslCredentials().ssl_credentials
|
|
166
|
+
|
|
167
|
+
else:
|
|
168
|
+
if client_cert_source_for_mtls and not ssl_channel_credentials:
|
|
169
|
+
cert, key = client_cert_source_for_mtls()
|
|
170
|
+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
|
|
171
|
+
certificate_chain=cert, private_key=key
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
# The base transport sets the host, credentials and scopes
|
|
175
|
+
super().__init__(
|
|
176
|
+
host=host,
|
|
177
|
+
credentials=credentials,
|
|
178
|
+
credentials_file=credentials_file,
|
|
179
|
+
scopes=scopes,
|
|
180
|
+
quota_project_id=quota_project_id,
|
|
181
|
+
client_info=client_info,
|
|
182
|
+
always_use_jwt_access=always_use_jwt_access,
|
|
183
|
+
api_audience=api_audience,
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
if not self._grpc_channel:
|
|
187
|
+
# initialize with the provided callable or the default channel
|
|
188
|
+
channel_init = channel or type(self).create_channel
|
|
189
|
+
self._grpc_channel = channel_init(
|
|
190
|
+
self._host,
|
|
191
|
+
# use the credentials which are saved
|
|
192
|
+
credentials=self._credentials,
|
|
193
|
+
# Set ``credentials_file`` to ``None`` here as
|
|
194
|
+
# the credentials that we saved earlier should be used.
|
|
195
|
+
credentials_file=None,
|
|
196
|
+
scopes=self._scopes,
|
|
197
|
+
ssl_credentials=self._ssl_channel_credentials,
|
|
198
|
+
quota_project_id=quota_project_id,
|
|
199
|
+
options=[
|
|
200
|
+
("grpc.max_send_message_length", -1),
|
|
201
|
+
("grpc.max_receive_message_length", -1),
|
|
202
|
+
],
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
# Wrap messages. This must be done after self._grpc_channel exists
|
|
206
|
+
self._prep_wrapped_messages(client_info)
|
|
207
|
+
|
|
208
|
+
@classmethod
|
|
209
|
+
def create_channel(
|
|
210
|
+
cls,
|
|
211
|
+
host: str = "routeoptimization.googleapis.com",
|
|
212
|
+
credentials: Optional[ga_credentials.Credentials] = None,
|
|
213
|
+
credentials_file: Optional[str] = None,
|
|
214
|
+
scopes: Optional[Sequence[str]] = None,
|
|
215
|
+
quota_project_id: Optional[str] = None,
|
|
216
|
+
**kwargs,
|
|
217
|
+
) -> grpc.Channel:
|
|
218
|
+
"""Create and return a gRPC channel object.
|
|
219
|
+
Args:
|
|
220
|
+
host (Optional[str]): The host for the channel to use.
|
|
221
|
+
credentials (Optional[~.Credentials]): The
|
|
222
|
+
authorization credentials to attach to requests. These
|
|
223
|
+
credentials identify this application to the service. If
|
|
224
|
+
none are specified, the client will attempt to ascertain
|
|
225
|
+
the credentials from the environment.
|
|
226
|
+
credentials_file (Optional[str]): A file with credentials that can
|
|
227
|
+
be loaded with :func:`google.auth.load_credentials_from_file`.
|
|
228
|
+
This argument is mutually exclusive with credentials.
|
|
229
|
+
scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
|
|
230
|
+
service. These are only used when credentials are not specified and
|
|
231
|
+
are passed to :func:`google.auth.default`.
|
|
232
|
+
quota_project_id (Optional[str]): An optional project to use for billing
|
|
233
|
+
and quota.
|
|
234
|
+
kwargs (Optional[dict]): Keyword arguments, which are passed to the
|
|
235
|
+
channel creation.
|
|
236
|
+
Returns:
|
|
237
|
+
grpc.Channel: A gRPC channel object.
|
|
238
|
+
|
|
239
|
+
Raises:
|
|
240
|
+
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
|
|
241
|
+
and ``credentials_file`` are passed.
|
|
242
|
+
"""
|
|
243
|
+
|
|
244
|
+
return grpc_helpers.create_channel(
|
|
245
|
+
host,
|
|
246
|
+
credentials=credentials,
|
|
247
|
+
credentials_file=credentials_file,
|
|
248
|
+
quota_project_id=quota_project_id,
|
|
249
|
+
default_scopes=cls.AUTH_SCOPES,
|
|
250
|
+
scopes=scopes,
|
|
251
|
+
default_host=cls.DEFAULT_HOST,
|
|
252
|
+
**kwargs,
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
@property
|
|
256
|
+
def grpc_channel(self) -> grpc.Channel:
|
|
257
|
+
"""Return the channel designed to connect to this service."""
|
|
258
|
+
return self._grpc_channel
|
|
259
|
+
|
|
260
|
+
@property
|
|
261
|
+
def operations_client(self) -> operations_v1.OperationsClient:
|
|
262
|
+
"""Create the client designed to process long-running operations.
|
|
263
|
+
|
|
264
|
+
This property caches on the instance; repeated calls return the same
|
|
265
|
+
client.
|
|
266
|
+
"""
|
|
267
|
+
# Quick check: Only create a new client if we do not already have one.
|
|
268
|
+
if self._operations_client is None:
|
|
269
|
+
self._operations_client = operations_v1.OperationsClient(self.grpc_channel)
|
|
270
|
+
|
|
271
|
+
# Return the client from cache.
|
|
272
|
+
return self._operations_client
|
|
273
|
+
|
|
274
|
+
@property
|
|
275
|
+
def optimize_tours(
|
|
276
|
+
self,
|
|
277
|
+
) -> Callable[
|
|
278
|
+
[route_optimization_service.OptimizeToursRequest],
|
|
279
|
+
route_optimization_service.OptimizeToursResponse,
|
|
280
|
+
]:
|
|
281
|
+
r"""Return a callable for the optimize tours method over gRPC.
|
|
282
|
+
|
|
283
|
+
Sends an ``OptimizeToursRequest`` containing a ``ShipmentModel``
|
|
284
|
+
and returns an ``OptimizeToursResponse`` containing
|
|
285
|
+
``ShipmentRoute``\ s, which are a set of routes to be performed
|
|
286
|
+
by vehicles minimizing the overall cost.
|
|
287
|
+
|
|
288
|
+
A ``ShipmentModel`` model consists mainly of ``Shipment``\ s
|
|
289
|
+
that need to be carried out and ``Vehicle``\ s that can be used
|
|
290
|
+
to transport the ``Shipment``\ s. The ``ShipmentRoute``\ s
|
|
291
|
+
assign ``Shipment``\ s to ``Vehicle``\ s. More specifically,
|
|
292
|
+
they assign a series of ``Visit``\ s to each vehicle, where a
|
|
293
|
+
``Visit`` corresponds to a ``VisitRequest``, which is a pickup
|
|
294
|
+
or delivery for a ``Shipment``.
|
|
295
|
+
|
|
296
|
+
The goal is to provide an assignment of ``ShipmentRoute``\ s to
|
|
297
|
+
``Vehicle``\ s that minimizes the total cost where cost has many
|
|
298
|
+
components defined in the ``ShipmentModel``.
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
Callable[[~.OptimizeToursRequest],
|
|
302
|
+
~.OptimizeToursResponse]:
|
|
303
|
+
A function that, when called, will call the underlying RPC
|
|
304
|
+
on the server.
|
|
305
|
+
"""
|
|
306
|
+
# Generate a "stub function" on-the-fly which will actually make
|
|
307
|
+
# the request.
|
|
308
|
+
# gRPC handles serialization and deserialization, so we just need
|
|
309
|
+
# to pass in the functions for each.
|
|
310
|
+
if "optimize_tours" not in self._stubs:
|
|
311
|
+
self._stubs["optimize_tours"] = self.grpc_channel.unary_unary(
|
|
312
|
+
"/google.maps.routeoptimization.v1.RouteOptimization/OptimizeTours",
|
|
313
|
+
request_serializer=route_optimization_service.OptimizeToursRequest.serialize,
|
|
314
|
+
response_deserializer=route_optimization_service.OptimizeToursResponse.deserialize,
|
|
315
|
+
)
|
|
316
|
+
return self._stubs["optimize_tours"]
|
|
317
|
+
|
|
318
|
+
@property
|
|
319
|
+
def batch_optimize_tours(
|
|
320
|
+
self,
|
|
321
|
+
) -> Callable[
|
|
322
|
+
[route_optimization_service.BatchOptimizeToursRequest], operations_pb2.Operation
|
|
323
|
+
]:
|
|
324
|
+
r"""Return a callable for the batch optimize tours method over gRPC.
|
|
325
|
+
|
|
326
|
+
Optimizes vehicle tours for one or more ``OptimizeToursRequest``
|
|
327
|
+
messages as a batch.
|
|
328
|
+
|
|
329
|
+
This method is a Long Running Operation (LRO). The inputs for
|
|
330
|
+
optimization (``OptimizeToursRequest`` messages) and outputs
|
|
331
|
+
(``OptimizeToursResponse`` messages) are read/written from/to
|
|
332
|
+
Cloud Storage in user-specified format. Like the
|
|
333
|
+
``OptimizeTours`` method, each ``OptimizeToursRequest`` contains
|
|
334
|
+
a ``ShipmentModel`` and returns an ``OptimizeToursResponse``
|
|
335
|
+
containing ``ShipmentRoute``\ s, which are a set of routes to be
|
|
336
|
+
performed by vehicles minimizing the overall cost.
|
|
337
|
+
|
|
338
|
+
Returns:
|
|
339
|
+
Callable[[~.BatchOptimizeToursRequest],
|
|
340
|
+
~.Operation]:
|
|
341
|
+
A function that, when called, will call the underlying RPC
|
|
342
|
+
on the server.
|
|
343
|
+
"""
|
|
344
|
+
# Generate a "stub function" on-the-fly which will actually make
|
|
345
|
+
# the request.
|
|
346
|
+
# gRPC handles serialization and deserialization, so we just need
|
|
347
|
+
# to pass in the functions for each.
|
|
348
|
+
if "batch_optimize_tours" not in self._stubs:
|
|
349
|
+
self._stubs["batch_optimize_tours"] = self.grpc_channel.unary_unary(
|
|
350
|
+
"/google.maps.routeoptimization.v1.RouteOptimization/BatchOptimizeTours",
|
|
351
|
+
request_serializer=route_optimization_service.BatchOptimizeToursRequest.serialize,
|
|
352
|
+
response_deserializer=operations_pb2.Operation.FromString,
|
|
353
|
+
)
|
|
354
|
+
return self._stubs["batch_optimize_tours"]
|
|
355
|
+
|
|
356
|
+
def close(self):
|
|
357
|
+
self.grpc_channel.close()
|
|
358
|
+
|
|
359
|
+
@property
|
|
360
|
+
def get_operation(
|
|
361
|
+
self,
|
|
362
|
+
) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]:
|
|
363
|
+
r"""Return a callable for the get_operation method over gRPC."""
|
|
364
|
+
# Generate a "stub function" on-the-fly which will actually make
|
|
365
|
+
# the request.
|
|
366
|
+
# gRPC handles serialization and deserialization, so we just need
|
|
367
|
+
# to pass in the functions for each.
|
|
368
|
+
if "get_operation" not in self._stubs:
|
|
369
|
+
self._stubs["get_operation"] = self.grpc_channel.unary_unary(
|
|
370
|
+
"/google.longrunning.Operations/GetOperation",
|
|
371
|
+
request_serializer=operations_pb2.GetOperationRequest.SerializeToString,
|
|
372
|
+
response_deserializer=operations_pb2.Operation.FromString,
|
|
373
|
+
)
|
|
374
|
+
return self._stubs["get_operation"]
|
|
375
|
+
|
|
376
|
+
@property
|
|
377
|
+
def kind(self) -> str:
|
|
378
|
+
return "grpc"
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
__all__ = ("RouteOptimizationGrpcTransport",)
|