Skip to content

Commit

Permalink
Static typing
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Dec 15, 2023
1 parent f2171fd commit afa065c
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions muckrock/__init__.py
Expand Up @@ -19,14 +19,13 @@ def __init__(self, token: str | None = None, base_uri: str | None = None):
"""Create a new client object."""
self.BASE_URI = base_uri or BaseMuckRockClient.BASE_URI
if token:
self.token = token
self.token: str | None = token
else:
if os.getenv("MUCKROCK_API_TOKEN"):
self.token = os.getenv("MUCKROCK_API_TOKEN")
else:
self.token = None
self.token = os.getenv("MUCKROCK_API_TOKEN") or None

def _get_request(self, url: str, params: dict | None = None, headers: dict | None = None) -> Any:
def _get_request(
self, url: str, params: dict | None = None, headers: dict | None = None
) -> Any:
"""Make a GET request to the Muckrock API.
Returns the response as JSON.
Expand All @@ -50,7 +49,9 @@ def _get_request(self, url: str, params: dict | None = None, headers: dict | Non
)
return response.json()

def _post_request(self, url: str, data: dict | None = None, headers: dict | None = None) -> Any:
def _post_request(
self, url: str, data: dict | None = None, headers: dict | None = None
) -> Any:
"""Make a GET request to the Muckrock API.
Returns the response as JSON.
Expand Down Expand Up @@ -84,7 +85,13 @@ def _post_request(self, url: str, data: dict | None = None, headers: dict | None
class MuckRock(BaseMuckRockClient):
"""The public interface for the DocumentCloud API."""

def __init__(self, username: str | None = None, password: str | None = None, token: str | None = None, base_uri: str | None = None):
def __init__(
self,
username: str | None = None,
password: str | None = None,
token: str | None = None,
base_uri: str | None = None,
):
"""Create an object."""
# Set all the basic configuration options to this, the parent instance.
super().__init__(token, base_uri)
Expand All @@ -99,7 +106,7 @@ def __init__(self, username: str | None = None, password: str | None = None, tok
class BaseEndpointMixin:
"""Methods shared by endpoint classes."""

def get(self, id: str | int):
def get(self, id):
"""Return a request with the specified identifer."""
url = self.BASE_URI + self.endpoint + f"/{id}/"
r = self._get_request(url)
Expand All @@ -122,7 +129,7 @@ def filter(
requires_proxy: bool | None = None,
) -> Any:
"""Return a list of requests that match the provide input filters."""
params = {}
params: dict[str, Any] = {}
if name:
params["name"] = name
if abbreviation:
Expand All @@ -146,9 +153,15 @@ class AgencyEndpoint(BaseMuckRockClient, BaseEndpointMixin):

endpoint = "agency"

def filter(self, name: str | None = None, status: str | None = None, jurisdiction_id: str | int | None = None, requires_proxy: bool | None = None) -> Any:
def filter(
self,
name: str | None = None,
status: str | None = None,
jurisdiction_id: str | int | None = None,
requires_proxy: bool | None = None,
) -> Any:
"""Return a list of requests that match the provide input filters."""
params = {}
params: dict[str, Any] = {}
if name:
params["name"] = name
if status:
Expand Down Expand Up @@ -214,10 +227,10 @@ def filter(
agency_id: str | int | None = None,
has_datetime_submitted: bool | None = None,
has_datetime_done: bool | None = None,
ordering: str ="-datetime_submitted",
ordering: str = "-datetime_submitted",
) -> Any:
"""Return a list of requests that match the provide input filters."""
params = {}
params: dict[str, Any] = {}
if user:
params["user"] = user
if title:
Expand Down

0 comments on commit afa065c

Please sign in to comment.