Skip to content

Commit 37a0e99

Browse files
committed
Add overload methodst
1 parent dcbcc9a commit 37a0e99

File tree

7 files changed

+514
-189
lines changed

7 files changed

+514
-189
lines changed

sdk/maps/azure-maps-route/azure/maps/route/_route_client.py

+74-89
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# license information.
55
# --------------------------------------------------------------------------
66

7-
# pylint: disable=unused-import,ungrouped-imports, R0904, C0302
8-
from typing import Union, Any, List, Tuple
7+
# pylint: disable=unused-import,ungrouped-imports, R0904, C0302, W0212
8+
from typing import Union, Any, List, Tuple, overload
99
from azure.core.tracing.decorator import distributed_trace
1010
from azure.core.credentials import AzureKeyCredential, TokenCredential
1111
from azure.core.polling import LROPoller
@@ -24,6 +24,12 @@
2424
ResponseFormat
2525
)
2626

27+
def get_batch_id_from_poller(polling_method):
28+
if hasattr(polling_method, "_operation"):
29+
operation=polling_method._operation
30+
return operation._location_url.split('/')[-1].split('?')[0]
31+
return None
32+
2733
# By default, use the latest supported API version
2834
class MapsRouteClient(MapsRouteClientBase):
2935
"""Azure Maps Route REST APIs.
@@ -501,73 +507,68 @@ def get_route_directions_batch_sync(
501507
)
502508
return RouteDirectionsBatchResult(summary=result.batch_summary, items=result.batch_items)
503509

504-
@distributed_trace
505-
def begin_route_directions_batch(
510+
@overload
511+
def begin_get_route_directions_batch(
512+
self,
513+
batch_id: str,
514+
**kwargs: Any
515+
) -> LROPoller[RouteDirectionsBatchResult]:
516+
pass
517+
518+
@overload
519+
def begin_get_route_directions_batch(
506520
self,
507521
queries: List[str],
508522
**kwargs: Any
509523
) -> LROPoller[RouteDirectionsBatchResult]:
524+
pass
525+
526+
@distributed_trace
527+
def begin_get_route_directions_batch(
528+
self,
529+
**kwargs: Any
530+
) -> LROPoller[RouteDirectionsBatchResult]:
510531

511532
"""Sends batches of route direction queries.
512533
The method returns a poller for retrieving the result later.
513534
514-
:param queries: The list of route directions queries/requests to
535+
:keyword queries: The list of route directions queries/requests to
515536
process. The list can contain a max of 700 queries for async and 100 queries for sync version
516537
and must contain at least 1 query. Required.
517-
:type queries: List[str]
538+
:paramtype queries: List[str]
539+
:keyword batch_id: Batch id for querying the operation. Required.
540+
:paramtype batch_id: str
518541
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
519542
:keyword polling: By default, your polling method will be LROBasePolling. Pass in False for
520543
this operation to not poll, or pass in your own initialized polling object for a personal
521544
polling strategy.
522-
:paramtype polling: bool or ~azure.core.polling.PollingMethod
545+
:paramtype polling: bool
523546
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
524547
Retry-After header is present.
525548
:return: An instance of LROPoller that returns RouteDirectionsBatchResult
526549
:rtype: ~azure.core.polling.LROPoller[RouteDirectionsBatchResult]
527550
:raises ~azure.core.exceptions.HttpResponseError:
528551
"""
552+
queries=kwargs.pop('queries', None)
553+
batch_id=kwargs.pop('batch_id', None)
554+
555+
if batch_id:
556+
poller = self._route_client.begin_get_route_directions_batch(
557+
format=ResponseFormat.JSON,
558+
batch_id=batch_id,
559+
**kwargs
560+
)
561+
return poller
562+
529563
batch_items = [{"query": f"?query={query}"} for query
530564
in queries] if queries else []
531-
532-
poller = self._route_client.begin_request_route_directions_batch(
565+
batch_poller = self._route_client.begin_request_route_directions_batch(
533566
format=ResponseFormat.JSON,
534567
route_directions_batch_queries={"batch_items": batch_items},
535568
**kwargs
536569
)
537-
return poller
538-
539-
540-
@distributed_trace
541-
def get_route_directions_batch(
542-
self,
543-
batch_id: str,
544-
**kwargs: Any
545-
)-> LROPoller[RouteDirectionsBatchResult]:
546-
547-
"""Retrieves the result of a previous route direction batch request.
548-
The method returns a poller for retrieving the result.
549-
550-
:param batch_id: Batch id for querying the operation. Required.
551-
:type batch_id: str
552-
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
553-
:keyword polling: By default, your polling method will be LROBasePolling. Pass in False for
554-
this operation to not poll, or pass in your own initialized polling object for a personal
555-
polling strategy.
556-
:paramtype polling: bool or ~azure.core.polling.PollingMethod
557-
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
558-
Retry-After header is present.
559-
:return: An instance of LROPoller that returns RouteDirectionsBatchResult
560-
:rtype: ~azure.core.polling.LROPoller[RouteDirectionsBatchResult]
561-
:raises ~azure.core.exceptions.HttpResponseError:
562-
"""
563-
564-
poller = self._route_client.begin_get_route_directions_batch(
565-
format=ResponseFormat.JSON,
566-
batch_id=batch_id,
567-
**kwargs
568-
)
569-
return poller
570-
570+
batch_poller.batch_id = get_batch_id_from_poller(batch_poller.polling_method())
571+
return batch_poller
571572

572573
@distributed_trace
573574
def get_route_matrix(
@@ -589,9 +590,6 @@ def get_route_matrix(
589590
**100** for sync respectively. For example, it can be 35 origins and 20 destinations or 25
590591
origins and 25 destinations for async API. Is either a model type or a IO type. Required.
591592
:type query: ~azure.maps.route.models.RouteMatrixQuery or IO
592-
:param format: Desired format of the response. Only ``json`` format is supported. "json"
593-
Default value is "json".
594-
:type format: str or ~azure.maps.route.models.JsonFormat
595593
:keyword wait_for_results: Boolean to indicate whether to execute the request synchronously. If
596594
set to true, user will get a 200 response if the request is finished under 120 seconds.
597595
Otherwise, user will get a 202 response right away. Please refer to the API description for
@@ -687,11 +685,25 @@ def get_route_matrix(
687685
**kwargs
688686
)
689687

688+
@overload
689+
def begin_get_route_matrix_batch(
690+
self,
691+
query: RouteMatrixQuery,
692+
**kwargs: Any
693+
) -> LROPoller[RouteMatrixResult]:
694+
pass
695+
696+
@overload
697+
def begin_get_route_matrix_batch(
698+
self,
699+
matrix_id: str,
700+
**kwargs: Any
701+
) -> LROPoller[RouteMatrixResult]:
702+
pass
690703

691704
@distributed_trace
692-
def begin_route_matrix_batch(
705+
def begin_get_route_matrix_batch(
693706
self,
694-
query: RouteMatrixQuery,
695707
**kwargs: Any
696708
) -> LROPoller[RouteMatrixResult]:
697709

@@ -702,15 +714,15 @@ def begin_route_matrix_batch(
702714
The maximum size of a matrix for this method is 700
703715
(the number of origins multiplied by the number of destinations)
704716
705-
:param query: The matrix of origin and destination coordinates to compute the
717+
:keyword query: The matrix of origin and destination coordinates to compute the
706718
route distance, travel time and other summary for each cell of the matrix based on the input
707719
parameters. The minimum and the maximum cell count supported are 1 and **700** for async and
708720
**100** for sync respectively. For example, it can be 35 origins and 20 destinations or 25
709721
origins and 25 destinations for async API. Required.
710-
:type query: ~azure.maps.route.models.RouteMatrixQuery
711-
:param format: Desired format of the response. Only ``json`` format is supported. "json"
712-
Default value is "json".
713-
:type format: str or ~azure.maps.route.models.JsonFormat
722+
:paramtype query: ~azure.maps.route.models.RouteMatrixQuery
723+
:keyword matrix_id: Matrix id received after the Matrix Route request was accepted successfully.
724+
Required.
725+
:paramtype matrix_id: str
714726
:keyword wait_for_results: Boolean to indicate whether to execute the request synchronously. If
715727
set to true, user will get a 200 response if the request is finished under 120 seconds.
716728
Otherwise, user will get a 202 response right away. Please refer to the API description for
@@ -800,52 +812,25 @@ def begin_route_matrix_batch(
800812
:keyword polling: By default, your polling method will be LROBasePolling. Pass in False for
801813
this operation to not poll, or pass in your own initialized polling object for a personal
802814
polling strategy.
803-
:paramtype polling: bool or ~azure.core.polling.PollingMethod
815+
:paramtype polling: bool
804816
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
805817
Retry-After header is present.
806818
:return: An instance of LROPoller that returns RouteMatrixResult
807819
:rtype: ~azure.core.polling.LROPoller[~azure.maps.route.models.RouteMatrixResult]
808820
:raises ~azure.core.exceptions.HttpResponseError:
809821
"""
822+
query=kwargs.pop('query', None)
823+
matrix_id = kwargs.pop('matrix_id', None)
824+
825+
if matrix_id:
826+
return self._route_client.begin_get_route_matrix(
827+
matrix_id=matrix_id,
828+
**kwargs
829+
)
810830

