Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,27 @@


class CommercialModeApiClient(ApiBaseClient, EntityApi[CommercialMode]):
"""
API client for handling 'CommercialMode' entities in the Navitia API.
"""API client for handling 'CommercialMode' entities in the Navitia API.

See https://doc.navitia.io/#pt-ref

Attributes:
entity_name (str): The name of the entity.
entity_name: The name of the entity.
get_navitia_api: A method to get the Navitia API.

Methods:
_get_entity_from_response(raw_entity_response: Any) -> Sequence[CommercialMode]:
Extracts CommercialMode entities from the API response.

list_entity_collection_from_region(
region_id: str,
request: BasePTEntityRequest,
) -> Tuple[Sequence[CommercialMode], Pagination]:
Lists commercial modes from a specified region.

get_entity_by_id(
region_id: str,
object_id: str,
request: BasePTEntityRequest,
) -> Tuple[Sequence[CommercialMode], Pagination]:
Retrieves a specific commercial mode by its ID from a specified region.

list_entity_collection_from_coordinates(
lon: float,
lat: float,
request: BasePTEntityRequest,
) -> Tuple[Sequence[CommercialMode], Pagination]:
Lists commercial modes from specified coordinates.

get_entity_by_id_and_coordinates(
lon: float,
lat: float,
object_id: str,
request: BasePTEntityRequest,
) -> Tuple[Sequence[CommercialMode], Pagination]:
Retrieves a specific commercial mode by its ID from specified coordinates.
"""

entity_name: str = "commercial_modes"
get_navitia_api = ApiBaseClient.get_navitia_api

@staticmethod
def _get_entity_from_response(raw_entity_response: Any) -> Sequence[CommercialMode]:
"""
Extracts CommercialMode entities from the API response.
"""Extract CommercialMode entities from the API response.

Parameters:
raw_entity_response (Any): The raw response from the API.
Args:
raw_entity_response: The raw response from the API.

Returns:
Sequence[CommercialMode]: A sequence of CommercialMode objects.
A sequence of CommercialMode objects.
"""
entities = []
for entity in raw_entity_response:
Expand All @@ -73,15 +39,14 @@ def list_entity_collection_from_region(
region_id: str,
request: BasePTEntityRequest,
) -> Tuple[Sequence[CommercialMode], Pagination]:
"""
Lists commercial modes from a specified region.
"""List commercial modes from a specified region.

Parameters:
region_id (str): The ID of the region.
request (BasePTEntityRequest): Request parameters for filtering.
Args:
region_id: The ID of the region.
request: Request parameters for filtering.

Returns:
Tuple[Sequence[CommercialMode], Pagination]: A tuple containing a sequence of CommercialMode objects and Pagination object.
A tuple containing a sequence of CommercialMode objects and Pagination object.
"""
url = f"{self.base_navitia_url}/coverage/{region_id}/{self.entity_name}"
return self._get_entity_results(url, self.entity_name, request.to_filters())
Expand All @@ -92,16 +57,15 @@ def get_entity_by_id(
object_id: str,
request: BasePTEntityRequest,
) -> Tuple[Sequence[CommercialMode], Pagination]:
"""
Retrieves a specific commercial mode by its ID from a specified region.
"""Retrieve a specific commercial mode by its ID from a specified region.

Parameters:
region_id (str): The ID of the region.
object_id (str): The ID of the commercial mode.
request (BasePTEntityRequest): Request parameters for filtering.
Args:
region_id: The ID of the region.
object_id: The ID of the commercial mode.
request: Request parameters for filtering.

Returns:
Tuple[Sequence[CommercialMode], Pagination]: A tuple containing a sequence of CommercialMode objects and Pagination object.
A tuple containing a sequence of CommercialMode objects and Pagination object.
"""
url = f"{self.base_navitia_url}/coverage/{region_id}/{self.entity_name}/{object_id}"
return self._get_entity_results(url, self.entity_name, request.to_filters())
Expand All @@ -112,16 +76,15 @@ def list_entity_collection_from_coordinates(
lat: float,
request: BasePTEntityRequest,
) -> Tuple[Sequence[CommercialMode], Pagination]:
"""
Lists commercial modes from specified coordinates.
"""List commercial modes from specified coordinates.

Parameters:
lon (float): The longitude coordinate.
lat (float): The latitude coordinate.
request (BasePTEntityRequest): Request parameters for filtering.
Args:
lon: The longitude coordinate.
lat: The latitude coordinate.
request: Request parameters for filtering.

Returns:
Tuple[Sequence[CommercialMode], Pagination]: A tuple containing a sequence of CommercialMode objects and Pagination object.
A tuple containing a sequence of CommercialMode objects and Pagination object.
"""
url = f"{self.base_navitia_url}/coverage/{lon};{lat}/{self.entity_name}"
return self._get_entity_results(url, self.entity_name, request.to_filters())
Expand All @@ -133,17 +96,16 @@ def get_entity_by_id_and_coordinates(
object_id: str,
request: BasePTEntityRequest,
) -> Tuple[Sequence[CommercialMode], Pagination]:
"""
Retrieves a specific commercial mode by its ID from specified coordinates.
"""Retrieve a specific commercial mode by its ID from specified coordinates.

Parameters:
lon (float): The longitude coordinate.
lat (float): The latitude coordinate.
object_id (str): The ID of the commercial mode.
request (BasePTEntityRequest): Request parameters for filtering.
Args:
lon: The longitude coordinate.
lat: The latitude coordinate.
object_id: The ID of the commercial mode.
request: Request parameters for filtering.

Returns:
Tuple[Sequence[CommercialMode], Pagination]: A tuple containing a sequence of CommercialMode objects and Pagination object.
A tuple containing a sequence of CommercialMode objects and Pagination object.
"""
url = f"{self.base_navitia_url}/coverage/{lon};{lat}/{self.entity_name}/{object_id}"
return self._get_entity_results(url, self.entity_name, request.to_filters())
Loading