Skip to content

Commit c9c68be

Browse files
authored
fix(api): use request objects in all api clients (#97)
Changelog * Fix APIs missing usage of request objects * Update documentation * Fix tests
1 parent 9441d9b commit c9c68be

24 files changed

+477
-1826
lines changed

navitia_client/client/apis/arrival_apis.py

Lines changed: 28 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,21 @@
66

77

88
class ArrivalApiClient(ApiBaseClient):
9-
"""
10-
A client class to interact with the Navitia API for fetching arrival information.
9+
"""Client class to interact with the Navitia API for fetching arrival information.
1110
1211
See https://doc.navitia.io/#arrivals
13-
14-
Methods
15-
-------
16-
_get_departure_objects_from_response(response: Any) -> Sequence[Arrival]
17-
A static method to transform raw API response data into a list of Arrival objects.
18-
19-
_get_departures(url: str, filters: dict) -> Tuple[Sequence[Arrival], Pagination]
20-
Internal method to fetch departures based on a given URL and filters.
21-
22-
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]
23-
Retrieves a list of arrivals for a specific region and resource path.
24-
25-
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]
26-
Retrieves a list of arrivals for specific coordinates.
2712
"""
2813

2914
@staticmethod
3015
def _get_arrival_objects_from_response(
3116
response: Any,
3217
) -> Sequence[Arrival]:
33-
"""
34-
Converts raw response data into a list of Arrival objects.
18+
"""Convert raw response data into a list of Arrival objects.
3519
36-
Parameters
37-
----------
38-
response : Any
39-
The raw response data from the API containing arrivals' information.
20+
Args:
21+
response: The raw response data from the API containing arrivals' information.
4022
41-
Returns
42-
-------
43-
Sequence[Arrival]
23+
Returns:
4424
A list of Arrival objects created from the raw response data.
4525
"""
4626

