1
1
"""A simple python wrapper for the [MuckRock API."""
2
+ from __future__ import annotations
3
+
2
4
import os
5
+ from typing import Any
3
6
4
7
import requests
5
8
@@ -12,7 +15,7 @@ class BaseMuckRockClient:
12
15
BASE_URI = "https://www.muckrock.com/api_v1/"
13
16
USER_AGENT = "python-muckrock (https://github.com/palewire/python-muckrock)"
14
17
15
- def __init__ (self , token = None , base_uri = None ):
18
+ def __init__ (self , token : str | None = None , base_uri : str | None = None ):
16
19
"""Create a new client object."""
17
20
self .BASE_URI = base_uri or BaseMuckRockClient .BASE_URI
18
21
if token :
@@ -23,7 +26,7 @@ def __init__(self, token=None, base_uri=None):
23
26
else :
24
27
self .token = None
25
28
26
- def _get_request (self , url , params = None , headers = None ):
29
+ def _get_request (self , url : str , params : dict | None = None , headers : dict | None = None ) -> Any :
27
30
"""Make a GET request to the Muckrock API.
28
31
29
32
Returns the response as JSON.
@@ -47,7 +50,7 @@ def _get_request(self, url, params=None, headers=None):
47
50
)
48
51
return response .json ()
49
52
50
- def _post_request (self , url , data = None , headers = None ):
53
+ def _post_request (self , url : str , data : dict | None = None , headers : dict | None = None ) -> Any :
51
54
"""Make a GET request to the Muckrock API.
52
55
53
56
Returns the response as JSON.
@@ -81,7 +84,7 @@ def _post_request(self, url, data=None, headers=None):
81
84
class MuckRock (BaseMuckRockClient ):
82
85
"""The public interface for the DocumentCloud API."""
83
86
84
- def __init__ (self , username = None , password = None , token = None , base_uri = None ):
87
+ def __init__ (self , username : str | None = None , password : str | None = None , token : str | None = None , base_uri : str | None = None ):
85
88
"""Create an object."""
86
89
# Set all the basic configuration options to this, the parent instance.
87
90
super ().__init__ (token , base_uri )
@@ -96,7 +99,7 @@ def __init__(self, username=None, password=None, token=None, base_uri=None):
96
99
class BaseEndpointMixin :
97
100
"""Methods shared by endpoint classes."""
98
101
99
- def get (self , id ):
102
+ def get (self , id : str | int ):
100
103
"""Return a request with the specified identifer."""
101
104
url = self .BASE_URI + self .endpoint + f"/{ id } /"
102
105
r = self ._get_request (url )
@@ -112,12 +115,12 @@ class JurisdictionEndpoint(BaseMuckRockClient, BaseEndpointMixin):
112
115
113
116
def filter (
114
117
self ,
115
- name = None ,
116
- abbreviation = None ,
117
- parent_id = None ,
118
- level = None ,
119
- requires_proxy = None ,
120
- ):
118
+ name : str | None = None ,
119
+ abbreviation : str | None = None ,
120
+ parent_id : str | int | None = None ,
121
+ level : str | None = None ,
122
+ requires_proxy : bool | None = None ,
123
+ ) -> Any :
121
124
"""Return a list of requests that match the provide input filters."""
122
125
params = {}
123
126
if name :
@@ -143,7 +146,7 @@ class AgencyEndpoint(BaseMuckRockClient, BaseEndpointMixin):
143
146
144
147
endpoint = "agency"
145
148
146
- def filter (self , name = None , status = None , jurisdiction_id = None , requires_proxy = None ):
149
+ def filter (self , name : str | None = None , status : str | None = None , jurisdiction_id : str | int | None = None , requires_proxy : bool | None = None ) -> Any :
147
150
"""Return a list of requests that match the provide input filters."""
148
151
params = {}
149
152
if name :
@@ -168,15 +171,15 @@ class FoiaEndpoint(BaseMuckRockClient, BaseEndpointMixin):
168
171
169
172
def create (
170
173
self ,
171
- title = "" ,
172
- document_request = "" ,
173
- full_text = "" ,
174
- agency_ids = None ,
175
- embargo = False ,
176
- permanent_embargo = False ,
177
- attachments = None ,
178
- organization = None ,
179
- ):
174
+ title : str = "" ,
175
+ document_request : str = "" ,
176
+ full_text : str = "" ,
177
+ agency_ids : list [ str | int ] | None = None ,
178
+ embargo : bool = False ,
179
+ permanent_embargo : bool = False ,
180
+ attachments : Any | None = None ,
181
+ organization : str | int | None = None ,
182
+ ) -> Any :
180
183
"""Create a new request."""
181
184
if not title :
182
185
raise TypeError ("title kwarg required" )
@@ -203,16 +206,16 @@ def create(
203
206
204
207
def filter (
205
208
self ,
206
- user = None ,
207
- title = None ,
208
- status = None ,
209
- embargo = None ,
210
- jurisdiction_id = None ,
211
- agency_id = None ,
212
- has_datetime_submitted = None ,
213
- has_datetime_done = None ,
214
- ordering = "-datetime_submitted" ,
215
- ):
209
+ user : str | None = None ,
210
+ title : str | None = None ,
211
+ status : str | None = None ,
212
+ embargo : str | None = None ,
213
+ jurisdiction_id : str | int | None = None ,
214
+ agency_id : str | int | None = None ,
215
+ has_datetime_submitted : bool | None = None ,
216
+ has_datetime_done : bool | None = None ,
217
+ ordering : str = "-datetime_submitted" ,
218
+ ) -> Any :
216
219
"""Return a list of requests that match the provide input filters."""
217
220
params = {}
218
221
if user :
0 commit comments