Skip to content

Commit

Permalink
fix: fix typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Dec 4, 2023
1 parent cf86a02 commit eb9afe5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions openfoodfacts/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Any, Dict, List, Optional, Tuple, Union, cast

import requests

Expand All @@ -15,7 +15,7 @@ def send_get_request(
api_config: APIConfig,
params: Optional[Dict[str, Any]] = None,
return_none_on_404: bool = False,
) -> JSONType:
) -> Optional[JSONType]:
"""Send a GET request to the given URL.
:param url: the URL to send the request to
Expand Down Expand Up @@ -73,11 +73,13 @@ def __init__(self, api_config: APIConfig):
def get(self, facet_name: Union[Facet, str]) -> JSONType:
facet = Facet.from_str_or_enum(facet_name)
facet_plural = facet.value.replace("_", "-")
return send_get_request(
resp = send_get_request(
url=f"{self.base_url}/{facet_plural}",
params={"json": "1"},
api_config=self.api_config,
)
resp = cast(JSONType, resp)
return resp

def get_products(
self,
Expand All @@ -99,15 +101,17 @@ def get_products(
"""
facet = Facet.from_str_or_enum(facet_name)
facet_singular = facet.name.replace("_", "-")
params = {"page": page, "page_size": page_size}
params: JSONType = {"page": page, "page_size": page_size}
if fields is not None:
params["fields"] = ",".join(fields)

return send_get_request(
resp = send_get_request(
url=f"{self.base_url}/{facet_singular}/{facet_value}.json",
params=params,
api_config=self.api_config,
)
resp = cast(JSONType, resp)
return resp


class ProductResource:
Expand Down

0 comments on commit eb9afe5

Please sign in to comment.