From 5b4a77fb9225c46e831c7a602843860f427f85e1 Mon Sep 17 00:00:00 2001 From: Jonathan Perron Date: Tue, 11 Nov 2025 16:56:38 +0100 Subject: [PATCH] fix(api): use request objects in all api clients Changelog * Fix APIs missing usage of request objects * Update documentation * Fix tests --- navitia_client/client/apis/arrival_apis.py | 95 +-- .../client/apis/contributors_apis.py | 52 +- navitia_client/client/apis/coverage_apis.py | 73 +- navitia_client/client/apis/datasets_apis.py | 52 +- navitia_client/client/apis/departure_apis.py | 101 +-- .../client/apis/equipment_report_apis.py | 62 +- .../client/apis/freefloatings_nearby_apis.py | 114 +-- .../client/apis/inverted_geocoding_apis.py | 164 ++-- navitia_client/client/apis/isochrone_apis.py | 64 +- navitia_client/client/apis/journeys_apis.py | 753 +----------------- .../client/apis/line_report_apis.py | 48 +- navitia_client/client/apis/place_apis.py | 36 +- .../client/apis/places_nearby_apis.py | 310 ++----- .../apis/public_transport_objects_apis.py | 44 +- .../client/apis/route_schedules_apis.py | 80 +- .../client/apis/stop_schedules_apis.py | 80 +- .../client/apis/terminus_schedules_apis.py | 80 +- .../client/apis/traffic_report_apis.py | 43 +- .../client/apis/test_equipment_report_apis.py | 7 +- .../apis/test_freefloatings_nearby_apis.py | 12 +- tests/client/apis/test_journeys_apis.py | 22 +- tests/client/apis/test_line_report_apis.py | 3 +- tests/client/apis/test_places_nearby_apis.py | 5 +- tests/client/apis/test_traffic_report_apis.py | 3 +- 24 files changed, 477 insertions(+), 1826 deletions(-) diff --git a/navitia_client/client/apis/arrival_apis.py b/navitia_client/client/apis/arrival_apis.py index bcfc70a..de04ede 100644 --- a/navitia_client/client/apis/arrival_apis.py +++ b/navitia_client/client/apis/arrival_apis.py @@ -6,41 +6,21 @@ class ArrivalApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching arrival information. + """Client class to interact with the Navitia API for fetching arrival information. See https://doc.navitia.io/#arrivals - - Methods - ------- - _get_departure_objects_from_response(response: Any) -> Sequence[Arrival] - A static method to transform raw API response data into a list of Arrival objects. - - _get_departures(url: str, filters: dict) -> Tuple[Sequence[Arrival], Pagination] - Internal method to fetch departures based on a given URL and filters. - - list_arrivals_by_region_id_and_path(region_id: str, resource_path: str, from_datetime: datetime = datetime.now(), duration: int = 86400, depth: int = 1, forbidden_uris: Optional[Sequence[str]] = None, data_freshness: str = "realtime", disable_geojson: bool = False, direction_type: str = "all") -> Tuple[Sequence[Arrival], Pagination] - Retrieves a list of arrivals for a specific region and resource path. - - list_arrivals_by_coordinates(region_lon: float, region_lat: float, lon: float, lat: float, from_datetime: datetime = datetime.now(), duration: int = 86400, depth: int = 1, forbidden_uris: Optional[Sequence[str]] = None, data_freshness: str = "realtime", disable_geojson: bool = False, direction_type: str = "all") -> Tuple[Sequence[Arrival], Pagination] - Retrieves a list of arrivals for specific coordinates. """ @staticmethod def _get_arrival_objects_from_response( response: Any, ) -> Sequence[Arrival]: - """ - Converts raw response data into a list of Arrival objects. + """Convert raw response data into a list of Arrival objects. - Parameters - ---------- - response : Any - The raw response data from the API containing arrivals' information. + Args: + response: The raw response data from the API containing arrivals' information. - Returns - ------- - Sequence[Arrival] + Returns: A list of Arrival objects created from the raw response data. """ @@ -53,19 +33,13 @@ def _get_arrival_objects_from_response( def _get_arrivals( self, url: str, filters: dict ) -> Tuple[Sequence[Arrival], Pagination]: - """ - Internal method to fetch departures based on a given URL and filters. - - Parameters - ---------- - url : str - The URL for the API request. - filters : dict - The filters to apply to the API request. - - Returns - ------- - Tuple[Sequence[Arrival], Pagination] + """Fetch arrivals based on a given URL and filters. + + Args: + url: The URL for the API request. + filters: The filters to apply to the API request. + + Returns: A tuple containing a list of Arrival objects and a Pagination object for managing result pages. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) @@ -79,20 +53,14 @@ def list_arrivals_by_region_id_and_path( resource_path: str, request: ArrivalRequest, ) -> Tuple[Sequence[Arrival], Pagination]: - """ - Retrieves a list of arrivals for a specific region and resource path. - - Parameters - ---------- - region_id : str - The identifier of the region to fetch arrivals from. - resource_path : str - The resource path within the region to fetch arrivals for. + """Retrieve a list of arrivals for a specific region and resource path. + Args: + region_id: The identifier of the region to fetch arrivals from. + resource_path: The resource path within the region to fetch arrivals for. + request: The ArrivalRequest containing filters and parameters for the query. - Returns - ------- - Tuple[Sequence[Arrival], Pagination] + Returns: A tuple containing a list of Arrival objects and a Pagination object for managing result pages. """ request_url = ( @@ -109,23 +77,16 @@ def list_arrivals_by_coordinates( lat: float, request: ArrivalRequest, ) -> Tuple[Sequence[Arrival], Pagination]: - """ - Retrieves a list of arrivals for specific coordinates. - - Parameters - ---------- - region_lon : float - The longitude of the region to fetch arrivals from. - region_lat : float - The latitude of the region to fetch arrivals from. - lon : float - The longitude of the specific location to fetch arrivals for. - lat : float - The latitude of the specific location to fetch arrivals for. - - Returns - ------- - Tuple[Sequence[Arrival], Pagination] + """Retrieve a list of arrivals for specific coordinates. + + Args: + region_lon: The longitude of the region to fetch arrivals from. + region_lat: The latitude of the region to fetch arrivals from. + lon: The longitude of the specific location to fetch arrivals for. + lat: The latitude of the specific location to fetch arrivals for. + request: The ArrivalRequest containing filters and parameters for the query. + + Returns: A tuple containing a list of Arrival objects and a Pagination object for managing result pages. """ # List of objects near the resource, navitia guesses the region from coordinates diff --git a/navitia_client/client/apis/contributors_apis.py b/navitia_client/client/apis/contributors_apis.py index a04a129..d5871d3 100644 --- a/navitia_client/client/apis/contributors_apis.py +++ b/navitia_client/client/apis/contributors_apis.py @@ -7,9 +7,7 @@ class ContributorsApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching contributors APIs. - Uses the ContributorRequest class to encapsulate query parameters. + """Client class to interact with the Navitia API for fetching contributors. See https://doc.navitia.io/#contributors """ @@ -18,17 +16,12 @@ class ContributorsApiClient(ApiBaseClient): def _get_contributors_from_response( raw_contributors_response: Any, ) -> Sequence[Contributor]: - """ - Converts raw response data into a list of Contributor objects. + """Convert raw response data into a list of Contributor objects. - Parameters - ---------- - raw_contributors_response : Any - The raw response data from the API containing contributors' information. + Args: + raw_contributors_response: The raw response data from the API containing contributors' information. - Returns - ------- - Sequence[Contributor] + Returns: A list of Contributor objects created from the raw response data. """ contributors = [] @@ -40,19 +33,13 @@ def _get_contributors_from_response( def list_contributors( self, region_id: str, request: ContributorRequest ) -> Tuple[Sequence[Contributor], Pagination]: - """ - Retrieves a list of contributors for a specific region. + """Retrieve a list of contributors for a specific region. - Parameters - ---------- - region_id : str - The identifier of the region to fetch contributors from. - request : ContributorRequest - The request object containing query parameters (count, start_page). + Args: + region_id: The identifier of the region to fetch contributors from. + request: The request object containing query parameters. - Returns - ------- - Tuple[Sequence[Contributor], Pagination] + Returns: A tuple containing a list of Contributor objects and a Pagination object for managing result pages. """ url = f"{self.base_navitia_url}/coverage/{region_id}/contributors" @@ -68,21 +55,14 @@ def list_contributors( def get_contributor_on_dataset( self, region_id: str, dataset_id: str, request: ContributorRequest ) -> Tuple[Sequence[Contributor], Pagination]: - """ - Retrieves a list of contributors for a specific dataset in a region. + """Retrieve a list of contributors for a specific dataset in a region. - Parameters - ---------- - region_id : str - The identifier of the region to fetch contributors from. - dataset_id : str - The identifier of the dataset to fetch contributors for. - request : ContributorRequest - The request object containing query parameters (count, start_page). + Args: + region_id: The identifier of the region to fetch contributors from. + dataset_id: The identifier of the dataset to fetch contributors for. + request: The request object containing query parameters. - Returns - ------- - Tuple[Sequence[Contributor], Pagination] + Returns: A tuple containing a list of Contributor objects and a Pagination object for managing result pages. """ url = f"{self.base_navitia_url}/coverage/{region_id}/contributors/{dataset_id}" diff --git a/navitia_client/client/apis/coverage_apis.py b/navitia_client/client/apis/coverage_apis.py index c708805..19194c9 100644 --- a/navitia_client/client/apis/coverage_apis.py +++ b/navitia_client/client/apis/coverage_apis.py @@ -7,26 +7,19 @@ class CoverageApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching coverage area information. - Uses the CoverageRequest class to encapsulate query parameters. + """Client class to interact with the Navitia API for fetching coverage area information. See https://doc.navitia.io/#coverage """ @staticmethod def _get_regions_from_response(raw_regions_response: Any) -> Sequence[Region]: - """ - Converts raw response data into a list of Region objects. + """Convert raw response data into a list of Region objects. - Parameters - ---------- - raw_regions_response : Any - The raw response data from the API containing regions' information. + Args: + raw_regions_response: The raw response data from the API containing regions' information. - Returns - ------- - Sequence[Region] + Returns: A list of Region objects created from the raw response data. """ regions = [] @@ -37,17 +30,12 @@ def _get_regions_from_response(raw_regions_response: Any) -> Sequence[Region]: def list_covered_areas( self, request: CoverageRequest ) -> Tuple[Sequence[Region], Pagination]: - """ - Retrieves a list of covered areas from the Navitia API. + """Retrieve a list of covered areas from the Navitia API. - Parameters - ---------- - request : CoverageRequest - The request object containing query parameters (count, start_page). + Args: + request: The request object containing query parameters. - Returns - ------- - Tuple[Sequence[Region], Pagination] + Returns: A tuple containing a list of Region objects and a Pagination object for managing result pages. """ url = f"{self.base_navitia_url}/coverage" @@ -62,19 +50,13 @@ def list_covered_areas( def get_coverage_by_region_id( self, region_id: str, request: CoverageRequest ) -> Tuple[Sequence[Region], Pagination]: - """ - Retrieves information about a specific region by its ID. - - Parameters - ---------- - region_id : str - The identifier of the region to fetch information about. - request : CoverageRequest - The request object containing query parameters (count, start_page). - - Returns - ------- - Tuple[Sequence[Region], Pagination] + """Retrieve information about a specific region by its ID. + + Args: + region_id: The identifier of the region to fetch information about. + request: The request object containing query parameters. + + Returns: A tuple containing a list of Region objects and a Pagination object for managing result pages. """ url = f"{self.base_navitia_url}/coverage/{region_id}" @@ -89,21 +71,14 @@ def get_coverage_by_region_id( def get_coverage_by_region_coordinates_and_coordinates( self, lon: float, lat: float, request: CoverageRequest ) -> Tuple[Sequence[Region], Pagination]: - """ - Retrieves information about a region based on coordinates. - - Parameters - ---------- - lon : float - The longitude of the location to fetch information about. - lat : float - The latitude of the location to fetch information about. - request : CoverageRequest - The request object containing query parameters (count, start_page). - - Returns - ------- - Tuple[Sequence[Region], Pagination] + """Retrieve information about a region based on coordinates. + + Args: + lon: The longitude of the location to fetch information about. + lat: The latitude of the location to fetch information about. + request: The request object containing query parameters. + + Returns: A tuple containing a list of Region objects and a Pagination object for managing result pages. """ url = f"{self.base_navitia_url}/coverage/{lon};{lat}" diff --git a/navitia_client/client/apis/datasets_apis.py b/navitia_client/client/apis/datasets_apis.py index f3a69b4..8b7f12a 100644 --- a/navitia_client/client/apis/datasets_apis.py +++ b/navitia_client/client/apis/datasets_apis.py @@ -7,26 +7,19 @@ class DatasetsApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching dataset information. - Uses the DatasetRequest class to encapsulate query parameters. + """Client class to interact with the Navitia API for fetching dataset information. See https://doc.navitia.io/#datasets """ @staticmethod def _get_datasets_from_response(raw_datasets_response: Any) -> Sequence[Dataset]: - """ - Converts raw response data into a list of Dataset objects. + """Convert raw response data into a list of Dataset objects. - Parameters - ---------- - raw_datasets_response : Any - The raw response data from the API containing datasets' information. + Args: + raw_datasets_response: The raw response data from the API containing datasets' information. - Returns - ------- - Sequence[Dataset] + Returns: A list of Dataset objects created from the raw response data. """ datasets = [] @@ -42,19 +35,13 @@ def _get_datasets_from_response(raw_datasets_response: Any) -> Sequence[Dataset] def list_datasets( self, region_id: str, request: DatasetRequest ) -> Tuple[Sequence[Dataset], Pagination]: - """ - Retrieves a list of datasets for a specified region from the Navitia API. + """Retrieve a list of datasets for a specified region from the Navitia API. - Parameters - ---------- - region_id : str - The identifier of the region to fetch datasets from. - request : DatasetRequest - The request object containing query parameters (count, start_page). + Args: + region_id: The identifier of the region to fetch datasets from. + request: The request object containing query parameters. - Returns - ------- - Tuple[Sequence[Dataset], Pagination] + Returns: A tuple containing a list of Dataset objects and a Pagination object for managing result pages. """ url = f"{self.base_navitia_url}/coverage/{region_id}/datasets" @@ -68,21 +55,14 @@ def list_datasets( def get_dataset_by_id( self, region_id: str, dataset_id: str, request: DatasetRequest ) -> Tuple[Sequence[Dataset], Pagination]: - """ - Retrieves information about a specific dataset by its ID within a region. + """Retrieve information about a specific dataset by its ID within a region. - Parameters - ---------- - region_id : str - The identifier of the region to fetch the dataset from. - dataset_id : str - The identifier of the dataset to fetch. - request : DatasetRequest - The request object containing query parameters (count, start_page). + Args: + region_id: The identifier of the region to fetch the dataset from. + dataset_id: The identifier of the dataset to fetch. + request: The request object containing query parameters. - Returns - ------- - Tuple[Sequence[Dataset], Pagination] + Returns: A tuple containing a list of Dataset objects and a Pagination object for managing result pages. """ url = f"{self.base_navitia_url}/coverage/{region_id}/datasets/{dataset_id}" diff --git a/navitia_client/client/apis/departure_apis.py b/navitia_client/client/apis/departure_apis.py index 6dae00d..c2429ab 100644 --- a/navitia_client/client/apis/departure_apis.py +++ b/navitia_client/client/apis/departure_apis.py @@ -6,34 +6,21 @@ class DepartureApiClient(ApiBaseClient): - """ - This module provides a client for interacting with the Navitia API to retrieve departure schedules. - - It includes the `DepartureApiClient` class, which allows users to fetch departure information - based on region ID and resource paths or by specifying coordinates. The client uses the - `DepartureRequest` class to encapsulate query parameters. + """Client for interacting with the Navitia API to retrieve departure schedules. - Classes - ------- - DepartureApiClient - A client for accessing departure schedules from the Navitia API. + See https://doc.navitia.io/#departures """ @staticmethod def _get_departure_objects_from_response( response: Any, ) -> Sequence[Departure]: - """ - Converts raw response data into a list of Departure objects. + """Convert raw response data into a list of Departure objects. - Parameters - ---------- - response : Any - The raw response data from the API containing departures' information. + Args: + response: The raw response data from the API containing departures' information. - Returns - ------- - Sequence[Departure] + Returns: A list of Departure objects created from the raw response data. """ departures = [] @@ -45,19 +32,13 @@ def _get_departure_objects_from_response( def _get_departures( self, url: str, filters: dict ) -> Tuple[Sequence[Departure], Pagination]: - """ - Fetches departures from the Navitia API based on the provided URL and filters. - - Parameters - ---------- - url : str - The URL to fetch departures from. - filters : dict - A dictionary of filters to apply to the query. - - Returns - ------- - Tuple[Sequence[Departure], Pagination] + """Fetch departures from the Navitia API based on the provided URL and filters. + + Args: + url: The URL to fetch departures from. + filters: A dictionary of filters to apply to the query. + + Returns: A tuple containing a list of Departure objects and a Pagination object for managing result pages. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) @@ -71,23 +52,14 @@ def list_departures_by_region_id_and_path( resource_path: str, request: DepartureRequest, ) -> Tuple[Sequence[Departure], Pagination]: - """ - Retrieves a list of departures for a specified region and resource path from the Navitia API. - - Parameters - ---------- - region_id : str - The identifier of the region to fetch departures from. - resource_path : str - The resource path to fetch departures for. - request : DepartureRequest - The request object containing query parameters such as from_datetime, - duration, depth, count, start_page, forbidden_uris, data_freshness, - disable_geojson, and direction_type. - - Returns - ------- - Tuple[Sequence[Departure], Pagination] + """Retrieve a list of departures for a specified region and resource path. + + Args: + region_id: The identifier of the region to fetch departures from. + resource_path: The resource path to fetch departures for. + request: The request object containing query parameters. + + Returns: A tuple containing a list of Departure objects and a Pagination object for managing result pages. """ request_url = ( @@ -104,27 +76,16 @@ def list_departures_by_coordinates( lat: float, request: DepartureRequest, ) -> Tuple[Sequence[Departure], Pagination]: - """ - Retrieves a list of departures for a specified region and coordinates from the Navitia API. - - Parameters - ---------- - region_lon : float - The longitude of the region. - region_lat : float - The latitude of the region. - lon : float - The longitude of the specific location. - lat : float - The latitude of the specific location. - request : DepartureRequest - The request object containing query parameters such as from_datetime, - duration, depth, count, start_page, forbidden_uris, data_freshness, - disable_geojson, and direction_type. - - Returns - ------- - Tuple[Sequence[Departure], Pagination] + """Retrieve a list of departures for a specified region and coordinates. + + Args: + region_lon: The longitude of the region. + region_lat: The latitude of the region. + lon: The longitude of the specific location. + lat: The latitude of the specific location. + request: The request object containing query parameters. + + Returns: A tuple containing a list of Departure objects and a Pagination object for managing result pages. """ request_url = f"{self.base_navitia_url}/coverage/{region_lon};{region_lat}/coords/{lon};{lat}/departures" diff --git a/navitia_client/client/apis/equipment_report_apis.py b/navitia_client/client/apis/equipment_report_apis.py index ce19ddb..15a907b 100644 --- a/navitia_client/client/apis/equipment_report_apis.py +++ b/navitia_client/client/apis/equipment_report_apis.py @@ -6,44 +6,22 @@ class EquipmentReportsApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching equipment reports. + """Client class to interact with the Navitia API for fetching equipment reports. See https://doc.navitia.io/#equipment-reports - - Methods - ------- - _get_equipment_reports( - url: str, filters: dict - ) -> Tuple[Sequence[EquipmentReports], Pagination]: - Retrieves equipment reports from the Navitia API based on provided URL and filters. - - list_equipment_reports( - region_id: str, - request: EquipmentReportRequest = EquipmentReportRequest(), - ) -> Tuple[Sequence[EquipmentReports], Pagination]: - Retrieves equipment reports for a specified region from the Navitia API. - - list_equipment_reports_with_resource_path( - region_id: str, - resource_path: str, - request: EquipmentReportRequest = EquipmentReportRequest(), - ) -> Tuple[Sequence[EquipmentReports], Pagination]: - Retrieves equipment reports for a specific resource path in a region from the Navitia API. """ def _get_equipment_reports( self, url: str, filters: dict ) -> Tuple[Sequence[EquipmentReports], Pagination]: - """ - Retrieves equipment reports from the Navitia API based on provided URL and filters. + """Retrieve equipment reports from the Navitia API based on provided URL and filters. - Parameters: - url (str): The URL for the API request. - filters (dict): Filters to apply to the API request. + Args: + url: The URL for the API request. + filters: Filters to apply to the API request. Returns: - Tuple[Sequence[EquipmentReports], Pagination]: A tuple containing sequences of EquipmentReports objects and Pagination object. + A tuple containing sequences of EquipmentReports objects and Pagination object. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) equipment_reports = [ @@ -56,21 +34,20 @@ def _get_equipment_reports( def list_equipment_reports( self, region_id: str, - request: EquipmentReportRequest = EquipmentReportRequest(), + request: EquipmentReportRequest, ) -> Tuple[Sequence[EquipmentReports], Pagination]: - """ - Retrieves equipment reports for a specified region from the Navitia API. + """Retrieve equipment reports for a specified region from the Navitia API. This service provides the state of equipments such as lifts or elevators that are giving better accessibility to public transport facilities. The endpoint will report accessible equipment per stop area and per line. - Parameters: - region_id (str): The region ID (coverage identifier). - request (EquipmentReportRequest): The request object containing query parameters. + Args: + region_id: The region ID (coverage identifier). + request: The request object containing query parameters. Returns: - Tuple[Sequence[EquipmentReports], Pagination]: A tuple containing sequences of EquipmentReports objects and Pagination object. + A tuple containing sequences of EquipmentReports objects and Pagination object. Note: This feature requires a specific configuration from an equipment service provider. @@ -83,22 +60,21 @@ def list_equipment_reports_with_resource_path( self, region_id: str, resource_path: str, - request: EquipmentReportRequest = EquipmentReportRequest(), + request: EquipmentReportRequest, ) -> Tuple[Sequence[EquipmentReports], Pagination]: - """ - Retrieves equipment reports for a specific resource path in a region from the Navitia API. + """Retrieve equipment reports for a specific resource path in a region. This service provides the state of equipments such as lifts or elevators that are giving better accessibility to public transport facilities. The endpoint will report accessible equipment per stop area and per line. - Parameters: - region_id (str): The region ID (coverage identifier). - resource_path (str): The resource path (e.g., 'lines/line:A'). - request (EquipmentReportRequest): The request object containing query parameters. + Args: + region_id: The region ID (coverage identifier). + resource_path: The resource path (e.g., 'lines/line:A'). + request: The request object containing query parameters. Returns: - Tuple[Sequence[EquipmentReports], Pagination]: A tuple containing sequences of EquipmentReports objects and Pagination object. + A tuple containing sequences of EquipmentReports objects and Pagination object. Note: This feature requires a specific configuration from an equipment service provider. diff --git a/navitia_client/client/apis/freefloatings_nearby_apis.py b/navitia_client/client/apis/freefloatings_nearby_apis.py index 3e24c90..40b5433 100644 --- a/navitia_client/client/apis/freefloatings_nearby_apis.py +++ b/navitia_client/client/apis/freefloatings_nearby_apis.py @@ -9,62 +9,22 @@ class FreefloatingsNearbyApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching nearby free-floating vehicles. + """Client class to interact with the Navitia API for fetching nearby free-floating vehicles. See https://doc.navitia.io/#freefloatings-nearby-api - - Methods - ------- - _get_freefloatings_nearby( - url: str, filters: dict - ) -> Tuple[Sequence[FreeFloating], Pagination]: - Retrieves free-floating vehicles from the Navitia API based on provided URL and filters. - - list_freefloatings_nearby( - region_id: str, - lon: float, - lat: float, - request: FreefloatingsNearbyRequest = FreefloatingsNearbyRequest(), - ) -> Tuple[Sequence[FreeFloating], Pagination]: - Retrieves free-floating vehicles near coordinates in a specific region from the Navitia API. - - list_freefloatings_nearby_with_resource_path( - region_id: str, - resource_path: str, - request: FreefloatingsNearbyRequest = FreefloatingsNearbyRequest(), - ) -> Tuple[Sequence[FreeFloating], Pagination]: - Retrieves free-floating vehicles near a specific resource path in a region from the Navitia API. - - list_freefloatings_nearby_by_coordinates( - region_lon: float, - region_lat: float, - lon: float, - lat: float, - request: FreefloatingsNearbyRequest = FreefloatingsNearbyRequest(), - ) -> Tuple[Sequence[FreeFloating], Pagination]: - Retrieves free-floating vehicles near coordinates, navitia guesses the region from coordinates. - - list_freefloatings_nearby_by_coordinates_only( - lon: float, - lat: float, - request: FreefloatingsNearbyRequest = FreefloatingsNearbyRequest(), - ) -> Tuple[Sequence[FreeFloating], Pagination]: - Retrieves free-floating vehicles near coordinates without any region id. """ def _get_freefloatings_nearby( self, url: str, filters: dict ) -> Tuple[Sequence[FreeFloating], Pagination]: - """ - Retrieves free-floating vehicles from the Navitia API based on provided URL and filters. + """Retrieve free-floating vehicles from the Navitia API based on provided URL and filters. - Parameters: - url (str): The URL for the API request. - filters (dict): Filters to apply to the API request. + Args: + url: The URL for the API request. + filters: Filters to apply to the API request. Returns: - Tuple[Sequence[FreeFloating], Pagination]: A tuple containing sequences of FreeFloating objects and Pagination object. + A tuple containing sequences of FreeFloating objects and Pagination object. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) free_floatings = [ @@ -78,22 +38,21 @@ def list_freefloatings_nearby( region_id: str, lon: float, lat: float, - request: FreefloatingsNearbyRequest = FreefloatingsNearbyRequest(), + request: FreefloatingsNearbyRequest, ) -> Tuple[Sequence[FreeFloating], Pagination]: - """ - Retrieves free-floating vehicles near coordinates in a specific region from the Navitia API. + """Retrieve free-floating vehicles near coordinates in a specific region. This service provides access to nearby shared mobility options (such as bikes, scooters, or cars) based on user-provided coordinates. - Parameters: - region_id (str): The region ID (coverage identifier). - lon (float): The longitude coordinate. - lat (float): The latitude coordinate. - request (FreefloatingsNearbyRequest): The request object containing query parameters. + Args: + region_id: The region ID (coverage identifier). + lon: The longitude coordinate. + lat: The latitude coordinate. + request: The request object containing query parameters. Returns: - Tuple[Sequence[FreeFloating], Pagination]: A tuple containing sequences of FreeFloating objects and Pagination object. + A tuple containing sequences of FreeFloating objects and Pagination object. Note: This feature requires a specific configuration from a freefloating data service provider. @@ -106,21 +65,20 @@ def list_freefloatings_nearby_with_resource_path( self, region_id: str, resource_path: str, - request: FreefloatingsNearbyRequest = FreefloatingsNearbyRequest(), + request: FreefloatingsNearbyRequest, ) -> Tuple[Sequence[FreeFloating], Pagination]: - """ - Retrieves free-floating vehicles near a specific resource path in a region from the Navitia API. + """Retrieve free-floating vehicles near a specific resource path in a region. This service provides access to nearby shared mobility options (such as bikes, scooters, or cars) near a specific resource (stop area, address, etc.). - Parameters: - region_id (str): The region ID (coverage identifier). - resource_path (str): The resource path (e.g., 'stop_areas/stop_area:XXX'). - request (FreefloatingsNearbyRequest): The request object containing query parameters. + Args: + region_id: The region ID (coverage identifier). + resource_path: The resource path (e.g., 'stop_areas/stop_area:XXX'). + request: The request object containing query parameters. Returns: - Tuple[Sequence[FreeFloating], Pagination]: A tuple containing sequences of FreeFloating objects and Pagination object. + A tuple containing sequences of FreeFloating objects and Pagination object. Note: This feature requires a specific configuration from a freefloating data service provider. @@ -137,22 +95,21 @@ def list_freefloatings_nearby_by_coordinates( lat: float, request: FreefloatingsNearbyRequest = FreefloatingsNearbyRequest(), ) -> Tuple[Sequence[FreeFloating], Pagination]: - """ - Retrieves free-floating vehicles near coordinates, navitia guesses the region from coordinates. + """Retrieve free-floating vehicles near coordinates, navitia guesses the region from coordinates. This service provides access to nearby shared mobility options (such as bikes, scooters, or cars) based on user-provided coordinates. Navitia will automatically determine the region based on the provided region coordinates. - Parameters: - region_lon (float): The longitude coordinate for region identification. - region_lat (float): The latitude coordinate for region identification. - lon (float): The longitude coordinate for the search center. - lat (float): The latitude coordinate for the search center. - request (FreefloatingsNearbyRequest): The request object containing query parameters. + Args: + region_lon: The longitude coordinate for region identification. + region_lat: The latitude coordinate for region identification. + lon: The longitude coordinate for the search center. + lat: The latitude coordinate for the search center. + request: The request object containing query parameters. Returns: - Tuple[Sequence[FreeFloating], Pagination]: A tuple containing sequences of FreeFloating objects and Pagination object. + A tuple containing sequences of FreeFloating objects and Pagination object. Note: This feature requires a specific configuration from a freefloating data service provider. @@ -167,20 +124,19 @@ def list_freefloatings_nearby_by_coordinates_only( lat: float, request: FreefloatingsNearbyRequest = FreefloatingsNearbyRequest(), ) -> Tuple[Sequence[FreeFloating], Pagination]: - """ - Retrieves free-floating vehicles near coordinates without any region id. + """Retrieve free-floating vehicles near coordinates without any region id. This service provides access to nearby shared mobility options (such as bikes, scooters, or cars) based on user-provided coordinates. This method does not require a region ID; Navitia will automatically determine the appropriate region. - Parameters: - lon (float): The longitude coordinate. - lat (float): The latitude coordinate. - request (FreefloatingsNearbyRequest): The request object containing query parameters. + Args: + lon: The longitude coordinate. + lat: The latitude coordinate. + request: The request object containing query parameters. Returns: - Tuple[Sequence[FreeFloating], Pagination]: A tuple containing sequences of FreeFloating objects and Pagination object. + A tuple containing sequences of FreeFloating objects and Pagination object. Note: This feature requires a specific configuration from a freefloating data service provider. diff --git a/navitia_client/client/apis/inverted_geocoding_apis.py b/navitia_client/client/apis/inverted_geocoding_apis.py index 6c7142b..8587902 100644 --- a/navitia_client/client/apis/inverted_geocoding_apis.py +++ b/navitia_client/client/apis/inverted_geocoding_apis.py @@ -4,48 +4,19 @@ class InvertedGeocodingApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for performing inverted geocoding operations. + """Client class to interact with the Navitia API for performing inverted geocoding operations. See https://doc.navitia.io/#coord - - Methods - ------- - _get_regions_from_response(response: Any) -> Sequence[Place] - A static method to transform raw API response data into a list of Place objects. - - get_address_and_region_from_coordinates(lon: float, lat: float) -> Sequence[Place] - Retrieves address and region information based on given coordinates. - - get_address_and_region_from_id(id: str) -> Sequence[Place] - Retrieves address and region information based on a given place ID. - - get_address_from_region_coordinates_and_coordinates(region_lon: float, region_lat: float, lon: float, lat: float) -> Sequence[Place] - Retrieves address information based on region coordinates and specific coordinates. - - get_address_from_region_coordinates_and_id(region_lon: float, region_lat: float, id: str) -> Sequence[Place] - Retrieves address information based on region coordinates and a specific place ID. - - get_address_from_region_id_and_coordinates(region_id: str, lon: float, lat: float) -> Sequence[Place] - Retrieves address information based on a region ID and specific coordinates. - - get_address_from_region_id_and_id(region_id: str, id: str) -> Sequence[Place] - Retrieves address information based on a region ID and a specific place ID. """ @staticmethod def _get_regions_from_response(response: Any) -> Sequence[Place]: - """ - Converts raw response data into a list of Place objects. + """Convert raw response data into a list of Place objects. - Parameters - ---------- - response : Any - The raw response data from the API containing places' information. + Args: + response: The raw response data from the API containing places' information. - Returns - ------- - Sequence[Place] + Returns: A list of Place objects created from the raw response data. """ entities = [] @@ -57,19 +28,13 @@ def _get_regions_from_response(response: Any) -> Sequence[Place]: def get_address_and_region_from_coordinates( self, lon: float, lat: float ) -> Sequence[Place]: - """ - Retrieves address and region information based on given coordinates. - - Parameters - ---------- - lon : float - The longitude of the location. - lat : float - The latitude of the location. - - Returns - ------- - Sequence[Place] + """Retrieve address and region information based on given coordinates. + + Args: + lon: The longitude of the location. + lat: The latitude of the location. + + Returns: A list of Place objects representing the address and region information. """ result = self.get_navitia_api(f"{self.base_navitia_url}/places/{lon};{lat}") @@ -77,17 +42,12 @@ def get_address_and_region_from_coordinates( return places def get_address_and_region_from_id(self, id: str) -> Sequence[Place]: - """ - Retrieves address and region information based on a given place ID. + """Retrieve address and region information based on a given place ID. - Parameters - ---------- - id : str - The identifier of the place. + Args: + id: The identifier of the place. - Returns - ------- - Sequence[Place] + Returns: A list of Place objects representing the address and region information. """ result = self.get_navitia_api(f"{self.base_navitia_url}/places/{id}") @@ -97,23 +57,15 @@ def get_address_and_region_from_id(self, id: str) -> Sequence[Place]: def get_address_from_region_coordinates_and_coordinates( self, region_lon: float, region_lat: float, lon: float, lat: float ) -> Sequence[Place]: - """ - Retrieves address information based on region coordinates and specific coordinates. - - Parameters - ---------- - region_lon : float - The longitude of the region. - region_lat : float - The latitude of the region. - lon : float - The longitude of the specific location. - lat : float - The latitude of the specific location. - - Returns - ------- - Sequence[Place] + """Retrieve address information based on region coordinates and specific coordinates. + + Args: + region_lon: The longitude of the region. + region_lat: The latitude of the region. + lon: The longitude of the specific location. + lat: The latitude of the specific location. + + Returns: A list of Place objects representing the address information. """ result = self.get_navitia_api( @@ -125,21 +77,14 @@ def get_address_from_region_coordinates_and_coordinates( def get_address_from_region_coordinates_and_id( self, region_lon: float, region_lat: float, id: str ) -> Sequence[Place]: - """ - Retrieves address information based on region coordinates and a specific place ID. - - Parameters - ---------- - region_lon : float - The longitude of the region. - region_lat : float - The latitude of the region. - id : str - The identifier of the place. - - Returns - ------- - Sequence[Place] + """Retrieve address information based on region coordinates and a specific place ID. + + Args: + region_lon: The longitude of the region. + region_lat: The latitude of the region. + id: The identifier of the place. + + Returns: A list of Place objects representing the address information. """ result = self.get_navitia_api( @@ -151,21 +96,14 @@ def get_address_from_region_coordinates_and_id( def get_address_from_region_id_and_coordinates( self, region_id: str, lon: float, lat: float ) -> Sequence[Place]: - """ - Retrieves address information based on a region ID and specific coordinates. - - Parameters - ---------- - region_id : str - The identifier of the region. - lon : float - The longitude of the specific location. - lat : float - The latitude of the specific location. - - Returns - ------- - Sequence[Place] + """Retrieve address information based on a region ID and specific coordinates. + + Args: + region_id: The identifier of the region. + lon: The longitude of the specific location. + lat: The latitude of the specific location. + + Returns: A list of Place objects representing the address information. """ result = self.get_navitia_api( @@ -177,19 +115,13 @@ def get_address_from_region_id_and_coordinates( def get_address_from_region_id_and_id( self, region_id: str, id: str ) -> Sequence[Place]: - """ - Retrieves address information based on a region ID and a specific place ID. - - Parameters - ---------- - region_id : str - The identifier of the region. - id : str - The identifier of the place. - - Returns - ------- - Sequence[Place] + """Retrieve address information based on a region ID and a specific place ID. + + Args: + region_id: The identifier of the region. + id: The identifier of the place. + + Returns: A list of Place objects representing the address information. """ result = self.get_navitia_api( diff --git a/navitia_client/client/apis/isochrone_apis.py b/navitia_client/client/apis/isochrone_apis.py index 474591a..300306c 100644 --- a/navitia_client/client/apis/isochrone_apis.py +++ b/navitia_client/client/apis/isochrone_apis.py @@ -5,42 +5,19 @@ class IsochronesApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching isochrones data. + """Client class to interact with the Navitia API for fetching isochrones data. See https://doc.navitia.io/#isochrones-api - - Methods - ------- - _get_traffic_reports(url: str, filters: dict) -> Sequence[Isochrone] - Internal method to fetch isochrone data based on the provided URL and filters. - - list_isochrones_with_region_id( - region_id: str, - request: IsochroneRequest - ) -> Sequence[Isochrone] - Fetches isochrones data for a specific region based on various parameters. - - list_isochrones( - request: IsochroneRequest - ) -> Sequence[Isochrone] - Fetches isochrones data based on various parameters. """ def _get_traffic_reports(self, url: str, filters: dict) -> Sequence[Isochrone]: - """ - Internal method to fetch isochrone data based on the provided URL and filters. + """Fetch isochrone data based on the provided URL and filters. - Parameters - ---------- - url : str - The API endpoint URL for fetching isochrone data. - filters : dict - The query parameters for filtering the isochrone data. + Args: + url: The API endpoint URL for fetching isochrone data. + filters: The query parameters for filtering the isochrone data. - Returns - ------- - Sequence[Isochrone] + Returns: A list of Isochrone objects created from the API response. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) @@ -54,19 +31,13 @@ def list_isochrones_with_region_id( region_id: str, request: IsochroneRequest, ) -> Sequence[Isochrone]: - """ - Fetches isochrones data for a specific region based on various parameters. + """Fetch isochrones data for a specific region based on various parameters. - Parameters - ---------- - region_id : str - The identifier of the region. - request : IsochroneRequest - The request object containing query parameters. + Args: + region_id: The identifier of the region. + request: The request object containing query parameters. - Returns - ------- - Sequence[Isochrone] + Returns: A list of Isochrone objects representing the isochrone data. """ request_url = f"{self.base_navitia_url}/coverage/{region_id}/isochrones" @@ -76,17 +47,12 @@ def list_isochrones( self, request: IsochroneRequest, ) -> Sequence[Isochrone]: - """ - Fetches isochrones data based on various parameters. + """Fetch isochrones data based on various parameters. - Parameters - ---------- - request : IsochroneRequest - The request object containing query parameters. + Args: + request: The request object containing query parameters. - Returns - ------- - Sequence[Isochrone] + Returns: A list of Isochrone objects representing the isochrone data. """ request_url = f"{self.base_navitia_url}/isochrones" diff --git a/navitia_client/client/apis/journeys_apis.py b/navitia_client/client/apis/journeys_apis.py index 2f2a053..90186e6 100644 --- a/navitia_client/client/apis/journeys_apis.py +++ b/navitia_client/client/apis/journeys_apis.py @@ -1,144 +1,23 @@ -from datetime import datetime -from typing import Optional, Sequence +from typing import Sequence from navitia_client.client.apis.api_base_client import ApiBaseClient -from navitia_client.entities.response import Journey, ParkMode +from navitia_client.entities.request.journey import JourneyRequest +from navitia_client.entities.response import Journey class JourneyApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching journey data. + """A client class to interact with the Navitia API for fetching journey data. See https://doc.navitia.io/#journeys - - Methods - ------- - _get_journeys(url: str, filters: dict) -> Sequence[Journey] - Internal method to fetch journey data based on the provided URL and filters. - - list_journeys( - from_: Optional[str] = None, - to_: Optional[str] = None, - datetime_: datetime = datetime.now(), - datetime_represents: str = "departure", - traveler_type: str = "standard", - data_freshness: str = "realtime", - forbidden_uris: Optional[Sequence[str]] = None, - allowed_id: Optional[Sequence[str]] = None, - first_section_mode: Optional[Sequence[str]] = None, - last_section_mode: Optional[Sequence[str]] = None, - language: str = "en-GB", - depth: int = 1, - max_duration_to_pt: int = 30 * 60, - walking_speed: float = 1.12, - bike_speed: float = 4.1, - bss_speed: float = 4.1, - car_speed: float = 16.8, - min_nb_journeys: int = 1, - max_nb_journeys: int = 1, - count: int = 1, - max_nb_transfers: int = 10, - min_nb_transfers: int = 0, - max_duration: int = 86400, - wheelchair: bool = False, - direct_path: str = "indifferent", - direct_path_mode: Optional[Sequence[str]] = None, - add_poi_infos: Optional[Sequence[str]] = None, - debug: bool = False, - free_radius_from: int = 0, - free_radius_to: int = 0, - timeframe_duration: int = 0 - ) -> Sequence[Journey] - Fetches journey data based on various parameters. - - list_journeys_with_region_id( - self, - region_id: str, - from_: Optional[str] = None, - to_: Optional[str] = None, - datetime_: datetime = datetime.now(), - datetime_represents: str = "departure", - traveler_type: str = "standard", - data_freshness: str = "realtime", - forbidden_uris: Optional[Sequence[str]] = None, - allowed_id: Optional[Sequence[str]] = None, - first_section_mode: Optional[Sequence[str]] = None, - last_section_mode: Optional[Sequence[str]] = None, - language: str = "en-GB", - depth: int = 1, - max_duration_to_pt: int = 30 * 60, - walking_speed: float = 1.12, - bike_speed: float = 4.1, - bss_speed: float = 4.1, - car_speed: float = 16.8, - min_nb_journeys: int = 1, - max_nb_journeys: int = 1, - count: int = 1, - max_nb_transfers: int = 10, - min_nb_transfers: int = 0, - max_duration: int = 86400, - wheelchair: bool = False, - direct_path: str = "indifferent", - direct_path_mode: Optional[Sequence[str]] = None, - add_poi_infos: Optional[Sequence[str]] = None, - debug: bool = False, - free_radius_from: int = 0, - free_radius_to: int = 0, - timeframe_duration: int = 0 - ) -> Sequence[Journey] - Fetches journey data for a specific region based on various parameters. - - list_journeys_with_resource_path( - self, - resource_path: str, - from_: Optional[str] = None, - to_: Optional[str] = None, - datetime_: datetime = datetime.now(), - datetime_represents: str = "departure", - traveler_type: str = "standard", - data_freshness: str = "realtime", - forbidden_uris: Optional[Sequence[str]] = None, - allowed_id: Optional[Sequence[str]] = None, - first_section_mode: Optional[Sequence[str]] = None, - last_section_mode: Optional[Sequence[str]] = None, - language: str = "en-GB", - depth: int = 1, - max_duration_to_pt: int = 30 * 60, - walking_speed: float = 1.12, - bike_speed: float = 4.1, - bss_speed: float = 4.1, - car_speed: float = 16.8, - min_nb_journeys: int = 1, - max_nb_journeys: int = 1, - count: int = 1, - max_nb_transfers: int = 10, - min_nb_transfers: int = 0, - max_duration: int = 86400, - wheelchair: bool = False, - direct_path: str = "indifferent", - direct_path_mode: Optional[Sequence[str]] = None, - add_poi_infos: Optional[Sequence[str]] = None, - debug: bool = False, - free_radius_from: int = 0, - free_radius_to: int = 0, - timeframe_duration: int = 0 - ) -> Sequence[Journey] - Fetches journey data for a specific resource path based on various parameters. """ def _get_journeys(self, url: str, filters: dict) -> Sequence[Journey]: - """ - Internal method to fetch journey data based on the provided URL and filters. + """Internal method to fetch journey data based on the provided URL and filters. - Parameters - ---------- - url : str - The API endpoint URL for fetching journey data. - filters : dict - The query parameters for filtering the journey data. + Args: + url: The API endpoint URL for fetching journey data. + filters: The query parameters for filtering the journey data. - Returns - ------- - Sequence[Journey] + Returns: A list of Journey objects created from the API response. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) @@ -147,624 +26,52 @@ def _get_journeys(self, url: str, filters: dict) -> Sequence[Journey]: def list_journeys( self, - from_: Optional[str] = None, - to_: Optional[str] = None, - datetime_: datetime = datetime.now(), - datetime_represents: str = "departure", - traveler_type: str = "standard", - data_freshness: str = "realtime", - forbidden_uris: Optional[Sequence[str]] = None, - allowed_id: Optional[Sequence[str]] = None, - first_section_mode: Optional[Sequence[str]] = None, - last_section_mode: Optional[Sequence[str]] = None, - language: str = "en-GB", - depth: int = 1, - max_duration_to_pt: int = 30 * 60, - walking_speed: float = 1.12, - bike_speed: float = 4.1, - bss_speed: float = 4.1, - car_speed: float = 16.8, - min_nb_journeys: int = 1, - max_nb_journeys: int = 1, - count: int = 1, - max_nb_transfers: int = 10, - min_nb_transfers: int = 0, - max_duration: int = 86400, - wheelchair: bool = False, - direct_path: str = "indifferent", - direct_path_mode: Optional[Sequence[str]] = None, - add_poi_infos: Optional[Sequence[str]] = None, - debug: bool = False, - free_radius_from: int = 0, - free_radius_to: int = 0, - timeframe_duration: int = 0, - park_mode: ParkMode = ParkMode.NONE, - is_journey_schedules: bool = False, - bike_use_hills: Optional[float] = None, - walking_use_hills: Optional[float] = None, - bike_avoid_bad_surfaces: Optional[float] = None, - walking_step_penalty: Optional[float] = None, - bike_maneuver_penalty: Optional[float] = None, - bike_use_living_streets: Optional[float] = None, + request: JourneyRequest, ) -> Sequence[Journey]: - """ - Fetches journey data based on various parameters. + """Fetch journey data based on various parameters. - Parameters - ---------- - from_ : Optional[str], optional - The starting point for the journey. - to_ : Optional[str], optional - The ending point for the journey. - datetime_ : datetime, optional - The date and time for the journey calculation (default is datetime.now()). - datetime_represents : str, optional - Represents whether the datetime is for departure or arrival (default is "departure"). - traveler_type : str, optional - The type of traveler (default is "standard"). - data_freshness : str, optional - The freshness of the data, can be "realtime" or "base_schedule" (default is "realtime"). - forbidden_uris : Optional[Sequence[str]], optional - A list of URIs that are forbidden in the journey calculation. - allowed_id : Optional[Sequence[str]], optional - A list of allowed IDs for the journey calculation. - first_section_mode : Optional[Sequence[str]], optional - Modes of transportation for the first section of the journey. - last_section_mode : Optional[Sequence[str]], optional - Modes of transportation for the last section of the journey. - language : str, optional - The language for the journey results (default is "en-GB"). - depth : int, optional - The depth of the journey search (default is 1). - max_duration_to_pt : int, optional - Maximum duration to public transportation in seconds (default is 30 * 60). - walking_speed : float, optional - Walking speed in meters per second (default is 1.12). - bike_speed : float, optional - Bike speed in meters per second (default is 4.1). - bss_speed : float, optional - Bike-sharing speed in meters per second (default is 4.1). - car_speed : float, optional - Car speed in meters per second (default is 16.8). - min_nb_journeys : int, optional - Minimum number of journeys to be returned (default is 1). - max_nb_journeys : int, optional - Maximum number of journeys to be returned (default is 1). - count : int, optional - Number of journey results to return (default is 1). - max_nb_transfers : int, optional - Maximum number of transfers allowed in the journey (default is 10). - min_nb_transfers : int, optional - Minimum number of transfers required in the journey (default is 0). - max_duration : int, optional - Maximum duration of the journey in seconds (default is 86400). - wheelchair : bool, optional - Whether the journey should be wheelchair accessible (default is False). - direct_path : str, optional - Preference for direct paths, can be "indifferent", "requested", or "forbidden" (default is "indifferent"). - direct_path_mode : Optional[Sequence[str]], optional - Modes of transportation for direct paths. - add_poi_infos : Sequence[str], optional - Additional points of interest information to be included. - debug : bool, optional - Whether to include debug information in the response (default is False). - free_radius_from : int, optional - Free radius from the starting point in meters (default is 0). - free_radius_to : int, optional - Free radius to the ending point in meters (default is 0). - timeframe_duration : int, optional - Timeframe duration in seconds for the journey calculation (default is 0). - park_mode : ParkMode, optional - Parking mode for car-based journeys: ParkMode.NONE, ParkMode.ON_STREET, or ParkMode.PARK_AND_RIDE (default is ParkMode.NONE). - is_journey_schedules : bool, optional - Whether to return journey schedules instead of journeys (default is False). - bike_use_hills : Optional[float], optional - Valhalla parameter: preference for using hills when biking, from 0 (avoid) to 1 (prefer) (default is None). - walking_use_hills : Optional[float], optional - Valhalla parameter: preference for using hills when walking, from 0 (avoid) to 1 (prefer) (default is None). - bike_avoid_bad_surfaces : Optional[float], optional - Valhalla parameter: preference for avoiding bad surfaces when biking, from 0 (don't avoid) to 1 (strongly avoid) (default is None). - walking_step_penalty : Optional[float], optional - Valhalla parameter: penalty applied to steps when walking, in seconds (default is None). - bike_maneuver_penalty : Optional[float], optional - Valhalla parameter: penalty applied to maneuvers when biking, in seconds (default is None). - bike_use_living_streets : Optional[float], optional - Valhalla parameter: preference for using living streets when biking, from 0 (avoid) to 1 (prefer) (default is None). + Args: + request: Journey request containing all query parameters. - Returns - ------- - Sequence[Journey] + Returns: A list of Journey objects representing the journey results. """ request_url = f"{self.base_navitia_url}/journeys" - filters = { - "datetime": datetime_.isoformat(), - "datetime_represents": datetime_represents, - "traveler_type": traveler_type, - "data_freshness": data_freshness, - "language": language, - "depth": depth, - "max_duration_to_pt": max_duration_to_pt, - "walking_speed": walking_speed, - "bike_speed": bike_speed, - "bss_speed": bss_speed, - "car_speed": car_speed, - "min_nb_journeys": min_nb_journeys, - "max_nb_journeys": max_nb_journeys, - "count": count, - "max_nb_transfers": max_nb_transfers, - "min_nb_transfers": min_nb_transfers, - "max_duration": max_duration, - "wheelchair": wheelchair, - "direct_path": direct_path, - "debug": debug, - "free_radius_from": free_radius_from, - "free_radius_to": free_radius_to, - "timeframe_duration": timeframe_duration, - "is_journey_schedules": is_journey_schedules, - } - - if from_: - filters["from"] = from_ - - if to_: - filters["to"] = to_ - - filters["park_mode"] = park_mode.value - - if bike_use_hills is not None: - filters["bike_use_hills"] = bike_use_hills - - if walking_use_hills is not None: - filters["walking_use_hills"] = walking_use_hills - - if bike_avoid_bad_surfaces is not None: - filters["bike_avoid_bad_surfaces"] = bike_avoid_bad_surfaces - - if walking_step_penalty is not None: - filters["walking_step_penalty"] = walking_step_penalty - - if bike_maneuver_penalty is not None: - filters["bike_maneuver_penalty"] = bike_maneuver_penalty - - if bike_use_living_streets is not None: - filters["bike_use_living_streets"] = bike_use_living_streets - - if forbidden_uris: - filters["forbidden_uris[]"] = forbidden_uris - - if allowed_id: - filters["allowed_id[]"] = allowed_id - - if first_section_mode: - filters["first_section_mode[]"] = first_section_mode - - if last_section_mode: - filters["last_section_mode[]"] = last_section_mode - - if add_poi_infos: - filters["add_poi_infos[]"] = add_poi_infos - - if any([direct_path_mode, first_section_mode]): - filters["direct_path_mode[]"] = direct_path_mode or first_section_mode - - return self._get_journeys(request_url, filters) + return self._get_journeys(request_url, request.to_filters()) def list_journeys_with_region_id( self, region_id: str, - from_: Optional[str] = None, - to_: Optional[str] = None, - datetime_: datetime = datetime.now(), - datetime_represents: str = "departure", - traveler_type: str = "standard", - data_freshness: str = "realtime", - forbidden_uris: Optional[Sequence[str]] = None, - allowed_id: Optional[Sequence[str]] = None, - first_section_mode: Optional[Sequence[str]] = None, - last_section_mode: Optional[Sequence[str]] = None, - language: str = "en-GB", - depth: int = 1, - max_duration_to_pt: int = 30 * 60, - walking_speed: float = 1.12, - bike_speed: float = 4.1, - bss_speed: float = 4.1, - car_speed: float = 16.8, - min_nb_journeys: int = 1, - max_nb_journeys: int = 1, - count: int = 1, - max_nb_transfers: int = 10, - min_nb_transfers: int = 0, - max_duration: int = 86400, - wheelchair: bool = False, - direct_path: str = "indifferent", - direct_path_mode: Optional[Sequence[str]] = None, - add_poi_infos: Optional[Sequence[str]] = None, - debug: bool = False, - free_radius_from: int = 0, - free_radius_to: int = 0, - timeframe_duration: int = 0, - park_mode: ParkMode = ParkMode.NONE, - is_journey_schedules: bool = False, - bike_use_hills: Optional[float] = None, - walking_use_hills: Optional[float] = None, - bike_avoid_bad_surfaces: Optional[float] = None, - walking_step_penalty: Optional[float] = None, - bike_maneuver_penalty: Optional[float] = None, - bike_use_living_streets: Optional[float] = None, + request: JourneyRequest, ) -> Sequence[Journey]: - """ - Fetches journey data for a specific region based on various parameters. + """Fetch journey data for a specific region based on various parameters. - Parameters - ---------- - region_id : str - The ID of the region to fetch journey data for. - from_ : Optional[str], optional - The starting point for the journey. - to_ : Optional[str], optional - The ending point for the journey. - datetime_ : datetime, optional - The date and time for the journey calculation (default is datetime.now()). - datetime_represents : str, optional - Represents whether the datetime is for departure or arrival (default is "departure"). - traveler_type : str, optional - The type of traveler (default is "standard"). - data_freshness : str, optional - The freshness of the data, can be "realtime" or "base_schedule" (default is "realtime"). - forbidden_uris : Optional[Sequence[str]], optional - A list of URIs that are forbidden in the journey calculation. - allowed_id : Optional[Sequence[str]], optional - A list of allowed IDs for the journey calculation. - first_section_mode : Optional[Sequence[str]], optional - Modes of transportation for the first section of the journey. - last_section_mode : Optional[Sequence[str]], optional - Modes of transportation for the last section of the journey. - language : str, optional - The language for the journey results (default is "en-GB"). - depth : int, optional - The depth of the journey search (default is 1). - max_duration_to_pt : int, optional - Maximum duration to public transportation in seconds (default is 30 * 60). - walking_speed : float, optional - Walking speed in meters per second (default is 1.12). - bike_speed : float, optional - Bike speed in meters per second (default is 4.1). - bss_speed : float, optional - Bike-sharing speed in meters per second (default is 4.1). - car_speed : float, optional - Car speed in meters per second (default is 16.8). - min_nb_journeys : int, optional - Minimum number of journeys to be returned (default is 1). - max_nb_journeys : int, optional - Maximum number of journeys to be returned (default is 1). - count : int, optional - Number of journey results to return (default is 1). - max_nb_transfers : int, optional - Maximum number of transfers allowed in the journey (default is 10). - min_nb_transfers : int, optional - Minimum number of transfers required in the journey (default is 0). - max_duration : int, optional - Maximum duration of the journey in seconds (default is 86400). - wheelchair : bool, optional - Whether the journey should be wheelchair accessible (default is False). - direct_path : str, optional - Preference for direct paths, can be "indifferent", "requested", or "forbidden" (default is "indifferent"). - direct_path_mode : Optional[Sequence[str]], optional - Modes of transportation for direct paths. - add_poi_infos : Sequence[str], optional - Additional points of interest information to be included. - debug : bool, optional - Whether to include debug information in the response (default is False). - free_radius_from : int, optional - Free radius from the starting point in meters (default is 0). - free_radius_to : int, optional - Free radius to the ending point in meters (default is 0). - timeframe_duration : int, optional - Timeframe duration in seconds for the journey calculation (default is 0). - park_mode : ParkMode, optional - Parking mode for car-based journeys: ParkMode.NONE, ParkMode.ON_STREET, or ParkMode.PARK_AND_RIDE (default is ParkMode.NONE). - is_journey_schedules : bool, optional - Whether to return journey schedules instead of journeys (default is False). - bike_use_hills : Optional[float], optional - Valhalla parameter: preference for using hills when biking, from 0 (avoid) to 1 (prefer) (default is None). - walking_use_hills : Optional[float], optional - Valhalla parameter: preference for using hills when walking, from 0 (avoid) to 1 (prefer) (default is None). - bike_avoid_bad_surfaces : Optional[float], optional - Valhalla parameter: preference for avoiding bad surfaces when biking, from 0 (don't avoid) to 1 (strongly avoid) (default is None). - walking_step_penalty : Optional[float], optional - Valhalla parameter: penalty applied to steps when walking, in seconds (default is None). - bike_maneuver_penalty : Optional[float], optional - Valhalla parameter: penalty applied to maneuvers when biking, in seconds (default is None). - bike_use_living_streets : Optional[float], optional - Valhalla parameter: preference for using living streets when biking, from 0 (avoid) to 1 (prefer) (default is None). + Args: + region_id: The ID of the region to fetch journey data for. + request: Journey request containing all query parameters. - Returns - ------- - Sequence[Journey] + Returns: A list of Journey objects representing the journey results for the specified region. """ request_url = f"{self.base_navitia_url}/coverage/{region_id}/journeys" - filters = { - "datetime": datetime_.isoformat(), - "datetime_represents": datetime_represents, - "traveler_type": traveler_type, - "data_freshness": data_freshness, - "language": language, - "depth": depth, - "max_duration_to_pt": max_duration_to_pt, - "walking_speed": walking_speed, - "bike_speed": bike_speed, - "bss_speed": bss_speed, - "car_speed": car_speed, - "min_nb_journeys": min_nb_journeys, - "max_nb_journeys": max_nb_journeys, - "count": count, - "max_nb_transfers": max_nb_transfers, - "min_nb_transfers": min_nb_transfers, - "max_duration": max_duration, - "wheelchair": wheelchair, - "direct_path": direct_path, - "debug": debug, - "free_radius_from": free_radius_from, - "free_radius_to": free_radius_to, - "timeframe_duration": timeframe_duration, - "is_journey_schedules": is_journey_schedules, - } - - if from_: - filters["from"] = from_ - - if to_: - filters["to"] = to_ - - filters["park_mode"] = park_mode.value - - if bike_use_hills is not None: - filters["bike_use_hills"] = bike_use_hills - - if walking_use_hills is not None: - filters["walking_use_hills"] = walking_use_hills - - if bike_avoid_bad_surfaces is not None: - filters["bike_avoid_bad_surfaces"] = bike_avoid_bad_surfaces - - if walking_step_penalty is not None: - filters["walking_step_penalty"] = walking_step_penalty - - if bike_maneuver_penalty is not None: - filters["bike_maneuver_penalty"] = bike_maneuver_penalty - - if bike_use_living_streets is not None: - filters["bike_use_living_streets"] = bike_use_living_streets - - if forbidden_uris: - filters["forbidden_uris[]"] = forbidden_uris - - if allowed_id: - filters["allowed_id[]"] = allowed_id - - if first_section_mode: - filters["first_section_mode[]"] = first_section_mode - - if last_section_mode: - filters["last_section_mode[]"] = last_section_mode - - if add_poi_infos: - filters["add_poi_infos[]"] = add_poi_infos - - if any([direct_path_mode, first_section_mode]): - filters["direct_path_mode[]"] = direct_path_mode or first_section_mode - - return self._get_journeys(request_url, filters) + return self._get_journeys(request_url, request.to_filters()) def list_journeys_with_resource_path( self, resource_path: str, - from_: Optional[str] = None, - to_: Optional[str] = None, - datetime_: datetime = datetime.now(), - datetime_represents: str = "departure", - traveler_type: str = "standard", - data_freshness: str = "realtime", - forbidden_uris: Optional[Sequence[str]] = None, - allowed_id: Optional[Sequence[str]] = None, - first_section_mode: Optional[Sequence[str]] = None, - last_section_mode: Optional[Sequence[str]] = None, - language: str = "en-GB", - depth: int = 1, - max_duration_to_pt: int = 30 * 60, - walking_speed: float = 1.12, - bike_speed: float = 4.1, - bss_speed: float = 4.1, - car_speed: float = 16.8, - min_nb_journeys: int = 1, - max_nb_journeys: int = 1, - count: int = 1, - max_nb_transfers: int = 10, - min_nb_transfers: int = 0, - max_duration: int = 86400, - wheelchair: bool = False, - direct_path: str = "indifferent", - direct_path_mode: Optional[Sequence[str]] = None, - add_poi_infos: Optional[Sequence[str]] = None, - debug: bool = False, - free_radius_from: int = 0, - free_radius_to: int = 0, - timeframe_duration: int = 0, - park_mode: ParkMode = ParkMode.NONE, - is_journey_schedules: bool = False, - bike_use_hills: Optional[float] = None, - walking_use_hills: Optional[float] = None, - bike_avoid_bad_surfaces: Optional[float] = None, - walking_step_penalty: Optional[float] = None, - bike_maneuver_penalty: Optional[float] = None, - bike_use_living_streets: Optional[float] = None, + request: JourneyRequest, ) -> Sequence[Journey]: - """ - Fetches journey data for a specific resource path based on various parameters. + """Fetch journey data for a specific resource path based on various parameters. - Parameters - ---------- - region_id : str - The ID of the region to fetch journey data for. - from_ : Optional[str], optional - The starting point for the journey. - to_ : Optional[str], optional - The ending point for the journey. - datetime_ : datetime, optional - The date and time for the journey calculation (default is datetime.now()). - datetime_represents : str, optional - Represents whether the datetime is for departure or arrival (default is "departure"). - traveler_type : str, optional - The type of traveler (default is "standard"). - data_freshness : str, optional - The freshness of the data, can be "realtime" or "base_schedule" (default is "realtime"). - forbidden_uris : Optional[Sequence[str]], optional - A list of URIs that are forbidden in the journey calculation. - allowed_id : Optional[Sequence[str]], optional - A list of allowed IDs for the journey calculation. - first_section_mode : Optional[Sequence[str]], optional - Modes of transportation for the first section of the journey. - last_section_mode : Optional[Sequence[str]], optional - Modes of transportation for the last section of the journey. - language : str, optional - The language for the journey results (default is "en-GB"). - depth : int, optional - The depth of the journey search (default is 1). - max_duration_to_pt : int, optional - Maximum duration to public transportation in seconds (default is 30 * 60). - walking_speed : float, optional - Walking speed in meters per second (default is 1.12). - bike_speed : float, optional - Bike speed in meters per second (default is 4.1). - bss_speed : float, optional - Bike-sharing speed in meters per second (default is 4.1). - car_speed : float, optional - Car speed in meters per second (default is 16.8). - min_nb_journeys : int, optional - Minimum number of journeys to be returned (default is 1). - max_nb_journeys : int, optional - Maximum number of journeys to be returned (default is 1). - count : int, optional - Number of journey results to return (default is 1). - max_nb_transfers : int, optional - Maximum number of transfers allowed in the journey (default is 10). - min_nb_transfers : int, optional - Minimum number of transfers required in the journey (default is 0). - max_duration : int, optional - Maximum duration of the journey in seconds (default is 86400). - wheelchair : bool, optional - Whether the journey should be wheelchair accessible (default is False). - direct_path : str, optional - Preference for direct paths, can be "indifferent", "requested", or "forbidden" (default is "indifferent"). - direct_path_mode : Optional[Sequence[str]], optional - Modes of transportation for direct paths. - add_poi_infos : Sequence[str], optional - Additional points of interest information to be included. - debug : bool, optional - Whether to include debug information in the response (default is False). - free_radius_from : int, optional - Free radius from the starting point in meters (default is 0). - free_radius_to : int, optional - Free radius to the ending point in meters (default is 0). - timeframe_duration : int, optional - Timeframe duration in seconds for the journey calculation (default is 0). - park_mode : ParkMode, optional - Parking mode for car-based journeys: ParkMode.NONE, ParkMode.ON_STREET, or ParkMode.PARK_AND_RIDE (default is ParkMode.NONE). - is_journey_schedules : bool, optional - Whether to return journey schedules instead of journeys (default is False). - bike_use_hills : Optional[float], optional - Valhalla parameter: preference for using hills when biking, from 0 (avoid) to 1 (prefer) (default is None). - walking_use_hills : Optional[float], optional - Valhalla parameter: preference for using hills when walking, from 0 (avoid) to 1 (prefer) (default is None). - bike_avoid_bad_surfaces : Optional[float], optional - Valhalla parameter: preference for avoiding bad surfaces when biking, from 0 (don't avoid) to 1 (strongly avoid) (default is None). - walking_step_penalty : Optional[float], optional - Valhalla parameter: penalty applied to steps when walking, in seconds (default is None). - bike_maneuver_penalty : Optional[float], optional - Valhalla parameter: penalty applied to maneuvers when biking, in seconds (default is None). - bike_use_living_streets : Optional[float], optional - Valhalla parameter: preference for using living streets when biking, from 0 (avoid) to 1 (prefer) (default is None). + Args: + resource_path: The resource path to fetch journey data for. + request: Journey request containing all query parameters. - Returns - ------- - Sequence[Journey] - A list of Journey objects representing the journey results for the specified region. + Returns: + A list of Journey objects representing the journey results for the specified resource path. """ request_url = f"{self.base_navitia_url}/coverage/{resource_path}/journeys" - filters = { - "datetime": datetime_.isoformat(), - "datetime_represents": datetime_represents, - "traveler_type": traveler_type, - "data_freshness": data_freshness, - "language": language, - "depth": depth, - "max_duration_to_pt": max_duration_to_pt, - "walking_speed": walking_speed, - "bike_speed": bike_speed, - "bss_speed": bss_speed, - "car_speed": car_speed, - "min_nb_journeys": min_nb_journeys, - "max_nb_journeys": max_nb_journeys, - "count": count, - "max_nb_transfers": max_nb_transfers, - "min_nb_transfers": min_nb_transfers, - "max_duration": max_duration, - "wheelchair": wheelchair, - "direct_path": direct_path, - "debug": debug, - "free_radius_from": free_radius_from, - "free_radius_to": free_radius_to, - "timeframe_duration": timeframe_duration, - "is_journey_schedules": is_journey_schedules, - } - - if from_: - filters["from"] = from_ - - if to_: - filters["to"] = to_ - - filters["park_mode"] = park_mode.value - - if bike_use_hills is not None: - filters["bike_use_hills"] = bike_use_hills - - if walking_use_hills is not None: - filters["walking_use_hills"] = walking_use_hills - - if bike_avoid_bad_surfaces is not None: - filters["bike_avoid_bad_surfaces"] = bike_avoid_bad_surfaces - - if walking_step_penalty is not None: - filters["walking_step_penalty"] = walking_step_penalty - - if bike_maneuver_penalty is not None: - filters["bike_maneuver_penalty"] = bike_maneuver_penalty - - if bike_use_living_streets is not None: - filters["bike_use_living_streets"] = bike_use_living_streets - - if forbidden_uris: - filters["forbidden_uris[]"] = forbidden_uris - - if allowed_id: - filters["allowed_id[]"] = allowed_id - - if first_section_mode: - filters["first_section_mode[]"] = first_section_mode - - if last_section_mode: - filters["last_section_mode[]"] = last_section_mode - - if add_poi_infos: - filters["add_poi_infos[]"] = add_poi_infos - - if any([direct_path_mode, first_section_mode]): - filters["direct_path_mode[]"] = direct_path_mode or first_section_mode - - return self._get_journeys(request_url, filters) + return self._get_journeys(request_url, request.to_filters()) diff --git a/navitia_client/client/apis/line_report_apis.py b/navitia_client/client/apis/line_report_apis.py index d4328ff..20e52dd 100644 --- a/navitia_client/client/apis/line_report_apis.py +++ b/navitia_client/client/apis/line_report_apis.py @@ -6,36 +6,21 @@ class LineReportsApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching line reports. + """Client class to interact with the Navitia API for fetching line reports. See https://doc.navitia.io/#line-reports - - Methods - ------- - _get_line_reports(url: str, filters: dict) -> Tuple[Sequence[Disruption], Sequence[LineReport]]: - Retrieves line reports from the specified URL with the provided filters. - - list_line_reports(region_id: Optional[str] = None, resource_path: Optional[str] = None, request: LineReportRequest = LineReportRequest()) -> Tuple[Sequence[Disruption], Sequence[LineReport]]: - Lists line reports based on specified criteria. """ def _get_line_reports( self, url: str, filters: dict ) -> Tuple[Sequence[Disruption], Sequence[LineReport]]: - """ - Retrieves line reports from the specified URL with the provided filters. + """Retrieve line reports from the specified URL with the provided filters. - Parameters - ---------- - url : str - The URL to fetch line reports from. - filters : dict - Filters to apply to the API request. + Args: + url: The URL to fetch line reports from. + filters: Filters to apply to the API request. - Returns - ------- - Tuple[Sequence[Disruption], Sequence[LineReport]] + Returns: A tuple containing sequences of Disruption and LineReport objects. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) @@ -49,25 +34,18 @@ def _get_line_reports( def list_line_reports( self, + request: LineReportRequest, region_id: Optional[str] = None, resource_path: Optional[str] = None, - request: LineReportRequest = LineReportRequest(), ) -> Tuple[Sequence[Disruption], Sequence[LineReport]]: - """ - Lists line reports based on specified criteria. + """List line reports based on specified criteria. - Parameters - ---------- - region_id : Optional[str], optional - The ID of the region for which to fetch line reports, by default None. - resource_path : Optional[str], optional - The resource path for line reports, by default None. - request : LineReportRequest, optional - The request object containing query parameters. + Args: + request: The request object containing query parameters. + region_id: The ID of the region for which to fetch line reports, by default None. + resource_path: The resource path for line reports, by default None. - Returns - ------- - Tuple[Sequence[Disruption], Sequence[LineReport]] + Returns: A tuple containing sequences of Disruption and LineReport objects. """ if resource_path: diff --git a/navitia_client/client/apis/place_apis.py b/navitia_client/client/apis/place_apis.py index fe8d186..2bb6d83 100644 --- a/navitia_client/client/apis/place_apis.py +++ b/navitia_client/client/apis/place_apis.py @@ -5,35 +5,20 @@ class PlacesApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching place information. + """Client class to interact with the Navitia API for fetching place information. See https://doc.navitia.io/#places - - Methods - ------- - _get_pt_objects_from_response(response: Any) -> Sequence[Place] - A static method to transform raw API response data into a list of Place objects. - - list_places( - region_id: str, query: str, - type: Sequence[str] = ["stop_area", "address", "poi", "administrative_region"], - disable_geojson: bool = False, depth: int = 1, - from_lon_lat: Optional[Tuple[float, float]] = None - ) -> Sequence[Place] - Retrieves a list of places based on the provided query and region ID from the Navitia API. """ @staticmethod def _get_pt_objects_from_response(response: Any) -> Sequence[Place]: - """ - Transform raw API response data into a list of Place objects. + """Transform raw API response data into a list of Place objects. - Parameters: - response (Any): The raw API response data. + Args: + response: The raw API response data. Returns: - Sequence[Place]: A list of Place objects. + A list of Place objects. """ entities = [] for entity_data in response: @@ -45,15 +30,14 @@ def list_places( region_id: str, request: PlaceRequest, ) -> Sequence[Place]: - """ - Retrieves a list of places based on the provided query and region ID from the Navitia API. + """Retrieve a list of places based on the provided query and region ID. - Parameters: - region_id (str): The region ID. - request (PlaceRequest): The request object containing query parameters. + Args: + region_id: The region ID. + request: The request object containing query parameters. Returns: - Sequence[Place]: A list of Place objects matching the query. + A list of Place objects matching the query. """ request_url = f"{self.base_navitia_url}/coverage/{region_id}/places" results = self.get_navitia_api( diff --git a/navitia_client/client/apis/places_nearby_apis.py b/navitia_client/client/apis/places_nearby_apis.py index 4a43402..1400767 100644 --- a/navitia_client/client/apis/places_nearby_apis.py +++ b/navitia_client/client/apis/places_nearby_apis.py @@ -1,71 +1,25 @@ -from typing import Any, Optional, Sequence, Tuple +from typing import Any, Sequence, Tuple from navitia_client.client.apis.api_base_client import ApiBaseClient +from navitia_client.entities.request.places_nearby import PlacesNearbyRequest from navitia_client.entities.response import Pagination from navitia_client.entities.response.place import Place class PlacesNearbyApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching nearby places information. + """A client class to interact with the Navitia API for fetching nearby places information. See https://doc.navitia.io/#places_nearby - - Methods - ------- - _get_pt_objects_from_response(response: Any) -> Sequence[Place] - A static method to transform raw API response data into a list of Place objects. - - list_objects_by_region_id_and_path( - region_id: str, resource_path: str, - distance: int = 500, type: Sequence[str] = ["stop_area", "stop_point", "poi"], - admin_uri: Optional[Sequence[str]] = None, filter: Optional[str] = None, - disable_geojson: bool = False, disable_disruption: bool = False, - depth: int = 1, start_page: int = 0, count: int = 25, - add_poi_infos: Sequence[str] = ["bss_stands", "car_park"] - ) -> Tuple[Sequence[Place], Pagination] - Retrieves a list of places nearby based on the region ID and resource path from the Navitia API. - - list_objects_by_region_id_and_coordinates( - region_id: str, lon: float, lat: float, - distance: int = 500, type: Sequence[str] = ["stop_area", "stop_point", "poi"], - admin_uri: Optional[Sequence[str]] = None, filter: Optional[str] = None, - disable_geojson: bool = False, disable_disruption: bool = False, - depth: int = 1, start_page: int = 0, count: int = 25, - add_poi_infos: Sequence[str] = ["bss_stands", "car_park"] - ) -> Tuple[Sequence[Place], Pagination] - Retrieves a list of places nearby based on the region ID and coordinates from the Navitia API. - - list_objects_by_coordinates( - region_lon: float, region_lat: float, lon: float, lat: float, - distance: int = 500, type: Sequence[str] = ["stop_area", "stop_point", "poi"], - admin_uri: Optional[Sequence[str]] = None, filter: Optional[str] = None, - disable_geojson: bool = False, disable_disruption: bool = False, - depth: int = 1, start_page: int = 0, count: int = 25, - add_poi_infos: Sequence[str] = ["bss_stands", "car_park"] - ) -> Tuple[Sequence[Place], Pagination] - Retrieves a list of places nearby based on the coordinates from the Navitia API. - - list_objects_by_object_coordinates_only( - lon: float, lat: float, distance: int = 500, - type: Sequence[str] = ["stop_area", "stop_point", "poi"], - admin_uri: Optional[Sequence[str]] = None, filter: Optional[str] = None, - disable_geojson: bool = False, disable_disruption: bool = False, - depth: int = 1, start_page: int = 0, count: int = 25, - add_poi_infos: Sequence[str] = ["bss_stands", "car_park"] - ) -> Tuple[Sequence[Place], Pagination] - Retrieves a list of places nearby based on the coordinates only from the Navitia API. """ @staticmethod def _get_pt_objects_from_response(response: Any) -> Sequence[Place]: - """ - Transform raw API response data into a list of Place objects. + """Transform raw API response data into a list of Place objects. - Parameters: - response (Any): The raw API response data. + Args: + response: The raw API response data. Returns: - Sequence[Place]: A list of Place objects. + A list of Place objects. """ entities = [] for entity_data in response: @@ -76,16 +30,14 @@ def _get_pt_objects_from_response(response: Any) -> Sequence[Place]: def _get_places_nearby( self, url: str, filters: dict ) -> Tuple[Sequence[Place], Pagination]: - """ - Fetches nearby places based on the provided URL and filters. + """Fetch nearby places based on the provided URL and filters. - Parameters: - url (str): The URL for the API request. - filters (dict): Filters to be applied to the API request. + Args: + url: The URL for the API request. + filters: Filters to be applied to the API request. Returns: - Tuple[Sequence[Place], Pagination]: A tuple containing a list of nearby Place objects - and pagination information. + A tuple containing a list of nearby Place objects and pagination information. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) raw_results = results.json()["places_nearby"] @@ -96,129 +48,45 @@ def list_objects_by_region_id_and_path( self, region_id: str, resource_path: str, - distance: int = 500, - type: Sequence[str] = ["stop_area", "stop_point", "poi"], - admin_uri: Optional[Sequence[str]] = None, - filter: Optional[str] = None, - disable_geojson: bool = False, - disable_disruption: bool = False, - depth: int = 1, - start_page: int = 0, - count: int = 25, - add_poi_infos: Sequence[str] = ["bss_stands", "car_park"], + request: PlacesNearbyRequest, ) -> Tuple[Sequence[Place], Pagination]: - """ - Retrieves a list of places nearby based on the region ID and resource path from the Navitia API. + """Retrieve a list of places nearby based on region ID and resource path. - Parameters: - region_id (str): The region ID. - resource_path (str): The resource path. - distance (int, optional): The distance for nearby search. Defaults to 500. - type (Sequence[str], optional): The types of places to include in the search. - Defaults to ["stop_area", "stop_point", "poi"]. - admin_uri (Optional[Sequence[str]], optional): The administrative URIs to filter by. - Defaults to None. - filter (Optional[str], optional): Additional filtering criteria. Defaults to None. - disable_geojson (bool, optional): Whether to disable GeoJSON format in the response. - Defaults to False. - disable_disruption (bool, optional): Whether to disable disruption information. - Defaults to False. - depth (int, optional): The depth of data to retrieve. Defaults to 1. - start_page (int, optional): The starting page for pagination. Defaults to 0. - count (int, optional): The number of items per page. Defaults to 25. - add_poi_infos (Sequence[str], optional): Additional POI information to include. - Defaults to ["bss_stands", "car_park"]. + Args: + region_id: The region ID. + resource_path: The resource path. + request: The PlacesNearbyRequest containing filters and parameters for the query. Returns: - Tuple[Sequence[Place], Pagination]: A tuple containing a list of nearby Place objects - and pagination information. + A tuple containing a list of nearby Place objects and pagination information. """ request_url = f"{self.base_navitia_url}/coverage/{region_id}/{resource_path}/places_nearby" - filters = { - "start_page": start_page, - "count": count, - "depth": depth, - "type[]": type, - "distance": distance, - "disable_geojson": disable_geojson, - "disable_disruption": disable_disruption, - "add_poi_infos[]": add_poi_infos, - } - - if admin_uri: - filters["admin_uris[]"] = admin_uri - - if filter: - filters["filter"] = filter - - return self._get_places_nearby(request_url, filters) + return self._get_places_nearby(request_url, request.to_filters()) def list_objects_by_region_id_and_coordinates( self, region_id: str, lon: float, lat: float, - distance: int = 500, - type: Sequence[str] = ["stop_area", "stop_point", "poi"], - admin_uri: Optional[Sequence[str]] = None, - filter: Optional[str] = None, - disable_geojson: bool = False, - disable_disruption: bool = False, - depth: int = 1, - start_page: int = 0, - count: int = 25, - add_poi_infos: Sequence[str] = ["bss_stands", "car_park"], + request: PlacesNearbyRequest, ) -> Tuple[Sequence[Place], Pagination]: - """ - Retrieves a list of places nearby based on the region ID and coordinates from the Navitia API. + """Retrieve a list of places nearby based on region ID and coordinates. - Parameters: - region_id (str): The region ID. - lon (float): The longitude coordinate. - lat (float): The latitude coordinate. - distance (int, optional): The distance for nearby search. Defaults to 500. - type (Sequence[str], optional): The types of places to include in the search. - Defaults to ["stop_area", "stop_point", "poi"]. - admin_uri (Optional[Sequence[str]], optional): The administrative URIs to filter by. - Defaults to None. - filter (Optional[str], optional): Additional filtering criteria. Defaults to None. - disable_geojson (bool, optional): Whether to disable GeoJSON format in the response. - Defaults to False. - disable_disruption (bool, optional): Whether to disable disruption information. - Defaults to False. - depth (int, optional): The depth of data to retrieve. Defaults to 1. - start_page (int, optional): The starting page for pagination. Defaults to 0. - count (int, optional): The number of items per page. Defaults to 25. - add_poi_infos (Sequence[str], optional): Additional POI information to include. - Defaults to ["bss_stands", "car_park"]. + Args: + region_id: The region ID. + lon: The longitude coordinate. + lat: The latitude coordinate. + request: The PlacesNearbyRequest containing filters and parameters for the query. Returns: - Tuple[Sequence[Place], Pagination]: A tuple containing a list of nearby Place objects - and pagination information. + A tuple containing a list of nearby Place objects and pagination information. """ request_url = ( f"{self.base_navitia_url}/coverage/{region_id}/{lon};{lat}/places_nearby" ) - filters = { - "start_page": start_page, - "count": count, - "depth": depth, - "type[]": type, - "distance": distance, - "disable_geojson": disable_geojson, - "disable_disruption": disable_disruption, - "add_poi_infos[]": add_poi_infos, - } - - if admin_uri: - filters["admin_uris[]"] = admin_uri - - if filter: - filters["filter"] = filter - - return self._get_places_nearby(request_url, filters) + return self._get_places_nearby(request_url, request.to_filters()) def list_objects_by_coordinates( self, @@ -226,124 +94,40 @@ def list_objects_by_coordinates( region_lat: float, lon: float, lat: float, - distance: int = 500, - type: Sequence[str] = ["stop_area", "stop_point", "poi"], - admin_uri: Optional[Sequence[str]] = None, - filter: Optional[str] = None, - disable_geojson: bool = False, - disable_disruption: bool = False, - depth: int = 1, - start_page: int = 0, - count: int = 25, - add_poi_infos: Sequence[str] = ["bss_stands", "car_park"], + request: PlacesNearbyRequest, ) -> Tuple[Sequence[Place], Pagination]: - """ - Retrieves a list of places nearby based on the provided coordinates from the Navitia API. + """Retrieve a list of places nearby based on the provided coordinates. - Parameters: - region_lon (float): The longitude coordinate of the region. - region_lat (float): The latitude coordinate of the region. - lon (float): The longitude coordinate. - lat (float): The latitude coordinate. - distance (int, optional): The distance for nearby search. Defaults to 500. - type (Sequence[str], optional): The types of places to include in the search. - Defaults to ["stop_area", "stop_point", "poi"]. - admin_uri (Optional[Sequence[str]], optional): The administrative URIs to filter by. - Defaults to None. - filter (Optional[str], optional): Additional filtering criteria. Defaults to None. - disable_geojson (bool, optional): Whether to disable GeoJSON format in the response. - Defaults to False. - disable_disruption (bool, optional): Whether to disable disruption information. - Defaults to False. - depth (int, optional): The depth of data to retrieve. Defaults to 1. - start_page (int, optional): The starting page for pagination. Defaults to 0. - count (int, optional): The number of items per page. Defaults to 25. - add_poi_infos (Sequence[str], optional): Additional POI information to include. - Defaults to ["bss_stands", "car_park"]. + Args: + region_lon: The longitude coordinate of the region. + region_lat: The latitude coordinate of the region. + lon: The longitude coordinate. + lat: The latitude coordinate. + request: The PlacesNearbyRequest containing filters and parameters for the query. Returns: - Tuple[Sequence[Place], Pagination]: A tuple containing a list of nearby Place objects - and pagination information. + A tuple containing a list of nearby Place objects and pagination information. """ request_url = f"{self.base_navitia_url}/coverage/{region_lon};{region_lat}/coords/{lon};{lat}/places_nearby" - filters = { - "start_page": start_page, - "count": count, - "depth": depth, - "type[]": type, - "distance": distance, - "disable_geojson": disable_geojson, - "disable_disruption": disable_disruption, - "add_poi_infos[]": add_poi_infos, - } - - if admin_uri: - filters["admin_uris[]"] = admin_uri - - if filter: - filters["filter"] = filter - - return self._get_places_nearby(request_url, filters) + return self._get_places_nearby(request_url, request.to_filters()) def list_objects_by_object_coordinates_only( self, lon: float, lat: float, - distance: int = 500, - type: Sequence[str] = ["stop_area", "stop_point", "poi"], - admin_uri: Optional[Sequence[str]] = None, - filter: Optional[str] = None, - disable_geojson: bool = False, - disable_disruption: bool = False, - depth: int = 1, - start_page: int = 0, - count: int = 25, - add_poi_infos: Sequence[str] = ["bss_stands", "car_park"], + request: PlacesNearbyRequest, ) -> Tuple[Sequence[Place], Pagination]: - """ - Retrieves a list of places nearby based on the provided coordinates from the Navitia API. + """Retrieve a list of places nearby based on the provided coordinates. - Parameters: - lon (float): The longitude coordinate. - lat (float): The latitude coordinate. - distance (int, optional): The distance for nearby search. Defaults to 500. - type (Sequence[str], optional): The types of places to include in the search. - Defaults to ["stop_area", "stop_point", "poi"]. - admin_uri (Optional[Sequence[str]], optional): The administrative URIs to filter by. - Defaults to None. - filter (Optional[str], optional): Additional filtering criteria. Defaults to None. - disable_geojson (bool, optional): Whether to disable GeoJSON format in the response. - Defaults to False. - disable_disruption (bool, optional): Whether to disable disruption information. - Defaults to False. - depth (int, optional): The depth of data to retrieve. Defaults to 1. - start_page (int, optional): The starting page for pagination. Defaults to 0. - count (int, optional): The number of items per page. Defaults to 25. - add_poi_infos (Sequence[str], optional): Additional POI information to include. - Defaults to ["bss_stands", "car_park"]. + Args: + lon: The longitude coordinate. + lat: The latitude coordinate. + request: The PlacesNearbyRequest containing filters and parameters for the query. Returns: - Tuple[Sequence[Place], Pagination]: A tuple containing a list of nearby Place objects - and pagination information. + A tuple containing a list of nearby Place objects and pagination information. """ request_url = f"{self.base_navitia_url}/coverage/{lon};{lat}/places_nearby" - filters = { - "start_page": start_page, - "count": count, - "depth": depth, - "type[]": type, - "distance": distance, - "disable_geojson": disable_geojson, - "disable_disruption": disable_disruption, - "add_poi_infos[]": add_poi_infos, - } - - if admin_uri: - filters["admin_uris[]"] = admin_uri - - if filter: - filters["filter"] = filter - - return self._get_places_nearby(request_url, filters) + return self._get_places_nearby(request_url, request.to_filters()) diff --git a/navitia_client/client/apis/public_transport_objects_apis.py b/navitia_client/client/apis/public_transport_objects_apis.py index b1a3e32..fea6be4 100644 --- a/navitia_client/client/apis/public_transport_objects_apis.py +++ b/navitia_client/client/apis/public_transport_objects_apis.py @@ -7,43 +7,20 @@ class PublicTransportObjectsApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching public transport objects. + """Client class to interact with the Navitia API for fetching public transport objects. See https://doc.navitia.io/#pt-objects - - Methods - ------- - _get_pt_objects_from_response(response: Any) -> Sequence[PtObject]: - A static method to transform raw API response data into a list of PtObject objects. - - list_public_transport_objects( - region_id: str, - query: str, - type: Sequence[str] = [ - "network", - "commercial_mode", - "line", - "route", - "stop_area", - ], - disable_disruption: bool = False, - depth: int = 1, - post_query_filter: Optional[str] = None, - ) -> Sequence[PtObject]: - Retrieves a list of public transport objects for a specified region from the Navitia API. """ @staticmethod def _get_pt_objects_from_response(response: Any) -> Sequence[PtObject]: - """ - Static method to transform raw API response data into a list of PtObject objects. + """Transform raw API response data into a list of PtObject objects. - Parameters: - response (Any): The raw API response data. + Args: + response: The raw API response data. Returns: - Sequence[PtObject]: A sequence of PtObject objects. + A sequence of PtObject objects. """ pt_objects = [] for pt_objects_data in response: @@ -56,15 +33,14 @@ def list_public_transport_objects( region_id: str, request: PublicTransportObjectRequest, ) -> Sequence[PtObject]: - """ - Retrieves a list of public transport objects for a specified region from the Navitia API. + """Retrieve a list of public transport objects for a specified region. - Parameters: - region_id (str): The region ID. - request (PublicTransportObjectRequest): The request object containing query parameters. + Args: + region_id: The region ID. + request: The request object containing query parameters. Returns: - Sequence[PtObject]: A sequence of PtObject objects. + A sequence of PtObject objects. """ request_url = f"{self.base_navitia_url}/coverage/{region_id}/pt_objects" results = self.get_navitia_api( diff --git a/navitia_client/client/apis/route_schedules_apis.py b/navitia_client/client/apis/route_schedules_apis.py index 77de3cf..c4ee05f 100644 --- a/navitia_client/client/apis/route_schedules_apis.py +++ b/navitia_client/client/apis/route_schedules_apis.py @@ -5,9 +5,7 @@ class RouteSchedulesApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching route schedules. - Uses the RouteScheduleRequest class to encapsulate query parameters. + """Client class to interact with the Navitia API for fetching route schedules. See https://doc.navitia.io/#route-schedules """ @@ -16,14 +14,13 @@ class RouteSchedulesApiClient(ApiBaseClient): def _get_route_schedule_object_from_response( response: Any, ) -> Sequence[RouteSchedule]: - """ - Static method to transform raw API response data into a list of RouteSchedule objects. + """Transform raw API response data into a list of RouteSchedule objects. - Parameters: - response (Any): The raw API response data. + Args: + response: The raw API response data. Returns: - Sequence[RouteSchedule]: A sequence of RouteSchedule objects. + A sequence of RouteSchedule objects. """ route_schedules = [] for route_schedule_data in response: @@ -32,15 +29,14 @@ def _get_route_schedule_object_from_response( return route_schedules def _get_routes_nearby(self, url: str, filters: dict) -> Sequence[RouteSchedule]: - """ - Retrieves route schedules from the Navitia API based on provided URL and filters. + """Retrieve route schedules from the Navitia API based on provided URL and filters. - Parameters: - url (str): The URL for the API request. - filters (dict): Filters to apply to the API request. + Args: + url: The URL for the API request. + filters: Filters to apply to the API request. Returns: - Sequence[RouteSchedule]: A sequence of RouteSchedule objects. + A sequence of RouteSchedule objects. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) raw_results = results.json()["route_schedules"] @@ -52,23 +48,14 @@ def list_route_schedules_by_region_id_and_path( resource_path: str, request: RouteScheduleRequest, ) -> Sequence[RouteSchedule]: - """ - Retrieves route schedules for a specified region and resource path from the Navitia API. - - Parameters - ---------- - region_id : str - The region ID. - resource_path : str - The resource path. - request : RouteScheduleRequest - The request object containing query parameters such as from_datetime, - duration, depth, count, start_page, items_per_schedule, forbidden_uris, - data_freshness, disable_geojson, and direction_type. - - Returns - ------- - Sequence[RouteSchedule] + """Retrieve route schedules for a specified region and resource path. + + Args: + region_id: The region ID. + resource_path: The resource path. + request: The request object containing query parameters. + + Returns: A sequence of RouteSchedule objects. """ request_url = f"{self.base_navitia_url}/coverage/{region_id}/{resource_path}/route_schedules" @@ -83,27 +70,16 @@ def list_route_schedules_by_coordinates( lat: float, request: RouteScheduleRequest, ) -> Sequence[RouteSchedule]: - """ - Retrieves route schedules for a specified set of coordinates from the Navitia API. - - Parameters - ---------- - region_lon : float - The longitude of the region. - region_lat : float - The latitude of the region. - lon : float - The longitude of the coordinates. - lat : float - The latitude of the coordinates. - request : RouteScheduleRequest - The request object containing query parameters such as from_datetime, - duration, depth, count, start_page, items_per_schedule, forbidden_uris, - data_freshness, disable_geojson, and direction_type. - - Returns - ------- - Sequence[RouteSchedule] + """Retrieve route schedules for a specified set of coordinates. + + Args: + region_lon: The longitude of the region. + region_lat: The latitude of the region. + lon: The longitude of the coordinates. + lat: The latitude of the coordinates. + request: The request object containing query parameters. + + Returns: A sequence of RouteSchedule objects. """ request_url = f"{self.base_navitia_url}/coverage/{region_lon};{region_lat}/coords/{lon};{lat}/route_schedules" diff --git a/navitia_client/client/apis/stop_schedules_apis.py b/navitia_client/client/apis/stop_schedules_apis.py index 5c8f59a..ecd95fc 100644 --- a/navitia_client/client/apis/stop_schedules_apis.py +++ b/navitia_client/client/apis/stop_schedules_apis.py @@ -6,9 +6,7 @@ class StopSchedulesApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching stop schedules. - Uses the StopScheduleRequest class to encapsulate query parameters. + """Client class to interact with the Navitia API for fetching stop schedules. See https://doc.navitia.io/#stop-schedules """ @@ -17,14 +15,13 @@ class StopSchedulesApiClient(ApiBaseClient): def _get_stop_schedule_objects_from_response( response: Any, ) -> Sequence[StopSchedule]: - """ - Static method to transform raw API response data into a list of StopSchedule objects. + """Transform raw API response data into a list of StopSchedule objects. - Parameters: - response (Any): The raw API response data. + Args: + response: The raw API response data. Returns: - Sequence[StopSchedule]: A sequence of StopSchedule objects. + A sequence of StopSchedule objects. """ stop_schedules = [] for stop_schedule_data in response: @@ -35,15 +32,14 @@ def _get_stop_schedule_objects_from_response( def _get_stop_schedules( self, url: str, filters: dict ) -> Tuple[Sequence[StopSchedule], Pagination]: - """ - Retrieves stop schedules from the Navitia API based on provided URL and filters. + """Retrieve stop schedules from the Navitia API based on provided URL and filters. - Parameters: - url (str): The URL for the API request. - filters (dict): Filters to apply to the API request. + Args: + url: The URL for the API request. + filters: Filters to apply to the API request. Returns: - Tuple[Sequence[StopSchedule], Pagination]: A tuple containing a sequence of StopSchedule objects and Pagination object. + A tuple containing a sequence of StopSchedule objects and Pagination object. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) raw_results = results.json()["stop_schedules"] @@ -58,27 +54,16 @@ def list_stop_schedules_by_coordinates( lat: float, request: StopScheduleRequest, ) -> Tuple[Sequence[StopSchedule], Pagination]: - """ - Retrieves stop schedules for a specified set of coordinates from the Navitia API. - - Parameters - ---------- - region_lon : float - The longitude of the region. - region_lat : float - The latitude of the region. - lon : float - The longitude of the coordinates. - lat : float - The latitude of the coordinates. - request : StopScheduleRequest - The request object containing query parameters such as from_datetime, - duration, depth, count, start_page, items_per_schedule, forbidden_uris, - data_freshness, disable_geojson, and direction_type. - - Returns - ------- - Tuple[Sequence[StopSchedule], Pagination] + """Retrieve stop schedules for a specified set of coordinates. + + Args: + region_lon: The longitude of the region. + region_lat: The latitude of the region. + lon: The longitude of the coordinates. + lat: The latitude of the coordinates. + request: The request object containing query parameters. + + Returns: A tuple containing a sequence of StopSchedule objects and Pagination object. """ request_url = f"{self.base_navitia_url}/coverage/{region_lon};{region_lat}/coords/{lon};{lat}/stop_schedules" @@ -91,23 +76,14 @@ def list_stop_schedules_by_region_id_and_path( resource_path: str, request: StopScheduleRequest, ) -> Tuple[Sequence[StopSchedule], Pagination]: - """ - Retrieves stop schedules for a specified region and resource path from the Navitia API. - - Parameters - ---------- - region_id : str - The region ID. - resource_path : str - The resource path. - request : StopScheduleRequest - The request object containing query parameters such as from_datetime, - duration, depth, count, start_page, items_per_schedule, forbidden_uris, - data_freshness, disable_geojson, and direction_type. - - Returns - ------- - Tuple[Sequence[StopSchedule], Pagination] + """Retrieve stop schedules for a specified region and resource path. + + Args: + region_id: The region ID. + resource_path: The resource path. + request: The request object containing query parameters. + + Returns: A tuple containing a sequence of StopSchedule objects and Pagination object. """ request_url = f"{self.base_navitia_url}/coverage/{region_id}/{resource_path}/stop_schedules" diff --git a/navitia_client/client/apis/terminus_schedules_apis.py b/navitia_client/client/apis/terminus_schedules_apis.py index 696cd3a..02ad732 100644 --- a/navitia_client/client/apis/terminus_schedules_apis.py +++ b/navitia_client/client/apis/terminus_schedules_apis.py @@ -6,9 +6,7 @@ class TerminusSchedulesApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching terminus schedules. - Uses the TerminusScheduleRequest class to encapsulate query parameters. + """Client class to interact with the Navitia API for fetching terminus schedules. See https://doc.navitia.io/#terminus-schedules """ @@ -17,14 +15,13 @@ class TerminusSchedulesApiClient(ApiBaseClient): def _get_terminus_schedule_objects_from_response( response: Any, ) -> Sequence[TerminusSchedule]: - """ - Static method to transform raw API response data into a list of TerminusSchedule objects. + """Transform raw API response data into a list of TerminusSchedule objects. - Parameters: - response (Any): The raw API response data. + Args: + response: The raw API response data. Returns: - Sequence[TerminusSchedule]: A sequence of TerminusSchedule objects. + A sequence of TerminusSchedule objects. """ terminus_schedules = [] for terminus_schedule_data in response: @@ -37,15 +34,14 @@ def _get_terminus_schedule_objects_from_response( def _get_stop_schedules( self, url: str, filters: dict ) -> Tuple[Sequence[TerminusSchedule], Pagination]: - """ - Retrieves terminus schedules from the Navitia API based on provided URL and filters. + """Retrieve terminus schedules from the Navitia API based on provided URL and filters. - Parameters: - url (str): The URL for the API request. - filters (dict): Filters to apply to the API request. + Args: + url: The URL for the API request. + filters: Filters to apply to the API request. Returns: - Tuple[Sequence[TerminusSchedule], Pagination]: A tuple containing a sequence of TerminusSchedule objects and Pagination object. + A tuple containing a sequence of TerminusSchedule objects and Pagination object. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) raw_results = results.json()["terminus_schedules"] @@ -60,23 +56,14 @@ def list_terminus_schedules_by_region_id_and_path( resource_path: str, request: TerminusScheduleRequest, ) -> Tuple[Sequence[TerminusSchedule], Pagination]: - """ - Retrieves terminus schedules for a specified region and resource path from the Navitia API. - - Parameters - ---------- - region_id : str - The region ID. - resource_path : str - The resource path. - request : TerminusScheduleRequest - The request object containing query parameters such as from_datetime, - duration, depth, count, start_page, items_per_schedule, forbidden_uris, - data_freshness, disable_geojson, and direction_type. - - Returns - ------- - Tuple[Sequence[TerminusSchedule], Pagination] + """Retrieve terminus schedules for a specified region and resource path. + + Args: + region_id: The region ID. + resource_path: The resource path. + request: The request object containing query parameters. + + Returns: A tuple containing a sequence of TerminusSchedule objects and Pagination object. """ request_url = f"{self.base_navitia_url}/coverage/{region_id}/{resource_path}/terminus_schedules" @@ -91,27 +78,16 @@ def list_terminus_schedules_by_coordinates( lat: float, request: TerminusScheduleRequest, ) -> Tuple[Sequence[TerminusSchedule], Pagination]: - """ - Retrieves terminus schedules for a specified set of coordinates from the Navitia API. - - Parameters - ---------- - region_lon : float - The longitude of the region. - region_lat : float - The latitude of the region. - lon : float - The longitude of the coordinates. - lat : float - The latitude of the coordinates. - request : TerminusScheduleRequest - The request object containing query parameters such as from_datetime, - duration, depth, count, start_page, items_per_schedule, forbidden_uris, - data_freshness, disable_geojson, and direction_type. - - Returns - ------- - Tuple[Sequence[TerminusSchedule], Pagination] + """Retrieve terminus schedules for a specified set of coordinates. + + Args: + region_lon: The longitude of the region. + region_lat: The latitude of the region. + lon: The longitude of the coordinates. + lat: The latitude of the coordinates. + request: The request object containing query parameters. + + Returns: A tuple containing a sequence of TerminusSchedule objects and Pagination object. """ request_url = f"{self.base_navitia_url}/coverage/{region_lon};{region_lat}/coords/{lon};{lat}/terminus_schedules" diff --git a/navitia_client/client/apis/traffic_report_apis.py b/navitia_client/client/apis/traffic_report_apis.py index 4e4a44a..04fdc97 100644 --- a/navitia_client/client/apis/traffic_report_apis.py +++ b/navitia_client/client/apis/traffic_report_apis.py @@ -7,38 +7,22 @@ class TrafficReportsApiClient(ApiBaseClient): - """ - A client class to interact with the Navitia API for fetching traffic reports. + """Client class to interact with the Navitia API for fetching traffic reports. See https://doc.navitia.io/#traffic-reports - - Methods - ------- - _get_traffic_reports( - url: str, filters: dict - ) -> Tuple[Sequence[Disruption], Sequence[TrafficReport], Pagination]: - Retrieves traffic reports from the Navitia API based on provided URL and filters. - - list_traffic_reports( - region_id: Optional[str] = None, - resource_path: Optional[str] = None, - request: TrafficReportRequest = TrafficReportRequest(), - ) -> Tuple[Sequence[Disruption], Sequence[TrafficReport], Pagination]: - Retrieves traffic reports for a specified region and resource path from the Navitia API. """ def _get_traffic_reports( self, url: str, filters: dict ) -> Tuple[Sequence[Disruption], Sequence[TrafficReport], Pagination]: - """ - Retrieves traffic reports from the Navitia API based on provided URL and filters. + """Retrieve traffic reports from the Navitia API based on provided URL and filters. - Parameters: - url (str): The URL for the API request. - filters (dict): Filters to apply to the API request. + Args: + url: The URL for the API request. + filters: Filters to apply to the API request. Returns: - Tuple[Sequence[Disruption], Sequence[TrafficReport], Pagination]: A tuple containing sequences of Disruption and TrafficReport objects, and Pagination object. + A tuple containing sequences of Disruption and TrafficReport objects, and Pagination object. """ results = self.get_navitia_api(url + self._generate_filter_query(filters)) line_reports = [ @@ -53,20 +37,19 @@ def _get_traffic_reports( def list_traffic_reports( self, + request: TrafficReportRequest, region_id: Optional[str] = None, resource_path: Optional[str] = None, - request: TrafficReportRequest = TrafficReportRequest(), ) -> Tuple[Sequence[Disruption], Sequence[TrafficReport], Pagination]: - """ - Retrieves traffic reports for a specified region and resource path from the Navitia API. + """Retrieve traffic reports for a specified region and resource path. - Parameters: - region_id (Optional[str]): The region ID. - resource_path (Optional[str]): The resource path. - request (TrafficReportRequest): The request object containing query parameters. + Args: + request: The request object containing query parameters. + region_id: The region ID. + resource_path: The resource path. Returns: - Tuple[Sequence[Disruption], Sequence[TrafficReport], Pagination]: A tuple containing sequences of Disruption and TrafficReport objects, and Pagination object. + A tuple containing sequences of Disruption and TrafficReport objects, and Pagination object. """ if resource_path: request_url = f"{self.base_navitia_url}/coverage/{region_id}/{resource_path}/traffic_reports" diff --git a/tests/client/apis/test_equipment_report_apis.py b/tests/client/apis/test_equipment_report_apis.py index b8ceb0f..a53ad5a 100644 --- a/tests/client/apis/test_equipment_report_apis.py +++ b/tests/client/apis/test_equipment_report_apis.py @@ -4,6 +4,7 @@ import pytest from navitia_client.client.apis.equipment_report_apis import EquipmentReportsApiClient +from navitia_client.entities.request.equipment_report import EquipmentReportRequest @pytest.fixture @@ -29,7 +30,7 @@ def test_list_equipment_reports( # When equipment_reports, pagination = equipment_report_apis.list_equipment_reports( - region_id="fr-idf" + region_id="fr-idf", request=EquipmentReportRequest() ) # Then @@ -57,7 +58,9 @@ def test_list_equipment_reports_with_resource_path( # When equipment_reports, pagination = ( equipment_report_apis.list_equipment_reports_with_resource_path( - region_id="fr-idf", resource_path="lines/line:IDFM:C01742" + region_id="fr-idf", + resource_path="lines/line:IDFM:C01742", + request=EquipmentReportRequest(), ) ) diff --git a/tests/client/apis/test_freefloatings_nearby_apis.py b/tests/client/apis/test_freefloatings_nearby_apis.py index 6595604..f031b25 100644 --- a/tests/client/apis/test_freefloatings_nearby_apis.py +++ b/tests/client/apis/test_freefloatings_nearby_apis.py @@ -6,6 +6,9 @@ from navitia_client.client.apis.freefloatings_nearby_apis import ( FreefloatingsNearbyApiClient, ) +from navitia_client.entities.request.freefloatings_nearby import ( + FreefloatingsNearbyRequest, +) @pytest.fixture @@ -32,7 +35,10 @@ def test_list_freefloatings_nearby( # When free_floatings, pagination = freefloatings_nearby_apis.list_freefloatings_nearby( - region_id="fr-idf", lon=2.3522, lat=48.8566 + region_id="fr-idf", + lon=2.3522, + lat=48.8566, + request=FreefloatingsNearbyRequest(), ) # Then @@ -70,7 +76,9 @@ def test_list_freefloatings_nearby_with_resource_path( free_floatings, pagination, ) = freefloatings_nearby_apis.list_freefloatings_nearby_with_resource_path( - region_id="fr-idf", resource_path="stop_areas/stop_area:IDFM:71591" + region_id="fr-idf", + resource_path="stop_areas/stop_area:IDFM:71591", + request=FreefloatingsNearbyRequest(), ) # Then diff --git a/tests/client/apis/test_journeys_apis.py b/tests/client/apis/test_journeys_apis.py index cb98c17..ee428e1 100644 --- a/tests/client/apis/test_journeys_apis.py +++ b/tests/client/apis/test_journeys_apis.py @@ -5,6 +5,7 @@ import pytest from navitia_client.client.apis.journeys_apis import JourneyApiClient +from navitia_client.entities.request.journey import JourneyRequest from navitia_client.entities.response import Journey @@ -27,7 +28,9 @@ def test_list_covered_areas_with_region_id( mock_get_navitia_api.return_value = mock_response # When - journeys = journeys_apis.list_journeys_with_region_id(region_id="bar") + journeys = journeys_apis.list_journeys_with_region_id( + region_id="bar", request=JourneyRequest() + ) # Then assert len(journeys) == 1 @@ -46,7 +49,9 @@ def test_list_covered_areas_with_resource_path( mock_get_navitia_api.return_value = mock_response # When - journeys = journeys_apis.list_journeys_with_resource_path(resource_path="bar") + journeys = journeys_apis.list_journeys_with_resource_path( + resource_path="bar", request=JourneyRequest() + ) # Then assert len(journeys) == 1 @@ -65,7 +70,8 @@ def test_list_covered_areas( mock_get_navitia_api.return_value = mock_response # When - journeys = journeys_apis.list_journeys(from_="foo") + request = JourneyRequest(from_="foo") + journeys = journeys_apis.list_journeys(request=request) # Then assert len(journeys) == 1 @@ -82,10 +88,11 @@ def test_list_empty_add_poi_infos_parameter( mock_response.json.return_value = json.load(file) mock_get_navitia_api.return_value = mock_response - expected_url = "https://api.navitia.io/v1//journeys?datetime=2024-06-01T00:00:00&datetime_represents=departure&traveler_type=standard&data_freshness=realtime&language=en-GB&depth=1&max_duration_to_pt=1800&walking_speed=1.12&bike_speed=4.1&bss_speed=4.1&car_speed=16.8&min_nb_journeys=1&max_nb_journeys=1&count=1&max_nb_transfers=10&min_nb_transfers=0&max_duration=86400&wheelchair=False&direct_path=indifferent&debug=False&free_radius_from=0&free_radius_to=0&timeframe_duration=0&is_journey_schedules=False&from=foo&park_mode=none" + expected_url = "https://api.navitia.io/v1//journeys?datetime=2024-06-01T00:00:00&datetime_represents=departure&traveler_type=standard&data_freshness=realtime&language=en-GB&depth=1&max_duration_to_pt=1800&walking_speed=1.12&bike_speed=4.1&bss_speed=4.1&car_speed=16.8&min_nb_journeys=1&max_nb_journeys=1&count=10&max_nb_transfers=10&min_nb_transfers=0&max_duration=86400&wheelchair=False&direct_path=indifferent&debug=False&free_radius_from=0&free_radius_to=0&timeframe_duration=0&is_journey_schedules=False&park_mode=none&from=foo" # When - journeys_apis.list_journeys(datetime_=datetime(2024, 6, 1), from_="foo") + request = JourneyRequest(datetime_=datetime(2024, 6, 1), from_="foo") + journeys_apis.list_journeys(request=request) # Then mock_get_navitia_api.assert_called_with(expected_url) @@ -101,14 +108,15 @@ def test_list_add_poi_infos_parameter( mock_response.json.return_value = json.load(file) mock_get_navitia_api.return_value = mock_response - expected_url = "https://api.navitia.io/v1//journeys?datetime=2024-06-01T00:00:00&datetime_represents=departure&traveler_type=standard&data_freshness=realtime&language=en-GB&depth=1&max_duration_to_pt=1800&walking_speed=1.12&bike_speed=4.1&bss_speed=4.1&car_speed=16.8&min_nb_journeys=1&max_nb_journeys=1&count=1&max_nb_transfers=10&min_nb_transfers=0&max_duration=86400&wheelchair=False&direct_path=indifferent&debug=False&free_radius_from=0&free_radius_to=0&timeframe_duration=0&is_journey_schedules=False&from=foo&park_mode=none&add_poi_infos[]=bss_stands&add_poi_infos[]=car_parks" + expected_url = "https://api.navitia.io/v1//journeys?datetime=2024-06-01T00:00:00&datetime_represents=departure&traveler_type=standard&data_freshness=realtime&language=en-GB&depth=1&max_duration_to_pt=1800&walking_speed=1.12&bike_speed=4.1&bss_speed=4.1&car_speed=16.8&min_nb_journeys=1&max_nb_journeys=1&count=10&max_nb_transfers=10&min_nb_transfers=0&max_duration=86400&wheelchair=False&direct_path=indifferent&debug=False&free_radius_from=0&free_radius_to=0&timeframe_duration=0&is_journey_schedules=False&park_mode=none&from=foo&add_poi_infos[]=bss_stands&add_poi_infos[]=car_parks" # When - journeys_apis.list_journeys( + request = JourneyRequest( datetime_=datetime(2024, 6, 1), from_="foo", add_poi_infos=["bss_stands", "car_parks"], ) + journeys_apis.list_journeys(request=request) # Then mock_get_navitia_api.assert_called_with(expected_url) diff --git a/tests/client/apis/test_line_report_apis.py b/tests/client/apis/test_line_report_apis.py index ee1fe5f..47e06a3 100644 --- a/tests/client/apis/test_line_report_apis.py +++ b/tests/client/apis/test_line_report_apis.py @@ -4,6 +4,7 @@ import pytest from navitia_client.client.apis.line_report_apis import LineReportsApiClient +from navitia_client.entities.request.line_report import LineReportRequest from navitia_client.entities.response.disruption import Disruption from navitia_client.entities.response.line_report import LineReport @@ -28,7 +29,7 @@ def test_list_covered_areas( # When disruptions, line_reports = line_reports_apis.list_line_reports( - region_id="bar", resource_path="foo" + request=LineReportRequest(), region_id="bar", resource_path="foo" ) # Then diff --git a/tests/client/apis/test_places_nearby_apis.py b/tests/client/apis/test_places_nearby_apis.py index 3caee15..8c123ff 100644 --- a/tests/client/apis/test_places_nearby_apis.py +++ b/tests/client/apis/test_places_nearby_apis.py @@ -4,6 +4,7 @@ import pytest from navitia_client.client.apis.places_nearby_apis import PlacesNearbyApiClient +from navitia_client.entities.request.places_nearby import PlacesNearbyRequest from navitia_client.entities.response.place import Place @@ -27,7 +28,9 @@ def test_list_objects( # When places, _ = places_nearby_apis.list_objects_by_region_id_and_path( - region_id="bar", resource_path="stop_area/foo:bar" + region_id="bar", + resource_path="stop_area/foo:bar", + request=PlacesNearbyRequest(), ) # Then diff --git a/tests/client/apis/test_traffic_report_apis.py b/tests/client/apis/test_traffic_report_apis.py index a1de00a..aba3bc1 100644 --- a/tests/client/apis/test_traffic_report_apis.py +++ b/tests/client/apis/test_traffic_report_apis.py @@ -4,6 +4,7 @@ import pytest from navitia_client.client.apis.traffic_report_apis import TrafficReportsApiClient +from navitia_client.entities.request.traffic_report import TrafficReportRequest from navitia_client.entities.response.disruption import Disruption from navitia_client.entities.response.traffic_report import TrafficReport @@ -28,7 +29,7 @@ def test_list_covered_areas( # When disruptions, traffic_report, _ = traffic_reports_apis.list_traffic_reports( - region_id="bar", resource_path="foo" + request=TrafficReportRequest(), region_id="bar", resource_path="foo" ) # Then