neris-api-client 0.1.7__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neris_api_client
3
- Version: 0.1.7
3
+ Version: 1.0.0
4
4
  Summary: NERIS API Client
5
5
  Author-email: Ben Coleman <ben.coleman@ul.org>
6
6
  Project-URL: Homepage, https://github.com/ulfsri/neris-api-client
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "neris_api_client"
7
- version = "0.1.7"
7
+ version = "1.0.0"
8
8
  authors = [
9
9
  { name="Ben Coleman", email="ben.coleman@ul.org" },
10
10
  ]
@@ -19,7 +19,9 @@ from .models import (
19
19
  UpdateUserPayload,
20
20
  PatchStationPayload,
21
21
  PatchDepartmentPayload,
22
- CreateDepartmentPayload
22
+ CreateDepartmentPayload,
23
+ PatchIncidentAction,
24
+ TypeIncidentStatusValue,
23
25
  )
24
26
 
25
27
  __all__ = ("NerisApiClient",)
@@ -49,7 +51,7 @@ os.environ["AWS_DEFAULT_REGION"] = "us-east-2"
49
51
  class Encoder(json.JSONEncoder):
50
52
  def default(self, obj):
51
53
  if isinstance(obj, requests.structures.CaseInsensitiveDict):
52
- return { k: v for k, v in obj.items() }
54
+ return {k: v for k, v in obj.items()}
53
55
 
54
56
  return super().default(obj)
55
57
 
@@ -148,9 +150,7 @@ class _NerisApiClient:
148
150
  self._access_token_exp = datetime.fromtimestamp(
149
151
  self._decode_token(self._access_token)["exp"]
150
152
  )
151
- self._id_token_exp = datetime.fromtimestamp(
152
- self._decode_token(self._id_token)["exp"]
153
- )
153
+ self._id_token_exp = datetime.fromtimestamp(self._decode_token(self._id_token)["exp"])
154
154
 
155
155
  def _read_token_cache(self):
156
156
  if self._access_token_cache_path.exists():
@@ -160,9 +160,7 @@ class _NerisApiClient:
160
160
  if self._id_token_cache_path.exists():
161
161
  self._id_token = self._id_token_cache_path.read_text()
162
162
  if self._cognito_config_cache_path.exists():
163
- self._cognito_config = json.loads(
164
- self._cognito_config_cache_path.read_text()
165
- )
163
+ self._cognito_config = json.loads(self._cognito_config_cache_path.read_text())
166
164
 
167
165
  def _write_token_cache(self):
168
166
  self._token_cache_path.mkdir(exist_ok=True)
@@ -190,15 +188,11 @@ class _NerisApiClient:
190
188
  self._initiate_auth()
191
189
 
192
190
  if self._env != Environment.LOCAL:
193
- self._session.headers.update(
194
- {"Authorization": f"Bearer {self._access_token}"}
195
- )
191
+ self._session.headers.update({"Authorization": f"Bearer {self._access_token}"})
196
192
 
197
193
  if model:
198
194
  if isinstance(data, str):
199
- data = model.model_validate_json(data).model_dump(
200
- mode="json", by_alias=True
201
- )
195
+ data = model.model_validate_json(data).model_dump(mode="json", by_alias=True)
202
196
  if isinstance(data, dict):
203
197
  data = model.model_validate(data).model_dump(mode="json", by_alias=True)
204
198
 
@@ -211,17 +205,17 @@ class _NerisApiClient:
211
205
  },
212
206
  }
213
207
 
214
- res = getattr(self._session, method)(
215
- f"{self._base_url}{path}", json=data, params=params
216
- )
208
+ res = getattr(self._session, method)(f"{self._base_url}{path}", json=data, params=params)
217
209
 
