4
4
# license information.
5
5
# --------------------------------------------------------------------------
6
6
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
9
9
from azure .core .tracing .decorator import distributed_trace
10
10
from azure .core .credentials import AzureKeyCredential , TokenCredential
11
11
from azure .core .polling import LROPoller
24
24
ResponseFormat
25
25
)
26
26
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
+
27
33
# By default, use the latest supported API version
28
34
class MapsRouteClient (MapsRouteClientBase ):
29
35
"""Azure Maps Route REST APIs.
@@ -501,73 +507,68 @@ def get_route_directions_batch_sync(
501
507
)
502
508
return RouteDirectionsBatchResult (summary = result .batch_summary , items = result .batch_items )
503
509
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 (
506
520
self ,
507
521
queries : List [str ],
508
522
** kwargs : Any
509
523
) -> LROPoller [RouteDirectionsBatchResult ]:
524
+ pass
525
+
526
+ @distributed_trace
527
+ def begin_get_route_directions_batch (
528
+ self ,
529
+ ** kwargs : Any
530
+ ) -> LROPoller [RouteDirectionsBatchResult ]:
510
531
511
532
"""Sends batches of route direction queries.
512
533
The method returns a poller for retrieving the result later.
513
534
514
- :param queries: The list of route directions queries/requests to
535
+ :keyword queries: The list of route directions queries/requests to
515
536
process. The list can contain a max of 700 queries for async and 100 queries for sync version
516
537
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
518
541
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
519
542
:keyword polling: By default, your polling method will be LROBasePolling. Pass in False for
520
543
this operation to not poll, or pass in your own initialized polling object for a personal
521
544
polling strategy.
522
- :paramtype polling: bool or ~azure.core.polling.PollingMethod
545
+ :paramtype polling: bool
523
546
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
524
547
Retry-After header is present.
525
548
:return: An instance of LROPoller that returns RouteDirectionsBatchResult
526
549
:rtype: ~azure.core.polling.LROPoller[RouteDirectionsBatchResult]
527
550
:raises ~azure.core.exceptions.HttpResponseError:
528
551
"""
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
+
529
563
batch_items = [{"query" : f"?query={ query } " } for query
530
564
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 (
533
566
format = ResponseFormat .JSON ,
534
567
route_directions_batch_queries = {"batch_items" : batch_items },
535
568
** kwargs
536
569
)
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
571
572
572
573
@distributed_trace
573
574
def get_route_matrix (
@@ -589,9 +590,6 @@ def get_route_matrix(
589
590
**100** for sync respectively. For example, it can be 35 origins and 20 destinations or 25
590
591
origins and 25 destinations for async API. Is either a model type or a IO type. Required.
591
592
: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
595
593
:keyword wait_for_results: Boolean to indicate whether to execute the request synchronously. If
596
594
set to true, user will get a 200 response if the request is finished under 120 seconds.
597
595
Otherwise, user will get a 202 response right away. Please refer to the API description for
@@ -687,11 +685,25 @@ def get_route_matrix(
687
685
** kwargs
688
686
)
689
687
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
690
703
691
704
@distributed_trace
692
- def begin_route_matrix_batch (
705
+ def begin_get_route_matrix_batch (
693
706
self ,
694
- query : RouteMatrixQuery ,
695
707
** kwargs : Any
696
708
) -> LROPoller [RouteMatrixResult ]:
697
709
@@ -702,15 +714,15 @@ def begin_route_matrix_batch(
702
714
The maximum size of a matrix for this method is 700
703
715
(the number of origins multiplied by the number of destinations)
704
716
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
706
718
route distance, travel time and other summary for each cell of the matrix based on the input
707
719
parameters. The minimum and the maximum cell count supported are 1 and **700** for async and
708
720
**100** for sync respectively. For example, it can be 35 origins and 20 destinations or 25
709
721
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
714
726
:keyword wait_for_results: Boolean to indicate whether to execute the request synchronously. If
715
727
set to true, user will get a 200 response if the request is finished under 120 seconds.
716
728
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(
800
812
:keyword polling: By default, your polling method will be LROBasePolling. Pass in False for
801
813
this operation to not poll, or pass in your own initialized polling object for a personal
802
814
polling strategy.
803
- :paramtype polling: bool or ~azure.core.polling.PollingMethod
815
+ :paramtype polling: bool
804
816
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
805
817
Retry-After header is present.
806
818
:return: An instance of LROPoller that returns RouteMatrixResult
807
819
:rtype: ~azure.core.polling.LROPoller[~azure.maps.route.models.RouteMatrixResult]
808
820
:raises ~azure.core.exceptions.HttpResponseError:
809
821
"""
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
+ )
810
830
811
831
poller = self ._route_client .begin_request_route_matrix (
812
832
format = ResponseFormat .JSON ,
813
833
route_matrix_query = query ,
814
834
** kwargs
815
835
)
816
836
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