Skip to content

Commit b9162b1

Browse files
authored
Merge pull request #43 from GlobalFishingWatch/feature/bulk-downloads-file
implement download bulk report file url (file) API endpoints and request/response models
2 parents b023763 + edb4cdf commit b9162b1

File tree

13 files changed

+355
-0
lines changed

13 files changed

+355
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Global Fishing Watch (GFW) API Python Client - Download bulk Report (URL File).
2+
3+
This module provides the endpoint and associated functionalities for retrieving signed
4+
URL to download file(s) (i.e., `"DATA"`, `"README"`, or `"GEOM"`) of the previously
5+
created bulk report. It defines the `BulkReportFileEndPoint` class, which handles the
6+
construction and execution of API requests, and the parsing of API responses for
7+
Download bulk Report (URL File) API endpoint.
8+
9+
For detailed information about the Download bulk Report (URL File) API endpoint,
10+
please refer to the official Global Fishing Watch API documentation:
11+
12+
See: https://globalfishingwatch.org/our-apis/documentation#download-bulk-report-url-file
13+
14+
For more details on the Download bulk Report (URL File) data caveats, please refer to
15+
the official Global Fishing Watch API documentation:
16+
17+
See: https://globalfishingwatch.org/our-apis/documentation#sar-fixed-infrastructure-data-caveats
18+
"""
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""Global Fishing Watch (GFW) API Python Client - Download bulk Report (URL File) API endpoint."""
2+
3+
from gfwapiclient.http.client import HTTPClient
4+
from gfwapiclient.http.endpoints import GetEndPoint
5+
from gfwapiclient.http.models import RequestBody
6+
from gfwapiclient.resources.bulk_downloads.file.models.request import (
7+
BulkReportFileParams,
8+
)
9+
from gfwapiclient.resources.bulk_downloads.file.models.response import (
10+
BulkReportFileItem,
11+
BulkReportFileResult,
12+
)
13+
14+
15+
__all__ = ["BulkReportFileEndPoint"]
16+
17+
18+
class BulkReportFileEndPoint(
19+
GetEndPoint[
20+
BulkReportFileParams, RequestBody, BulkReportFileItem, BulkReportFileResult
21+
],
22+
):
23+
"""Download bulk Report (URL File) API endpoint.
24+
25+
This endpoint is used to retrieve signed URL to download file(s) (i.e., `"DATA"`,
26+
`"README"`, or `"GEOM"`) of the previously created bulk report.
27+
28+
For more details on the Download bulk Report (URL File) API endpoint, please refer
29+
to the official Global Fishing Watch API documentation:
30+
31+
See: https://globalfishingwatch.org/our-apis/documentation#download-bulk-report-url-file
32+
33+
For more details on the Download bulk Report (URL File) data caveats, please refer
34+
to the official Global Fishing Watch API documentation:
35+
36+
See: https://globalfishingwatch.org/our-apis/documentation#sar-fixed-infrastructure-data-caveats
37+
"""
38+
39+
def __init__(
40+
self,
41+
*,
42+
bulk_report_id: str,
43+
request_params: BulkReportFileParams,
44+
http_client: HTTPClient,
45+
) -> None:
46+
"""Initializes a new `BulkReportFileEndPoint`.
47+
48+
Args:
49+
bulk_report_id (str):
50+
Unique identifier (ID) of the bulk report.
51+
52+
request_params (BulkReportFileParams):
53+
The request query parameters.
54+
55+
http_client (HTTPClient):
56+
The HTTP client used to make the API call.
57+
"""
58+
super().__init__(
59+
path=f"bulk-reports/{bulk_report_id}/download-file-url",
60+
request_params=request_params,
61+
result_item_class=BulkReportFileItem,
62+
result_class=BulkReportFileResult,
63+
http_client=http_client,
64+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Global Fishing Watch (GFW) API Python Client - Download bulk Report (URL File) Models.
2+
3+
This module defines Pydantic data models used for interacting with the Download bulk
4+
Report (URL File) API endpoint. These models are used to represent request parameters
5+
and response data when obtaining signed URL to download file(s) (i.e., `"DATA"`,
6+
`"README"`, or `"GEOM"`) of the previously created bulk report.
7+
8+
For detailed information about the Download bulk Report (URL File) API endpoint,
9+
please refer to the official Global Fishing Watch API documentation:
10+
11+
See: https://globalfishingwatch.org/our-apis/documentation#download-bulk-report-url-file
12+
13+
For more details on the Download bulk Report (URL File) data caveats, please refer to
14+
the official Global Fishing Watch API documentation:
15+
16+
See: https://globalfishingwatch.org/our-apis/documentation#sar-fixed-infrastructure-data-caveats
17+
"""
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Global Fishing Watch (GFW) API Python Client - Download bulk Report (URL File) Request Models."""
2+
3+
from typing import Final, Optional
4+
5+
from pydantic import Field
6+
7+
from gfwapiclient.http.models import RequestParams
8+
from gfwapiclient.resources.bulk_downloads.base.models.request import BulkReportFileType
9+
10+
11+
__all__ = ["BulkReportFileParams"]
12+
13+
14+
BULK_REPORT_FILE_PARAMS_VALIDATION_ERROR_MESSAGE: Final[str] = (
15+
"Get bulk report file download URL request parameters validation failed."
16+
)
17+
18+
19+
class BulkReportFileParams(RequestParams):
20+
"""Request query parameters for Download bulk Report (URL File) API endpoint.
21+
22+
Represents request query parameters to obtain signed URL to download the file
23+
(i.e., `"DATA"`, `"README"`, or `"GEOM"`) of the previously created bulk report.
24+
25+
For more details on the Download bulk Report (URL File) API endpoint supported
26+
request parameters, please refer to the official Global Fishing Watch API
27+
documentation:
28+
29+
See: https://globalfishingwatch.org/our-apis/documentation#download-bulk-report-url-parameters-for-get-requests
30+
31+
Attributes:
32+
file (Optional[BulkReportFileType]):
33+
Type of bulk report file (i.e., `"DATA"`, `"README"`, or `"GEOM"`).
34+
"""
35+
36+
file: Optional[BulkReportFileType] = Field(BulkReportFileType.DATA, alias="file")
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""Global Fishing Watch (GFW) API Python Client - Download bulk Report (URL File) Response Models."""
2+
3+
from typing import Optional, Type
4+
5+
from pydantic import Field
6+
7+
from gfwapiclient.http.models import Result, ResultItem
8+
9+
10+
__all__ = ["BulkReportFileItem", "BulkReportFileResult"]
11+
12+
13+
class BulkReportFileItem(ResultItem):
14+
"""Result item for the Download bulk Report (URL File) API endpoint.
15+
16+
Represents signed URL to download the file (i.e., `"DATA"`, `"README"`,
17+
or `"GEOM"`) of the previously created bulk report.
18+
19+
For more details on the Download bulk Report (URL File) API endpoint supported
20+
response bodies, please refer to the official Global Fishing Watch API
21+
documentation:
22+
23+
See: https://globalfishingwatch.org/our-apis/documentation#download-bulk-report-http-response
24+
25+
Attributes:
26+
url (Optional[str]):
27+
Signed URL to download the file.
28+
"""
29+
30+
url: Optional[str] = Field(None, alias="url")
31+
32+
33+
class BulkReportFileResult(Result[BulkReportFileItem]):
34+
"""Result for the Download bulk Report (URL File) API endpoint.
35+
36+
For more details on the Download bulk Report (URL File) API endpoint supported
37+
response bodies, please refer to the official Global Fishing Watch API
38+
documentation:
39+
40+
See: https://globalfishingwatch.org/our-apis/documentation#download-bulk-report-http-response
41+
42+
Attributes:
43+
_result_item_class (Type[BulkReportFileItem]):
44+
The model used for individual result items.
45+
46+
_data (BulkReportFileItem):
47+
The bulk report file item returned in the response.
48+
"""
49+
50+
_result_item_class: Type[BulkReportFileItem]
51+
_data: BulkReportFileItem
52+
53+
def __init__(self, data: BulkReportFileItem) -> None:
54+
"""Initializes a new `BulkReportFileResult`.
55+
56+
Args:
57+
data (BulkReportFileItem):
58+
The bulk report file download details.
59+
"""
60+
super().__init__(data=data)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"url": "https://storage.googleapis.com/api-bulk-release-us-central1/adbb9b62-5c08-4142-82e0-b2b575f3e058/data.gz"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"file": "DATA"
3+
}

tests/resources/bulk_downloads/conftest.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,38 @@ def mock_raw_bulk_report_list_request_params(
7070
"bulk_downloads/bulk_report_list_request_params.json"
7171
)
7272
return raw_bulk_report_list_request_params
73+
74+
75+
@pytest.fixture
76+
def mock_raw_bulk_report_file_request_params(
77+
load_json_fixture: Callable[[str], Dict[str, Any]],
78+
) -> Dict[str, Any]:
79+
"""Fixture for mock raw bulk report file request parameters.
80+
81+
Returns:
82+
Dict[str, Any]:
83+
Raw `BulkReportFileParams` sample data as dictionary.
84+
"""
85+
raw_bulk_report_file_request_params: Dict[str, Any] = load_json_fixture(
86+
"bulk_downloads/bulk_report_file_request_params.json"
87+
)
88+
return raw_bulk_report_file_request_params
89+
90+
91+
@pytest.fixture
92+
def mock_raw_bulk_report_file_item(
93+
load_json_fixture: Callable[[str], Dict[str, Any]],
94+
) -> Dict[str, Any]:
95+
"""Fixture for a mock raw bulk report file item.
96+
97+
This fixture loads sample JSON data representing a single
98+
`BulkReportFileItem` from a fixture file.
99+
100+
Returns:
101+
Dict[str, Any]:
102+
Raw `BulkReportFileItem` sample data as a dictionary.
103+
"""
104+
raw_bulk_report_file_item: Dict[str, Any] = load_json_fixture(
105+
"bulk_downloads/bulk_report_file_item.json"
106+
)
107+
return raw_bulk_report_file_item
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for `gfwapiclient.resources.bulk_downloads.file`."""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for `gfwapiclient.resources.bulk_downloads.file.models`."""

0 commit comments

Comments
 (0)