@@ -53,19 +33,13 @@ def _get_arrival_objects_from_response(
5333
def _get_arrivals(
5434
self, url: str, filters: dict
5535
) -> Tuple[Sequence[Arrival], Pagination]:
56-
"""
57-
Internal method to fetch departures based on a given URL and filters.
58-
59-
Parameters
60-
----------
61-
url : str
62-
The URL for the API request.
63-
filters : dict
64-
The filters to apply to the API request.
65-
66-
Returns
67-
-------
68-
Tuple[Sequence[Arrival], Pagination]
36+
"""Fetch arrivals based on a given URL and filters.
37+
38+
Args:
39+
url: The URL for the API request.
40+
filters: The filters to apply to the API request.
41+
42+
Returns:
6943
A tuple containing a list of Arrival objects and a Pagination object for managing result pages.
7044
"""
7145
results = self.get_navitia_api(url + self._generate_filter_query(filters))
@@ -79,20 +53,14 @@ def list_arrivals_by_region_id_and_path(
7953
resource_path: str,
8054
request: ArrivalRequest,
8155
) -> Tuple[Sequence[Arrival], Pagination]:
82-
"""
83-
Retrieves a list of arrivals for a specific region and resource path.
84-
85-
Parameters
86-
----------
87-
region_id : str
88-
The identifier of the region to fetch arrivals from.
89-
resource_path : str
90-
The resource path within the region to fetch arrivals for.
56+
"""Retrieve a list of arrivals for a specific region and resource path.
9157
58+
Args:
59+
region_id: The identifier of the region to fetch arrivals from.
60+
resource_path: The resource path within the region to fetch arrivals for.
61+
request: The ArrivalRequest containing filters and parameters for the query.
9262
93-
Returns
94-
-------
95-
Tuple[Sequence[Arrival], Pagination]
63+
Returns:
9664
A tuple containing a list of Arrival objects and a Pagination object for managing result pages.
9765
"""
9866
request_url = (
@@ -109,23 +77,16 @@ def list_arrivals_by_coordinates(
10977
lat: float,
11078
request: ArrivalRequest,
11179
) -> Tuple[Sequence[Arrival], Pagination]:
112-
"""
113-
Retrieves a list of arrivals for specific coordinates.
114-
115-
Parameters
116-
----------
117-
region_lon : float
118-
The longitude of the region to fetch arrivals from.
119-
region_lat : float
120-
The latitude of the region to fetch arrivals from.
121-
lon : float
122-
The longitude of the specific location to fetch arrivals for.
123-
lat : float
124-
The latitude of the specific location to fetch arrivals for.
125-
126-
Returns
127-
-------
128-
Tuple[Sequence[Arrival], Pagination]
80+
"""Retrieve a list of arrivals for specific coordinates.
81+
82+
Args:
83+
region_lon: The longitude of the region to fetch arrivals from.
84+
region_lat: The latitude of the region to fetch arrivals from.
85+
lon: The longitude of the specific location to fetch arrivals for.
86+
lat: The latitude of the specific location to fetch arrivals for.
87+
request: The ArrivalRequest containing filters and parameters for the query.
88+
89+
Returns:
12990
A tuple containing a list of Arrival objects and a Pagination object for managing result pages.
13091
"""
13192
# List of objects near the resource, navitia guesses the region from coordinates

navitia_client/client/apis/contributors_apis.py

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88

99
class ContributorsApiClient(ApiBaseClient):
10-
"""
11-
A client class to interact with the Navitia API for fetching contributors APIs.
12-
Uses the ContributorRequest class to encapsulate query parameters.
10+
"""Client class to interact with the Navitia API for fetching contributors.
1311
1412
See https://doc.navitia.io/#contributors
1513
"""
@@ -18,17 +16,12 @@ class ContributorsApiClient(ApiBaseClient):
1816
def _get_contributors_from_response(
1917
raw_contributors_response: Any,
2018
) -> Sequence[Contributor]:
21-
"""
22-
Converts raw response data into a list of Contributor objects.
19+
"""Convert raw response data into a list of Contributor objects.
2320
24-
Parameters
25-
----------
26-
raw_contributors_response : Any
27-
The raw response data from the API containing contributors' information.
21+
Args:
22+
raw_contributors_response: The raw response data from the API containing contributors' information.
2823
29-
Returns
30-
-------
31-
Sequence[Contributor]
24+
Returns:
3225
A list of Contributor objects created from the raw response data.
3326
"""
3427
contributors = []
@@ -40,19 +33,13 @@ def _get_contributors_from_response(
4033
def list_contributors(
4134
self, region_id: str, request: ContributorRequest
4235
) -> Tuple[Sequence[Contributor], Pagination]:
43-
"""
44-
Retrieves a list of contributors for a specific region.
36+
"""Retrieve a list of contributors for a specific region.
4537
46-
Parameters
47-
----------
48-
region_id : str
49-
The identifier of the region to fetch contributors from.
50-
request : ContributorRequest
51-
The request object containing query parameters (count, start_page).
38+
Args:
39+
region_id: The identifier of the region to fetch contributors from.
40+
request: The request object containing query parameters.
5241
53-
Returns
54-
-------
55-
Tuple[Sequence[Contributor], Pagination]
42+
Returns:
5643
A tuple containing a list of Contributor objects and a Pagination object for managing result pages.
5744
"""
5845
url = f"{self.base_navitia_url}/coverage/{region_id}/contributors"
@@ -68,21 +55,14 @@ def list_contributors(
6855
def get_contributor_on_dataset(
6956
self, region_id: str, dataset_id: str, request: ContributorRequest
7057
) -> Tuple[Sequence[Contributor], Pagination]:
71-
"""
72-
Retrieves a list of contributors for a specific dataset in a region.
58+
"""Retrieve a list of contributors for a specific dataset in a region.
7359
74-
Parameters
75-
----------
76-
region_id : str
77-
The identifier of the region to fetch contributors from.
78-
dataset_id : str
79-
The identifier of the dataset to fetch contributors for.
80-
request : ContributorRequest
81-
The request object containing query parameters (count, start_page).
60+
Args:
61+
region_id: The identifier of the region to fetch contributors from.
62+
dataset_id: The identifier of the dataset to fetch contributors for.
63+
request: The request object containing query parameters.
8264
83-
Returns
84-
-------
85-
Tuple[Sequence[Contributor], Pagination]
65+
Returns:
8666
A tuple containing a list of Contributor objects and a Pagination object for managing result pages.
8767
"""
8868
url = f"{self.base_navitia_url}/coverage/{region_id}/contributors/{dataset_id}"

navitia_client/client/apis/coverage_apis.py

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,19 @@
77

88

99
class CoverageApiClient(ApiBaseClient):
10-
"""
11-
A client class to interact with the Navitia API for fetching coverage area information.
12-
Uses the CoverageRequest class to encapsulate query parameters.
10+
"""Client class to interact with the Navitia API for fetching coverage area information.
1311
1412
See https://doc.navitia.io/#coverage
1513
"""
1614

1715
@staticmethod
1816
def _get_regions_from_response(raw_regions_response: Any) -> Sequence[Region]:
19-
"""
20-
Converts raw response data into a list of Region objects.
17+
"""Convert raw response data into a list of Region objects.
2118
22-
Parameters
23-
----------
24-
raw_regions_response : Any
25-
The raw response data from the API containing regions' information.
19+
Args:
20+
raw_regions_response: The raw response data from the API containing regions' information.
2621
27-
Returns
28-
-------
29-
Sequence[Region]
22+
Returns:
3023
A list of Region objects created from the raw response data.
3124
"""
3225
regions = []
@@ -37,17 +30,12 @@ def _get_regions_from_response(raw_regions_response: Any) -> Sequence[Region]:
3730
def list_covered_areas(
3831
self, request: CoverageRequest
3932
) -> Tuple[Sequence[Region], Pagination]:
40-
"""
41-
Retrieves a list of covered areas from the Navitia API.
33+
"""Retrieve a list of covered areas from the Navitia API.
4234
43-
Parameters
44-
----------
45-
request : CoverageRequest
46-
The request object containing query parameters (count, start_page).
35+
Args:
36+
request: The request object containing query parameters.
4737
48-
Returns
49-
-------
50-
Tuple[Sequence[Region], Pagination]
38+
Returns:
5139
A tuple containing a list of Region objects and a Pagination object for managing result pages.
5240
"""
5341
url = f"{self.base_navitia_url}/coverage"
@@ -62,19 +50,13 @@ def list_covered_areas(
6250
def get_coverage_by_region_id(
6351
self, region_id: str, request: CoverageRequest
6452
) -> Tuple[Sequence[Region], Pagination]:
65-
"""
66-
Retrieves information about a specific region by its ID.
67-
68-
Parameters
69-
----------
70-
region_id : str
71-
The identifier of the region to fetch information about.
72-
request : CoverageRequest
73-
The request object containing query parameters (count, start_page).
74-
75-
Returns
76-
-------
77-
Tuple[Sequence[Region], Pagination]
53+
"""Retrieve information about a specific region by its ID.
54+
55+
Args:
56+
region_id: The identifier of the region to fetch information about.
57+
request: The request object containing query parameters.
58+
59+
Returns:
7860
A tuple containing a list of Region objects and a Pagination object for managing result pages.
7961
"""
8062
url = f"{self.base_navitia_url}/coverage/{region_id}"
@@ -89,21 +71,14 @@ def get_coverage_by_region_id(
8971
def get_coverage_by_region_coordinates_and_coordinates(
9072
self, lon: float, lat: float, request: CoverageRequest
9173
) -> Tuple[Sequence[Region], Pagination]:
92-
"""
93-
Retrieves information about a region based on coordinates.
94-
95-
Parameters
96-
----------
97-
lon : float
98-
The longitude of the location to fetch information about.
99-
lat : float
100-
The latitude of the location to fetch information about.
101-
request : CoverageRequest
102-
The request object containing query parameters (count, start_page).
103-
104-
Returns
105-
-------
106-
Tuple[Sequence[Region], Pagination]
74+
"""Retrieve information about a region based on coordinates.
75+
76+
Args:
77+
lon: The longitude of the location to fetch information about.
78+
lat: The latitude of the location to fetch information about.
79+
request: The request object containing query parameters.
80+
81+
Returns:
10782
A tuple containing a list of Region objects and a Pagination object for managing result pages.
10883
"""
10984
url = f"{self.base_navitia_url}/coverage/{lon};{lat}"

0 commit comments

Comments
 (0)