811831
poller = self._route_client.begin_request_route_matrix(
812832
format=ResponseFormat.JSON,
813833
route_matrix_query=query,
814834
**kwargs
815835
)
816836
return poller
817-
818-
819-
@distributed_trace
820-
def get_route_matrix_batch(
821-
self,
822-
matrix_id: str,
823-
**kwargs: Any
824-
) -> LROPoller[RouteMatrixResult]:
825-
826-
"""If the Matrix Route request was accepted successfully, the Location header in the response
827-
contains the URL to download the results of the request.
828-
829-
Retrieves the result of a previous route matrix request.
830-
The method returns a poller for retrieving the result.
831-
832-
:param matrix_id: Matrix id received after the Matrix Route request was accepted successfully.
833-
Required.
834-
:type matrix_id: str
835-
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
836-
:keyword polling: By default, your polling method will be LROBasePolling. Pass in False for
837-
this operation to not poll, or pass in your own initialized polling object for a personal
838-
polling strategy.
839-
:paramtype polling: bool or ~azure.core.polling.PollingMethod
840-
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
841-
Retry-After header is present.
842-
:return: An instance of LROPoller that returns RouteMatrixResult
843-
:rtype: ~azure.core.polling.LROPoller[~azure.maps.route.models.RouteMatrixResult]
844-
:raises ~azure.core.exceptions.HttpResponseError:
845-
"""
846-
poller = self._route_client.begin_get_route_matrix(
847-
matrix_id=matrix_id,
848-
**kwargs
849-
)
850-
851-
return poller

0 commit comments

Comments
 (0)