218
- debug.update({
219
- "response": {
220
- "status_code": res.status_code,
221
- "headers": res.headers,
222
- "content": res.text,
210
+ debug.update(
211
+ {
212
+ "response": {
213
+ "status_code": res.status_code,
214
+ "headers": res.headers,
215
+ "content": res.text,
216
+ }
223
217
  }
224
- })
218
+ )
225
219
 
226
220
  if self._debug:
227
221
  print(json.dumps(debug, indent=4, cls=Encoder))
@@ -254,9 +248,7 @@ class NerisApiClient(_NerisApiClient):
254
248
  def create_entity(self, body: str | Dict[str, Any]) -> Dict[str, Any]:
255
249
  return self._call("post", "/entity/", body, model=CreateDepartmentPayload)
256
250
 
257
- def update_entity(
258
- self, neris_id: str, body: str | Dict[str, Any]
259
- ) -> Dict[str, Any]:
251
+ def update_entity(self, neris_id: str, body: str | Dict[str, Any]) -> Dict[str, Any]:
260
252
  return self._call("put", f"/entity/{neris_id}", body, model=DepartmentPayload)
261
253
 
262
254
  def get_user(self, sub: str | UUID) -> Dict[str, Any]:
@@ -265,9 +257,7 @@ class NerisApiClient(_NerisApiClient):
265
257
  def create_user(self, body: str | Dict[str, Any]) -> Dict[str, Any]:
266
258
  return self._call("post", "/user", body, model=CreateUserPayload)
267
259
 
268
- def update_user(
269
- self, sub: str | UUID, body: str | Dict[str, Any]
270
- ) -> Dict[str, Any]:
260
+ def update_user(self, sub: str | UUID, body: str | Dict[str, Any]) -> Dict[str, Any]:
271
261
  return self._call("put", f"/user/{sub}", body, model=UpdateUserPayload)
272
262
 
273
263
  def delete_user(self, sub: str | UUID) -> None:
@@ -279,9 +269,7 @@ class NerisApiClient(_NerisApiClient):
279
269
  def delete_user_entity_membership(self, sub: str | UUID, neris_id: str) -> None:
280
270
  self._call("delete", f"/user/{sub}/user_entity_membership/{neris_id}")
281
271
 
282
- def update_user_entity_activation(
283
- self, sub: str | UUID, neris_id: str, active: bool
284
- ) -> None:
272
+ def update_user_entity_activation(self, sub: str | UUID, neris_id: str, active: bool) -> None:
285
273
  self._call(
286
274
  "put",
287
275
  f"/user/{sub}/user_entity_activation/{neris_id}",
@@ -300,16 +288,47 @@ class NerisApiClient(_NerisApiClient):
300
288
  )
301
289
 
302
290
  def patch_entity(self, neris_id: str, body: str | Dict[str, Any]) -> Dict[str, Any]:
291
+ return self._call("patch", f"/entity/{neris_id}", data=body, model=PatchDepartmentPayload)
292
+
293
+ def patch_station(
294
+ self, neris_id_entity: str, neris_id_station: str, body: str | Dict[str, Any]
295
+ ) -> Dict[str, Any]:
303
296
  return self._call(
304
- "patch", f"/entity/{neris_id}", data=body, model=PatchDepartmentPayload
297
+ "patch",
298
+ f"/entity/{neris_id_entity}/station/{neris_id_station}",
299
+ data=body,
300
+ model=PatchStationPayload,
305
301
  )
306
302
 
307
- def patch_station(self, neris_id_entity: str, neris_id_station: str, body: str | Dict[str, Any]) -> Dict[str, Any]:
303
+ def patch_unit(
304
+ self,
305
+ neris_id_entity: str,
306
+ neris_id_station: str,
307
+ neris_id_unit: str,
308
+ body: str | Dict[str, Any],
309
+ ) -> Dict[str, Any]:
308
310
  return self._call(
309
- "patch", f"/entity/{neris_id_entity}/station/{neris_id_station}", data=body, model=PatchStationPayload
311
+ "patch",
312
+ f"/entity/{neris_id}/station/{neris_id_station}/unit/{neris_id_unit}",
313
+ data=body,
314
+ model=PatchUnitPayload,
310
315
  )
311
316
 
312
- def patch_unit(self, neris_id_entity: str, neris_id_station: str, neris_id_unit: str, body: str | Dict[str, Any]) -> Dict[str, Any]:
317
+ def patch_incident(
318
+ self, neris_id_entity: str, neris_id_incident: str, body: str | Dict[str, Any]
319
+ ) -> Dict[str, Any]:
313
320
  return self._call(
314
- "patch", f"/entity/{neris_id}/station/{neris_id_station}/unit/{neris_id_unit}", data=body, model=PatchUnitPayload
321
+ "patch",
322
+ f"/incident/{neris_id_entity}/{neris_id_incident}",
323
+ data=body,
324
+ model=PatchIncidentAction,
325
+ )
326
+
327
+ def update_incident_status(
328
+ self, neris_id_entity: str, neris_id_incident: str, status: TypeIncidentStatusValue
329
+ ) -> Dict[str, Any]:
330
+ return self._call(
331
+ "put",
332
+ f"/incident/{neris_id_entity}/{neris_id_incident}/status",
333
+ data={"status": str(status)},
315
334
  )