|
| 1 | +""" |
| 2 | +Methods for the notifications namespace |
| 3 | +
|
| 4 | +https://docs.github.com/en/rest/activity/notifications |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import annotations |
| 8 | + |
| 9 | +from typing import Any |
| 10 | + |
| 11 | +from ..const import GitHubRequestKwarg |
| 12 | +from ..models.notification import GitHubNotificationModel |
| 13 | +from ..models.response import GitHubResponseModel |
| 14 | +from .base import BaseNamespace |
| 15 | + |
| 16 | + |
| 17 | +class GitHubNotificationsNamespace(BaseNamespace): |
| 18 | + """Methods for the notifications namespace""" |
| 19 | + |
| 20 | + async def list( |
| 21 | + self, |
| 22 | + *, |
| 23 | + all: bool = False, |
| 24 | + participating: bool = False, |
| 25 | + since: str | None = None, |
| 26 | + before: str | None = None, |
| 27 | + page: int = 1, |
| 28 | + per_page: int = 50, |
| 29 | + params: dict[str, str] | None = None, |
| 30 | + **kwargs: Any, |
| 31 | + ) -> GitHubResponseModel[list[GitHubNotificationModel]]: |
| 32 | + """ |
| 33 | + List notifications for the authenticated user |
| 34 | +
|
| 35 | + https://docs.github.com/en/rest/activity/notifications#list-notifications-for-the-authenticated-user |
| 36 | + """ |
| 37 | + request_params = {} |
| 38 | + if all: |
| 39 | + request_params["all"] = "true" |
| 40 | + if participating: |
| 41 | + request_params["participating"] = "true" |
| 42 | + if since: |
| 43 | + request_params["since"] = since |
| 44 | + if before: |
| 45 | + request_params["before"] = before |
| 46 | + if page != 1: |
| 47 | + request_params["page"] = str(page) |
| 48 | + if per_page != 50: |
| 49 | + request_params["per_page"] = str(per_page) |
| 50 | + if params: |
| 51 | + request_params.update(params) |
| 52 | + |
| 53 | + response = await self._client.async_call_api( |
| 54 | + endpoint="/notifications", |
| 55 | + params=request_params, |
| 56 | + **kwargs, |
| 57 | + ) |
| 58 | + response.data = [GitHubNotificationModel(data) for data in response.data] |
| 59 | + return response |
0 commit comments