diff --git a/README.srt b/README.srt index e69de29..238d2d1 100644 --- a/README.srt +++ b/README.srt @@ -0,0 +1,4 @@ +openapi-python-client +https://push.gooyal.com/swagger?base=push.gooyal.com + +npm install -g swagger2openapi \ No newline at end of file diff --git a/apps/core/admin.py b/apps/core/admin.py index 2ea9e71..c6fe108 100644 --- a/apps/core/admin.py +++ b/apps/core/admin.py @@ -1,9 +1,2 @@ from django.contrib import admin -from .models import Config - - -class ConfigAdmin(admin.ModelAdmin): - list_display = ['key', 'value', 'value_type', 'get_value'] - -admin.site.register(Config, ConfigAdmin) diff --git a/apps/core/migrations/0001_initial.py b/apps/core/migrations/0001_initial.py deleted file mode 100644 index e3c46f5..0000000 --- a/apps/core/migrations/0001_initial.py +++ /dev/null @@ -1,29 +0,0 @@ -# Generated by Django 5.1.7 on 2025-05-06 07:03 - -import uuid -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Config', - fields=[ - ('uuid', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), - ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)), - ('updated_at', models.DateTimeField(auto_now=True, db_index=True)), - ('key', models.CharField(db_index=True, max_length=255, unique=True, verbose_name='key')), - ('value', models.TextField(blank=True, null=True, verbose_name='value')), - ('value_type', models.CharField(choices=[('INT', 'Integer'), ('FLOAT', 'Float'), ('BOOLEAN', 'Boolean'), ('STRING', 'String'), ('DATE', 'Date'), ('DATETIME', 'DateTime'), ('JSON', 'JSON')], max_length=64)), - ], - options={ - 'abstract': False, - }, - ), - ] diff --git a/apps/notifications/__init__.py b/apps/notifications/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/notifications/admin.py b/apps/notifications/admin.py new file mode 100644 index 0000000..8932ae8 --- /dev/null +++ b/apps/notifications/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import PushUser, Device + + +admin.site.register(PushUser) +admin.site.register(Device) \ No newline at end of file diff --git a/apps/notifications/apps.py b/apps/notifications/apps.py new file mode 100644 index 0000000..001b4f9 --- /dev/null +++ b/apps/notifications/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class NotificationsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'notifications' diff --git a/apps/notifications/migrations/__init__.py b/apps/notifications/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/notifications/models.py b/apps/notifications/models.py new file mode 100644 index 0000000..7271692 --- /dev/null +++ b/apps/notifications/models.py @@ -0,0 +1,19 @@ +from django.db import models + +from apps.users.models import User +from utils.models import BaseModel + + +class PushUser(BaseModel): + user = models.ForeignKey(User, on_delete=models.CASCADE) + client_token = models.CharField(max_length=32, null=True, blank=True) + application_token = models.CharField(max_length=32, null=True, blank=True) + + def get_token(self): + return + + def send_push(self): + return + +class Device(BaseModel): + pass diff --git a/apps/notifications/serializers.py b/apps/notifications/serializers.py new file mode 100644 index 0000000..7c18961 --- /dev/null +++ b/apps/notifications/serializers.py @@ -0,0 +1,202 @@ +from rest_framework import serializers + +from .models import PushDevice + +from ..core.models import Config + + +class CategorySerializer(serializers.ModelSerializer): + class Meta: + model = Category + fields = ( + 'uuid', + 'color', + 'title', + 'icon', + ) + + +class VisitSerializer(serializers.ModelSerializer): + class Meta: + model = Visit + fields = ( + 'uuid', + 'ad', + 'state', + 'reward_amount', + 'location', + 'opportunity_until', + 'display_time', + ) + read_only_fields = ('uuid', 'state', 'reward_amount', 'opportunity_until', 'display_time') + + +class AdSerializer(TaggitSerializer, serializers.ModelSerializer): + tags = TagListSerializerField(read_only=True) + category_detail = CategorySerializer(read_only=True) + + class Meta: + model = Ad + fields = ( + 'uuid', + 'title', + 'content', + 'content_type', + 'description', + 'location', + 'category', + 'category_detail', + 'banner', + 'reward_amount', + 'reward_count', + 'address', + 'url', + 'tags', + 'created_at', + 'updated_at', + 'display_time', + 'status', + ) + read_only_fields = fields + + +class AdWithVisitSerializer(TaggitSerializer, serializers.ModelSerializer): + visit = VisitSerializer(read_only=True) + + tags = TagListSerializerField(read_only=True) + category_detail = CategorySerializer(read_only=True) + + class Meta: + model = Ad + fields = ( + 'uuid', + 'title', + 'content', + 'content_type', + 'description', + 'location', + 'category', + 'category_detail', + 'banner', + 'reward_amount', + 'reward_count', + 'address', + 'url', + 'tags', + 'created_at', + 'updated_at', + 'display_time', + 'visit' + ) + read_only_fields = fields + +class AdUserSerializer(TaggitSerializer, serializers.ModelSerializer): + tags = TagListSerializerField(allow_null=True, allow_empty=True, required=False, read_only=True) + category_detail = CategorySerializer(read_only=True) + + # new_tags = TagListSerializerField(allow_null=True, allow_empty=True) + new_category_detail = CategorySerializer(read_only=True) + + class Meta: + model = Ad + fields = ( + 'uuid', + 'title', + 'content', + 'content_type', + 'description', + 'location', + 'category', + 'category_detail', + 'banner', + 'reward_amount', + 'reward_count', + 'address', + 'url', + 'tags', + + 'new_title', + 'new_location', + 'new_category', + 'new_category_detail', + 'new_description', + 'new_banner', + 'new_content', + 'new_content_type', + 'new_url', + 'new_tags', + 'new_address', + + 'payment_state', + 'state', + 'rejection_reason', + 'created_at', + 'updated_at', + 'display_time', + 'status', + ) + read_only_fields = ['uuid', + 'title', + 'content', + 'content_type', + 'description', + 'location', + 'category', + 'category_detail', + 'banner', + 'address', + 'url', + 'tags', + + 'new_category_detail', + + 'payment_state', + 'state', + 'rejection_reason', + 'created_at', + 'updated_at', + 'display_time', + 'status' + ] + + +class TagSerializer(TaggitSerializer, serializers.ModelSerializer): + class Meta: + model = Tag + fields = ('name', 'slug') + + +class ConfigSerializer(serializers.ModelSerializer): + class Meta: + model = Config + fields = ['key', 'value', 'value_type'] + + + +# دریافتی +# کل بیلبورد +# کل بازدید +# درآمد سالیانه + + +class AdVisitStatisticSerializer(serializers.Serializer): + label = serializers.CharField() + with_reward_count = serializers.IntegerField() + without_reward_count = serializers.IntegerField() + reward_amount = serializers.IntegerField() + + +class StatisticSerializer(serializers.Serializer): + total_reward_input = serializers.IntegerField() + total_visit_count = serializers.IntegerField() + total_ads_count = serializers.IntegerField() + + monthly_data = AdVisitStatisticSerializer(many=True) + daily_data = AdVisitStatisticSerializer(many=True) + + +class ClusterSerializer(serializers.Serializer): + cluster = serializers.IntegerField() + ads_rewards_amount = serializers.IntegerField() + ads_count = serializers.IntegerField() + location = GeometryField() diff --git a/apps/notifications/tests.py b/apps/notifications/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/apps/notifications/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/apps/notifications/views.py b/apps/notifications/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/apps/notifications/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/gotify_rest_api_client/__init__.py b/gotify_rest_api_client/__init__.py new file mode 100644 index 0000000..60b883d --- /dev/null +++ b/gotify_rest_api_client/__init__.py @@ -0,0 +1,8 @@ +"""A client library for accessing Gotify REST-API.""" + +from .client import AuthenticatedClient, Client + +__all__ = ( + "AuthenticatedClient", + "Client", +) diff --git a/gotify_rest_api_client/api/__init__.py b/gotify_rest_api_client/api/__init__.py new file mode 100644 index 0000000..81f9fa2 --- /dev/null +++ b/gotify_rest_api_client/api/__init__.py @@ -0,0 +1 @@ +"""Contains methods for accessing the API""" diff --git a/gotify_rest_api_client/api/application/__init__.py b/gotify_rest_api_client/api/application/__init__.py new file mode 100644 index 0000000..2d7c0b2 --- /dev/null +++ b/gotify_rest_api_client/api/application/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/gotify_rest_api_client/api/application/create_app.py b/gotify_rest_api_client/api/application/create_app.py new file mode 100644 index 0000000..bc059ab --- /dev/null +++ b/gotify_rest_api_client/api/application/create_app.py @@ -0,0 +1,172 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application_model import ApplicationModel +from ...models.application_params_model import ApplicationParamsModel +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + *, + body: ApplicationParamsModel, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/application", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ApplicationModel, ErrorModel]]: + if response.status_code == 200: + response_200 = ApplicationModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ApplicationModel, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, + body: ApplicationParamsModel, +) -> Response[Union[ApplicationModel, ErrorModel]]: + """Create an application. + + Args: + body (ApplicationParamsModel): Params allowed to create or update Applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ApplicationModel, ErrorModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: ApplicationParamsModel, +) -> Optional[Union[ApplicationModel, ErrorModel]]: + """Create an application. + + Args: + body (ApplicationParamsModel): Params allowed to create or update Applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ApplicationModel, ErrorModel] + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: ApplicationParamsModel, +) -> Response[Union[ApplicationModel, ErrorModel]]: + """Create an application. + + Args: + body (ApplicationParamsModel): Params allowed to create or update Applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ApplicationModel, ErrorModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + body: ApplicationParamsModel, +) -> Optional[Union[ApplicationModel, ErrorModel]]: + """Create an application. + + Args: + body (ApplicationParamsModel): Params allowed to create or update Applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ApplicationModel, ErrorModel] + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/gotify_rest_api_client/api/application/delete_app.py b/gotify_rest_api_client/api/application/delete_app.py new file mode 100644 index 0000000..079f701 --- /dev/null +++ b/gotify_rest_api_client/api/application/delete_app.py @@ -0,0 +1,165 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "delete", + "url": f"/application/{id}", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[Any, ErrorModel]]: + if response.status_code == 200: + response_200 = cast(Any, None) + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[Any, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Delete an application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Delete an application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Delete an application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Delete an application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/application/get_apps.py b/gotify_rest_api_client/api/application/get_apps.py new file mode 100644 index 0000000..ea89261 --- /dev/null +++ b/gotify_rest_api_client/api/application/get_apps.py @@ -0,0 +1,140 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application_model import ApplicationModel +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/application", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, list["ApplicationModel"]]]: + if response.status_code == 200: + response_200 = [] + _response_200 = response.json() + for response_200_item_data in _response_200: + response_200_item = ApplicationModel.from_dict(response_200_item_data) + + response_200.append(response_200_item) + + return response_200 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, list["ApplicationModel"]]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, list["ApplicationModel"]]]: + """Return all applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, list['ApplicationModel']]] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, list["ApplicationModel"]]]: + """Return all applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, list['ApplicationModel']] + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, list["ApplicationModel"]]]: + """Return all applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, list['ApplicationModel']]] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, list["ApplicationModel"]]]: + """Return all applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, list['ApplicationModel']] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/application/remove_app_image.py b/gotify_rest_api_client/api/application/remove_app_image.py new file mode 100644 index 0000000..1899b93 --- /dev/null +++ b/gotify_rest_api_client/api/application/remove_app_image.py @@ -0,0 +1,169 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "delete", + "url": f"/application/{id}/image", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[Any, ErrorModel]]: + if response.status_code == 200: + response_200 = cast(Any, None) + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if response.status_code == 500: + response_500 = ErrorModel.from_dict(response.json()) + + return response_500 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[Any, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Deletes an image of an application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Deletes an image of an application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Deletes an image of an application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Deletes an image of an application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/application/update_application.py b/gotify_rest_api_client/api/application/update_application.py new file mode 100644 index 0000000..77e219f --- /dev/null +++ b/gotify_rest_api_client/api/application/update_application.py @@ -0,0 +1,189 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application_model import ApplicationModel +from ...models.application_params_model import ApplicationParamsModel +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, + *, + body: ApplicationParamsModel, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "put", + "url": f"/application/{id}", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ApplicationModel, ErrorModel]]: + if response.status_code == 200: + response_200 = ApplicationModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ApplicationModel, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, + body: ApplicationParamsModel, +) -> Response[Union[ApplicationModel, ErrorModel]]: + """Update an application. + + Args: + id (int): + body (ApplicationParamsModel): Params allowed to create or update Applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ApplicationModel, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, + body: ApplicationParamsModel, +) -> Optional[Union[ApplicationModel, ErrorModel]]: + """Update an application. + + Args: + id (int): + body (ApplicationParamsModel): Params allowed to create or update Applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ApplicationModel, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, + body: ApplicationParamsModel, +) -> Response[Union[ApplicationModel, ErrorModel]]: + """Update an application. + + Args: + id (int): + body (ApplicationParamsModel): Params allowed to create or update Applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ApplicationModel, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, + body: ApplicationParamsModel, +) -> Optional[Union[ApplicationModel, ErrorModel]]: + """Update an application. + + Args: + id (int): + body (ApplicationParamsModel): Params allowed to create or update Applications. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ApplicationModel, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + body=body, + ) + ).parsed diff --git a/gotify_rest_api_client/api/application/upload_app_image.py b/gotify_rest_api_client/api/application/upload_app_image.py new file mode 100644 index 0000000..8537a58 --- /dev/null +++ b/gotify_rest_api_client/api/application/upload_app_image.py @@ -0,0 +1,191 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.application_model import ApplicationModel +from ...models.error_model import ErrorModel +from ...models.upload_app_image_body import UploadAppImageBody +from ...types import Response + + +def _get_kwargs( + id: int, + *, + body: UploadAppImageBody, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": f"/application/{id}/image", + } + + _kwargs["files"] = body.to_multipart() + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ApplicationModel, ErrorModel]]: + if response.status_code == 200: + response_200 = ApplicationModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if response.status_code == 500: + response_500 = ErrorModel.from_dict(response.json()) + + return response_500 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ApplicationModel, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, + body: UploadAppImageBody, +) -> Response[Union[ApplicationModel, ErrorModel]]: + """Upload an image for an application. + + Args: + id (int): + body (UploadAppImageBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ApplicationModel, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, + body: UploadAppImageBody, +) -> Optional[Union[ApplicationModel, ErrorModel]]: + """Upload an image for an application. + + Args: + id (int): + body (UploadAppImageBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ApplicationModel, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, + body: UploadAppImageBody, +) -> Response[Union[ApplicationModel, ErrorModel]]: + """Upload an image for an application. + + Args: + id (int): + body (UploadAppImageBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ApplicationModel, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, + body: UploadAppImageBody, +) -> Optional[Union[ApplicationModel, ErrorModel]]: + """Upload an image for an application. + + Args: + id (int): + body (UploadAppImageBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ApplicationModel, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + body=body, + ) + ).parsed diff --git a/gotify_rest_api_client/api/client/__init__.py b/gotify_rest_api_client/api/client/__init__.py new file mode 100644 index 0000000..2d7c0b2 --- /dev/null +++ b/gotify_rest_api_client/api/client/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/gotify_rest_api_client/api/client/create_client.py b/gotify_rest_api_client/api/client/create_client.py new file mode 100644 index 0000000..dccf58f --- /dev/null +++ b/gotify_rest_api_client/api/client/create_client.py @@ -0,0 +1,172 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.client_model import ClientModel +from ...models.client_params_model import ClientParamsModel +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + *, + body: ClientParamsModel, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/client", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ClientModel, ErrorModel]]: + if response.status_code == 200: + response_200 = ClientModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ClientModel, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, + body: ClientParamsModel, +) -> Response[Union[ClientModel, ErrorModel]]: + """Create a client. + + Args: + body (ClientParamsModel): Params allowed to create or update Clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ClientModel, ErrorModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: ClientParamsModel, +) -> Optional[Union[ClientModel, ErrorModel]]: + """Create a client. + + Args: + body (ClientParamsModel): Params allowed to create or update Clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ClientModel, ErrorModel] + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: ClientParamsModel, +) -> Response[Union[ClientModel, ErrorModel]]: + """Create a client. + + Args: + body (ClientParamsModel): Params allowed to create or update Clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ClientModel, ErrorModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + body: ClientParamsModel, +) -> Optional[Union[ClientModel, ErrorModel]]: + """Create a client. + + Args: + body (ClientParamsModel): Params allowed to create or update Clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ClientModel, ErrorModel] + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/gotify_rest_api_client/api/client/delete_client.py b/gotify_rest_api_client/api/client/delete_client.py new file mode 100644 index 0000000..42e0a91 --- /dev/null +++ b/gotify_rest_api_client/api/client/delete_client.py @@ -0,0 +1,165 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "delete", + "url": f"/client/{id}", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[Any, ErrorModel]]: + if response.status_code == 200: + response_200 = cast(Any, None) + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[Any, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Delete a client. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Delete a client. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Delete a client. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Delete a client. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/client/get_clients.py b/gotify_rest_api_client/api/client/get_clients.py new file mode 100644 index 0000000..3ae448c --- /dev/null +++ b/gotify_rest_api_client/api/client/get_clients.py @@ -0,0 +1,140 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.client_model import ClientModel +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/client", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, list["ClientModel"]]]: + if response.status_code == 200: + response_200 = [] + _response_200 = response.json() + for response_200_item_data in _response_200: + response_200_item = ClientModel.from_dict(response_200_item_data) + + response_200.append(response_200_item) + + return response_200 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, list["ClientModel"]]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, list["ClientModel"]]]: + """Return all clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, list['ClientModel']]] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, list["ClientModel"]]]: + """Return all clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, list['ClientModel']] + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, list["ClientModel"]]]: + """Return all clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, list['ClientModel']]] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, list["ClientModel"]]]: + """Return all clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, list['ClientModel']] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/client/update_client.py b/gotify_rest_api_client/api/client/update_client.py new file mode 100644 index 0000000..f48d9e0 --- /dev/null +++ b/gotify_rest_api_client/api/client/update_client.py @@ -0,0 +1,189 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.client_model import ClientModel +from ...models.client_params_model import ClientParamsModel +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, + *, + body: ClientParamsModel, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "put", + "url": f"/client/{id}", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ClientModel, ErrorModel]]: + if response.status_code == 200: + response_200 = ClientModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ClientModel, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, + body: ClientParamsModel, +) -> Response[Union[ClientModel, ErrorModel]]: + """Update a client. + + Args: + id (int): + body (ClientParamsModel): Params allowed to create or update Clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ClientModel, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, + body: ClientParamsModel, +) -> Optional[Union[ClientModel, ErrorModel]]: + """Update a client. + + Args: + id (int): + body (ClientParamsModel): Params allowed to create or update Clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ClientModel, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, + body: ClientParamsModel, +) -> Response[Union[ClientModel, ErrorModel]]: + """Update a client. + + Args: + id (int): + body (ClientParamsModel): Params allowed to create or update Clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ClientModel, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, + body: ClientParamsModel, +) -> Optional[Union[ClientModel, ErrorModel]]: + """Update a client. + + Args: + id (int): + body (ClientParamsModel): Params allowed to create or update Clients. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ClientModel, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + body=body, + ) + ).parsed diff --git a/gotify_rest_api_client/api/health/__init__.py b/gotify_rest_api_client/api/health/__init__.py new file mode 100644 index 0000000..2d7c0b2 --- /dev/null +++ b/gotify_rest_api_client/api/health/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/gotify_rest_api_client/api/health/get_health.py b/gotify_rest_api_client/api/health/get_health.py new file mode 100644 index 0000000..86eba4f --- /dev/null +++ b/gotify_rest_api_client/api/health/get_health.py @@ -0,0 +1,126 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.health_model import HealthModel +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/health", + } + + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[HealthModel]: + if response.status_code == 200: + response_200 = HealthModel.from_dict(response.json()) + + return response_200 + if response.status_code == 500: + response_500 = HealthModel.from_dict(response.json()) + + return response_500 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[HealthModel]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: Union[AuthenticatedClient, Client], +) -> Response[HealthModel]: + """Get health information. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[HealthModel] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: Union[AuthenticatedClient, Client], +) -> Optional[HealthModel]: + """Get health information. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + HealthModel + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: Union[AuthenticatedClient, Client], +) -> Response[HealthModel]: + """Get health information. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[HealthModel] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: Union[AuthenticatedClient, Client], +) -> Optional[HealthModel]: + """Get health information. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + HealthModel + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/message/__init__.py b/gotify_rest_api_client/api/message/__init__.py new file mode 100644 index 0000000..2d7c0b2 --- /dev/null +++ b/gotify_rest_api_client/api/message/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/gotify_rest_api_client/api/message/create_message.py b/gotify_rest_api_client/api/message/create_message.py new file mode 100644 index 0000000..68f90c1 --- /dev/null +++ b/gotify_rest_api_client/api/message/create_message.py @@ -0,0 +1,183 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...models.message_external_model import MessageExternalModel +from ...types import Response + + +def _get_kwargs( + *, + body: MessageExternalModel, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/message", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, MessageExternalModel]]: + if response.status_code == 200: + response_200 = MessageExternalModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, MessageExternalModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, + body: MessageExternalModel, +) -> Response[Union[ErrorModel, MessageExternalModel]]: + """Create a message. + + __NOTE__: This API ONLY accepts an application token as authentication. + + Args: + body (MessageExternalModel): The MessageExternal holds information about a message which + was sent by an Application. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, MessageExternalModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: MessageExternalModel, +) -> Optional[Union[ErrorModel, MessageExternalModel]]: + """Create a message. + + __NOTE__: This API ONLY accepts an application token as authentication. + + Args: + body (MessageExternalModel): The MessageExternal holds information about a message which + was sent by an Application. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, MessageExternalModel] + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: MessageExternalModel, +) -> Response[Union[ErrorModel, MessageExternalModel]]: + """Create a message. + + __NOTE__: This API ONLY accepts an application token as authentication. + + Args: + body (MessageExternalModel): The MessageExternal holds information about a message which + was sent by an Application. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, MessageExternalModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + body: MessageExternalModel, +) -> Optional[Union[ErrorModel, MessageExternalModel]]: + """Create a message. + + __NOTE__: This API ONLY accepts an application token as authentication. + + Args: + body (MessageExternalModel): The MessageExternal holds information about a message which + was sent by an Application. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, MessageExternalModel] + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/gotify_rest_api_client/api/message/delete_app_messages.py b/gotify_rest_api_client/api/message/delete_app_messages.py new file mode 100644 index 0000000..010238e --- /dev/null +++ b/gotify_rest_api_client/api/message/delete_app_messages.py @@ -0,0 +1,165 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "delete", + "url": f"/application/{id}/message", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[Any, ErrorModel]]: + if response.status_code == 200: + response_200 = cast(Any, None) + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[Any, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Delete all messages from a specific application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Delete all messages from a specific application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Delete all messages from a specific application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Delete all messages from a specific application. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/message/delete_message.py b/gotify_rest_api_client/api/message/delete_message.py new file mode 100644 index 0000000..a2f1b06 --- /dev/null +++ b/gotify_rest_api_client/api/message/delete_message.py @@ -0,0 +1,165 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "delete", + "url": f"/message/{id}", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[Any, ErrorModel]]: + if response.status_code == 200: + response_200 = cast(Any, None) + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[Any, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Deletes a message with an id. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Deletes a message with an id. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Deletes a message with an id. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Deletes a message with an id. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/message/delete_messages.py b/gotify_rest_api_client/api/message/delete_messages.py new file mode 100644 index 0000000..a4e46c6 --- /dev/null +++ b/gotify_rest_api_client/api/message/delete_messages.py @@ -0,0 +1,133 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "delete", + "url": "/message", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[Any, ErrorModel]]: + if response.status_code == 200: + response_200 = cast(Any, None) + return response_200 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[Any, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Delete all messages. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Delete all messages. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Delete all messages. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Delete all messages. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/message/get_app_messages.py b/gotify_rest_api_client/api/message/get_app_messages.py new file mode 100644 index 0000000..9c8d515 --- /dev/null +++ b/gotify_rest_api_client/api/message/get_app_messages.py @@ -0,0 +1,203 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...models.paged_messages_model import PagedMessagesModel +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + id: int, + *, + limit: Union[Unset, int] = 100, + since: Union[Unset, int] = UNSET, +) -> dict[str, Any]: + params: dict[str, Any] = {} + + params["limit"] = limit + + params["since"] = since + + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} + + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/application/{id}/message", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, PagedMessagesModel]]: + if response.status_code == 200: + response_200 = PagedMessagesModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, PagedMessagesModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = 100, + since: Union[Unset, int] = UNSET, +) -> Response[Union[ErrorModel, PagedMessagesModel]]: + """Return all messages from a specific application. + + Args: + id (int): + limit (Union[Unset, int]): Default: 100. + since (Union[Unset, int]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, PagedMessagesModel]] + """ + + kwargs = _get_kwargs( + id=id, + limit=limit, + since=since, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = 100, + since: Union[Unset, int] = UNSET, +) -> Optional[Union[ErrorModel, PagedMessagesModel]]: + """Return all messages from a specific application. + + Args: + id (int): + limit (Union[Unset, int]): Default: 100. + since (Union[Unset, int]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, PagedMessagesModel] + """ + + return sync_detailed( + id=id, + client=client, + limit=limit, + since=since, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = 100, + since: Union[Unset, int] = UNSET, +) -> Response[Union[ErrorModel, PagedMessagesModel]]: + """Return all messages from a specific application. + + Args: + id (int): + limit (Union[Unset, int]): Default: 100. + since (Union[Unset, int]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, PagedMessagesModel]] + """ + + kwargs = _get_kwargs( + id=id, + limit=limit, + since=since, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = 100, + since: Union[Unset, int] = UNSET, +) -> Optional[Union[ErrorModel, PagedMessagesModel]]: + """Return all messages from a specific application. + + Args: + id (int): + limit (Union[Unset, int]): Default: 100. + since (Union[Unset, int]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, PagedMessagesModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + limit=limit, + since=since, + ) + ).parsed diff --git a/gotify_rest_api_client/api/message/get_messages.py b/gotify_rest_api_client/api/message/get_messages.py new file mode 100644 index 0000000..42835a5 --- /dev/null +++ b/gotify_rest_api_client/api/message/get_messages.py @@ -0,0 +1,186 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...models.paged_messages_model import PagedMessagesModel +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + limit: Union[Unset, int] = 100, + since: Union[Unset, int] = UNSET, +) -> dict[str, Any]: + params: dict[str, Any] = {} + + params["limit"] = limit + + params["since"] = since + + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} + + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/message", + "params": params, + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, PagedMessagesModel]]: + if response.status_code == 200: + response_200 = PagedMessagesModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, PagedMessagesModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = 100, + since: Union[Unset, int] = UNSET, +) -> Response[Union[ErrorModel, PagedMessagesModel]]: + """Return all messages. + + Args: + limit (Union[Unset, int]): Default: 100. + since (Union[Unset, int]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, PagedMessagesModel]] + """ + + kwargs = _get_kwargs( + limit=limit, + since=since, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = 100, + since: Union[Unset, int] = UNSET, +) -> Optional[Union[ErrorModel, PagedMessagesModel]]: + """Return all messages. + + Args: + limit (Union[Unset, int]): Default: 100. + since (Union[Unset, int]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, PagedMessagesModel] + """ + + return sync_detailed( + client=client, + limit=limit, + since=since, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = 100, + since: Union[Unset, int] = UNSET, +) -> Response[Union[ErrorModel, PagedMessagesModel]]: + """Return all messages. + + Args: + limit (Union[Unset, int]): Default: 100. + since (Union[Unset, int]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, PagedMessagesModel]] + """ + + kwargs = _get_kwargs( + limit=limit, + since=since, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + limit: Union[Unset, int] = 100, + since: Union[Unset, int] = UNSET, +) -> Optional[Union[ErrorModel, PagedMessagesModel]]: + """Return all messages. + + Args: + limit (Union[Unset, int]): Default: 100. + since (Union[Unset, int]): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, PagedMessagesModel] + """ + + return ( + await asyncio_detailed( + client=client, + limit=limit, + since=since, + ) + ).parsed diff --git a/gotify_rest_api_client/api/message/stream_messages.py b/gotify_rest_api_client/api/message/stream_messages.py new file mode 100644 index 0000000..3f4571b --- /dev/null +++ b/gotify_rest_api_client/api/message/stream_messages.py @@ -0,0 +1,143 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...models.message_external_model import MessageExternalModel +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/stream", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, MessageExternalModel]]: + if response.status_code == 200: + response_200 = MessageExternalModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 500: + response_500 = ErrorModel.from_dict(response.json()) + + return response_500 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, MessageExternalModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, MessageExternalModel]]: + """Websocket, return newly created messages. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, MessageExternalModel]] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, MessageExternalModel]]: + """Websocket, return newly created messages. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, MessageExternalModel] + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, MessageExternalModel]]: + """Websocket, return newly created messages. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, MessageExternalModel]] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, MessageExternalModel]]: + """Websocket, return newly created messages. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, MessageExternalModel] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/plugin/__init__.py b/gotify_rest_api_client/api/plugin/__init__.py new file mode 100644 index 0000000..2d7c0b2 --- /dev/null +++ b/gotify_rest_api_client/api/plugin/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/gotify_rest_api_client/api/plugin/disable_plugin.py b/gotify_rest_api_client/api/plugin/disable_plugin.py new file mode 100644 index 0000000..ec2ffbe --- /dev/null +++ b/gotify_rest_api_client/api/plugin/disable_plugin.py @@ -0,0 +1,165 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "post", + "url": f"/plugin/{id}/disable", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[Any, ErrorModel]]: + if response.status_code == 200: + response_200 = cast(Any, None) + return response_200 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if response.status_code == 500: + response_500 = ErrorModel.from_dict(response.json()) + + return response_500 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[Any, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Disable a plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Disable a plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Disable a plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Disable a plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/plugin/enable_plugin.py b/gotify_rest_api_client/api/plugin/enable_plugin.py new file mode 100644 index 0000000..1050ed4 --- /dev/null +++ b/gotify_rest_api_client/api/plugin/enable_plugin.py @@ -0,0 +1,165 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "post", + "url": f"/plugin/{id}/enable", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[Any, ErrorModel]]: + if response.status_code == 200: + response_200 = cast(Any, None) + return response_200 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if response.status_code == 500: + response_500 = ErrorModel.from_dict(response.json()) + + return response_500 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[Any, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Enable a plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Enable a plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Enable a plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Enable a plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/plugin/get_plugin_config.py b/gotify_rest_api_client/api/plugin/get_plugin_config.py new file mode 100644 index 0000000..93314f1 --- /dev/null +++ b/gotify_rest_api_client/api/plugin/get_plugin_config.py @@ -0,0 +1,91 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/plugin/{id}/config", + } + + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Any]: + """Get YAML configuration for Configurer plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Any]: + """Get YAML configuration for Configurer plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) diff --git a/gotify_rest_api_client/api/plugin/get_plugin_display.py b/gotify_rest_api_client/api/plugin/get_plugin_display.py new file mode 100644 index 0000000..2289850 --- /dev/null +++ b/gotify_rest_api_client/api/plugin/get_plugin_display.py @@ -0,0 +1,165 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/plugin/{id}/display", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, str]]: + if response.status_code == 200: + response_200 = cast(str, response.json()) + return response_200 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if response.status_code == 500: + response_500 = ErrorModel.from_dict(response.json()) + + return response_500 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, str]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, str]]: + """Get display info for a Displayer plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, str]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, str]]: + """Get display info for a Displayer plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, str] + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, str]]: + """Get display info for a Displayer plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, str]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, str]]: + """Get display info for a Displayer plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, str] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/plugin/get_plugins.py b/gotify_rest_api_client/api/plugin/get_plugins.py new file mode 100644 index 0000000..deab4d7 --- /dev/null +++ b/gotify_rest_api_client/api/plugin/get_plugins.py @@ -0,0 +1,148 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...models.plugin_conf_external_model import PluginConfExternalModel +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/plugin", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, list["PluginConfExternalModel"]]]: + if response.status_code == 200: + response_200 = [] + _response_200 = response.json() + for response_200_item_data in _response_200: + response_200_item = PluginConfExternalModel.from_dict(response_200_item_data) + + response_200.append(response_200_item) + + return response_200 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if response.status_code == 500: + response_500 = ErrorModel.from_dict(response.json()) + + return response_500 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, list["PluginConfExternalModel"]]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, list["PluginConfExternalModel"]]]: + """Return all plugins. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, list['PluginConfExternalModel']]] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, list["PluginConfExternalModel"]]]: + """Return all plugins. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, list['PluginConfExternalModel']] + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, list["PluginConfExternalModel"]]]: + """Return all plugins. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, list['PluginConfExternalModel']]] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, list["PluginConfExternalModel"]]]: + """Return all plugins. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, list['PluginConfExternalModel']] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/plugin/update_plugin_config.py b/gotify_rest_api_client/api/plugin/update_plugin_config.py new file mode 100644 index 0000000..a2bf207 --- /dev/null +++ b/gotify_rest_api_client/api/plugin/update_plugin_config.py @@ -0,0 +1,169 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "post", + "url": f"/plugin/{id}/config", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[Any, ErrorModel]]: + if response.status_code == 200: + response_200 = cast(Any, None) + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if response.status_code == 500: + response_500 = ErrorModel.from_dict(response.json()) + + return response_500 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[Any, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Update YAML configuration for Configurer plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Update YAML configuration for Configurer plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Update YAML configuration for Configurer plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Update YAML configuration for Configurer plugin. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/user/__init__.py b/gotify_rest_api_client/api/user/__init__.py new file mode 100644 index 0000000..2d7c0b2 --- /dev/null +++ b/gotify_rest_api_client/api/user/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/gotify_rest_api_client/api/user/create_user.py b/gotify_rest_api_client/api/user/create_user.py new file mode 100644 index 0000000..1115b52 --- /dev/null +++ b/gotify_rest_api_client/api/user/create_user.py @@ -0,0 +1,184 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.create_user_external_model import CreateUserExternalModel +from ...models.error_model import ErrorModel +from ...models.user_external_model import UserExternalModel +from ...types import Response + + +def _get_kwargs( + *, + body: CreateUserExternalModel, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/user", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, UserExternalModel]]: + if response.status_code == 200: + response_200 = UserExternalModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, UserExternalModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, + body: CreateUserExternalModel, +) -> Response[Union[ErrorModel, UserExternalModel]]: + """Create a user. + + With enabled registration: non admin users can be created without authentication. + With disabled registrations: users can only be created by admin users. + + Args: + body (CreateUserExternalModel): Used for user creation. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, UserExternalModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: CreateUserExternalModel, +) -> Optional[Union[ErrorModel, UserExternalModel]]: + """Create a user. + + With enabled registration: non admin users can be created without authentication. + With disabled registrations: users can only be created by admin users. + + Args: + body (CreateUserExternalModel): Used for user creation. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, UserExternalModel] + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: CreateUserExternalModel, +) -> Response[Union[ErrorModel, UserExternalModel]]: + """Create a user. + + With enabled registration: non admin users can be created without authentication. + With disabled registrations: users can only be created by admin users. + + Args: + body (CreateUserExternalModel): Used for user creation. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, UserExternalModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + body: CreateUserExternalModel, +) -> Optional[Union[ErrorModel, UserExternalModel]]: + """Create a user. + + With enabled registration: non admin users can be created without authentication. + With disabled registrations: users can only be created by admin users. + + Args: + body (CreateUserExternalModel): Used for user creation. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, UserExternalModel] + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/gotify_rest_api_client/api/user/current_user.py b/gotify_rest_api_client/api/user/current_user.py new file mode 100644 index 0000000..beab993 --- /dev/null +++ b/gotify_rest_api_client/api/user/current_user.py @@ -0,0 +1,135 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...models.user_external_model import UserExternalModel +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/current/user", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, UserExternalModel]]: + if response.status_code == 200: + response_200 = UserExternalModel.from_dict(response.json()) + + return response_200 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, UserExternalModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, UserExternalModel]]: + """Return the current user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, UserExternalModel]] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, UserExternalModel]]: + """Return the current user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, UserExternalModel] + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, UserExternalModel]]: + """Return the current user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, UserExternalModel]] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, UserExternalModel]]: + """Return the current user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, UserExternalModel] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/user/delete_user.py b/gotify_rest_api_client/api/user/delete_user.py new file mode 100644 index 0000000..75d2752 --- /dev/null +++ b/gotify_rest_api_client/api/user/delete_user.py @@ -0,0 +1,165 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "delete", + "url": f"/user/{id}", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[Any, ErrorModel]]: + if response.status_code == 200: + response_200 = cast(Any, None) + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[Any, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Deletes a user. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Deletes a user. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[Any, ErrorModel]]: + """Deletes a user. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[Any, ErrorModel]]: + """Deletes a user. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/user/get_user.py b/gotify_rest_api_client/api/user/get_user.py new file mode 100644 index 0000000..b3a4c0c --- /dev/null +++ b/gotify_rest_api_client/api/user/get_user.py @@ -0,0 +1,167 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...models.user_external_model import UserExternalModel +from ...types import Response + + +def _get_kwargs( + id: int, +) -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": f"/user/{id}", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, UserExternalModel]]: + if response.status_code == 200: + response_200 = UserExternalModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, UserExternalModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, UserExternalModel]]: + """Get a user. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, UserExternalModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, UserExternalModel]]: + """Get a user. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, UserExternalModel] + """ + + return sync_detailed( + id=id, + client=client, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, UserExternalModel]]: + """Get a user. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, UserExternalModel]] + """ + + kwargs = _get_kwargs( + id=id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, UserExternalModel]]: + """Get a user. + + Args: + id (int): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, UserExternalModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/user/get_users.py b/gotify_rest_api_client/api/user/get_users.py new file mode 100644 index 0000000..3784323 --- /dev/null +++ b/gotify_rest_api_client/api/user/get_users.py @@ -0,0 +1,140 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...models.user_external_model import UserExternalModel +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/user", + } + + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, list["UserExternalModel"]]]: + if response.status_code == 200: + response_200 = [] + _response_200 = response.json() + for response_200_item_data in _response_200: + response_200_item = UserExternalModel.from_dict(response_200_item_data) + + response_200.append(response_200_item) + + return response_200 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, list["UserExternalModel"]]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, list["UserExternalModel"]]]: + """Return all users. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, list['UserExternalModel']]] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, list["UserExternalModel"]]]: + """Return all users. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, list['UserExternalModel']] + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, +) -> Response[Union[ErrorModel, list["UserExternalModel"]]]: + """Return all users. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, list['UserExternalModel']]] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, +) -> Optional[Union[ErrorModel, list["UserExternalModel"]]]: + """Return all users. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, list['UserExternalModel']] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/api/user/update_current_user.py b/gotify_rest_api_client/api/user/update_current_user.py new file mode 100644 index 0000000..92456c3 --- /dev/null +++ b/gotify_rest_api_client/api/user/update_current_user.py @@ -0,0 +1,170 @@ +from http import HTTPStatus +from typing import Any, Optional, Union, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...models.user_external_pass_model import UserExternalPassModel +from ...types import Response + + +def _get_kwargs( + *, + body: UserExternalPassModel, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/current/user/password", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[Any, ErrorModel]]: + if response.status_code == 200: + response_200 = cast(Any, None) + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[Any, ErrorModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient, + body: UserExternalPassModel, +) -> Response[Union[Any, ErrorModel]]: + """Update the password of the current user. + + Args: + body (UserExternalPassModel): The Password for updating the user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient, + body: UserExternalPassModel, +) -> Optional[Union[Any, ErrorModel]]: + """Update the password of the current user. + + Args: + body (UserExternalPassModel): The Password for updating the user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient, + body: UserExternalPassModel, +) -> Response[Union[Any, ErrorModel]]: + """Update the password of the current user. + + Args: + body (UserExternalPassModel): The Password for updating the user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, ErrorModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient, + body: UserExternalPassModel, +) -> Optional[Union[Any, ErrorModel]]: + """Update the password of the current user. + + Args: + body (UserExternalPassModel): The Password for updating the user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[Any, ErrorModel] + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/gotify_rest_api_client/api/user/update_user.py b/gotify_rest_api_client/api/user/update_user.py new file mode 100644 index 0000000..ee0fc9b --- /dev/null +++ b/gotify_rest_api_client/api/user/update_user.py @@ -0,0 +1,189 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.error_model import ErrorModel +from ...models.update_user_external_model import UpdateUserExternalModel +from ...models.user_external_model import UserExternalModel +from ...types import Response + + +def _get_kwargs( + id: int, + *, + body: UpdateUserExternalModel, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": f"/user/{id}", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Optional[Union[ErrorModel, UserExternalModel]]: + if response.status_code == 200: + response_200 = UserExternalModel.from_dict(response.json()) + + return response_200 + if response.status_code == 400: + response_400 = ErrorModel.from_dict(response.json()) + + return response_400 + if response.status_code == 401: + response_401 = ErrorModel.from_dict(response.json()) + + return response_401 + if response.status_code == 403: + response_403 = ErrorModel.from_dict(response.json()) + + return response_403 + if response.status_code == 404: + response_404 = ErrorModel.from_dict(response.json()) + + return response_404 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: Union[AuthenticatedClient, Client], response: httpx.Response +) -> Response[Union[ErrorModel, UserExternalModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + id: int, + *, + client: AuthenticatedClient, + body: UpdateUserExternalModel, +) -> Response[Union[ErrorModel, UserExternalModel]]: + """Update a user. + + Args: + id (int): + body (UpdateUserExternalModel): Used for updating a user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, UserExternalModel]] + """ + + kwargs = _get_kwargs( + id=id, + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + id: int, + *, + client: AuthenticatedClient, + body: UpdateUserExternalModel, +) -> Optional[Union[ErrorModel, UserExternalModel]]: + """Update a user. + + Args: + id (int): + body (UpdateUserExternalModel): Used for updating a user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, UserExternalModel] + """ + + return sync_detailed( + id=id, + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + id: int, + *, + client: AuthenticatedClient, + body: UpdateUserExternalModel, +) -> Response[Union[ErrorModel, UserExternalModel]]: + """Update a user. + + Args: + id (int): + body (UpdateUserExternalModel): Used for updating a user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[ErrorModel, UserExternalModel]] + """ + + kwargs = _get_kwargs( + id=id, + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + id: int, + *, + client: AuthenticatedClient, + body: UpdateUserExternalModel, +) -> Optional[Union[ErrorModel, UserExternalModel]]: + """Update a user. + + Args: + id (int): + body (UpdateUserExternalModel): Used for updating a user. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Union[ErrorModel, UserExternalModel] + """ + + return ( + await asyncio_detailed( + id=id, + client=client, + body=body, + ) + ).parsed diff --git a/gotify_rest_api_client/api/version/__init__.py b/gotify_rest_api_client/api/version/__init__.py new file mode 100644 index 0000000..2d7c0b2 --- /dev/null +++ b/gotify_rest_api_client/api/version/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/gotify_rest_api_client/api/version/get_version.py b/gotify_rest_api_client/api/version/get_version.py new file mode 100644 index 0000000..bcf7771 --- /dev/null +++ b/gotify_rest_api_client/api/version/get_version.py @@ -0,0 +1,122 @@ +from http import HTTPStatus +from typing import Any, Optional, Union + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.version_info import VersionInfo +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/version", + } + + return _kwargs + + +def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[VersionInfo]: + if response.status_code == 200: + response_200 = VersionInfo.from_dict(response.json()) + + return response_200 + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[VersionInfo]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: Union[AuthenticatedClient, Client], +) -> Response[VersionInfo]: + """Get version information. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[VersionInfo] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: Union[AuthenticatedClient, Client], +) -> Optional[VersionInfo]: + """Get version information. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + VersionInfo + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: Union[AuthenticatedClient, Client], +) -> Response[VersionInfo]: + """Get version information. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[VersionInfo] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: Union[AuthenticatedClient, Client], +) -> Optional[VersionInfo]: + """Get version information. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + VersionInfo + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/gotify_rest_api_client/client.py b/gotify_rest_api_client/client.py new file mode 100644 index 0000000..e80446f --- /dev/null +++ b/gotify_rest_api_client/client.py @@ -0,0 +1,268 @@ +import ssl +from typing import Any, Optional, Union + +import httpx +from attrs import define, evolve, field + + +@define +class Client: + """A class for keeping track of data related to the API + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + + + Attributes: + raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a + status code that was not documented in the source OpenAPI document. Can also be provided as a keyword + argument to the constructor. + """ + + raise_on_unexpected_status: bool = field(default=False, kw_only=True) + _base_url: str = field(alias="base_url") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl") + _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: Optional[httpx.Client] = field(default=None, init=False) + _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False) + + def with_headers(self, headers: dict[str, str]) -> "Client": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self._headers, **headers}) + + def with_cookies(self, cookies: dict[str, str]) -> "Client": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self._cookies, **cookies}) + + def with_timeout(self, timeout: httpx.Timeout) -> "Client": + """Get a new client matching this one with a new timeout (in seconds)""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> "Client": + """Manually set the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self._client = httpx.Client( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._client + + def __enter__(self) -> "Client": + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client": + """Manually the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._async_client + + async def __aenter__(self) -> "Client": + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self + + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) + + +@define +class AuthenticatedClient: + """A Client which has been authenticated for use on secured endpoints + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + + + Attributes: + raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a + status code that was not documented in the source OpenAPI document. Can also be provided as a keyword + argument to the constructor. + token: The token to use for authentication + prefix: The prefix to use for the Authorization header + auth_header_name: The name of the Authorization header + """ + + raise_on_unexpected_status: bool = field(default=False, kw_only=True) + _base_url: str = field(alias="base_url") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl") + _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: Optional[httpx.Client] = field(default=None, init=False) + _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False) + + token: str + prefix: str = "Bearer" + auth_header_name: str = "Authorization" + + def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self._headers, **headers}) + + def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self._cookies, **cookies}) + + def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient": + """Get a new client matching this one with a new timeout (in seconds)""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient": + """Manually set the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._client = httpx.Client( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._client + + def __enter__(self) -> "AuthenticatedClient": + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient": + """Manually the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._async_client + + async def __aenter__(self) -> "AuthenticatedClient": + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self + + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) diff --git a/gotify_rest_api_client/errors.py b/gotify_rest_api_client/errors.py new file mode 100644 index 0000000..5f92e76 --- /dev/null +++ b/gotify_rest_api_client/errors.py @@ -0,0 +1,16 @@ +"""Contains shared errors types that can be raised from API functions""" + + +class UnexpectedStatus(Exception): + """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True""" + + def __init__(self, status_code: int, content: bytes): + self.status_code = status_code + self.content = content + + super().__init__( + f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}" + ) + + +__all__ = ["UnexpectedStatus"] diff --git a/gotify_rest_api_client/models/__init__.py b/gotify_rest_api_client/models/__init__.py new file mode 100644 index 0000000..1728727 --- /dev/null +++ b/gotify_rest_api_client/models/__init__.py @@ -0,0 +1,39 @@ +"""Contains all the data models used in inputs/outputs""" + +from .application_model import ApplicationModel +from .application_params_model import ApplicationParamsModel +from .client_model import ClientModel +from .client_params_model import ClientParamsModel +from .create_user_external_model import CreateUserExternalModel +from .error_model import ErrorModel +from .health_model import HealthModel +from .message_external_model import MessageExternalModel +from .message_external_model_extras import MessageExternalModelExtras +from .paged_messages_model import PagedMessagesModel +from .paging_model import PagingModel +from .plugin_conf_external_model import PluginConfExternalModel +from .update_user_external_model import UpdateUserExternalModel +from .upload_app_image_body import UploadAppImageBody +from .user_external_model import UserExternalModel +from .user_external_pass_model import UserExternalPassModel +from .version_info import VersionInfo + +__all__ = ( + "ApplicationModel", + "ApplicationParamsModel", + "ClientModel", + "ClientParamsModel", + "CreateUserExternalModel", + "ErrorModel", + "HealthModel", + "MessageExternalModel", + "MessageExternalModelExtras", + "PagedMessagesModel", + "PagingModel", + "PluginConfExternalModel", + "UpdateUserExternalModel", + "UploadAppImageBody", + "UserExternalModel", + "UserExternalPassModel", + "VersionInfo", +) diff --git a/gotify_rest_api_client/models/application_model.py b/gotify_rest_api_client/models/application_model.py new file mode 100644 index 0000000..d0b2a90 --- /dev/null +++ b/gotify_rest_api_client/models/application_model.py @@ -0,0 +1,154 @@ +import datetime +from collections.abc import Mapping +from typing import Any, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field +from dateutil.parser import isoparse + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ApplicationModel") + + +@_attrs_define +class ApplicationModel: + """The Application holds information about an app which can send notifications. + + Attributes: + description (Union[None, str]): The description of the application. Example: Backup server for the interwebs. + id (int): The application id. Example: 5. + image (str): The image of the application. Example: image/image.jpeg. + internal (bool): Whether the application is an internal application. Internal applications should not be + deleted. + name (str): The application name. This is how the application should be displayed to the user. Example: Backup + Server. + token (str): The application token. Can be used as `appToken`. See Authentication. Example: AWH0wZ5r0Mbac.r. + default_priority (Union[Unset, int]): The default priority of messages sent by this application. Defaults to 0. + Example: 4. + last_used (Union[None, Unset, datetime.datetime]): The last time the application token was used. Example: + 2019-01-01 00:00:00+00:00. + """ + + description: Union[None, str] + id: int + image: str + internal: bool + name: str + token: str + default_priority: Union[Unset, int] = UNSET + last_used: Union[None, Unset, datetime.datetime] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + description: Union[None, str] + description = self.description + + id = self.id + + image = self.image + + internal = self.internal + + name = self.name + + token = self.token + + default_priority = self.default_priority + + last_used: Union[None, Unset, str] + if isinstance(self.last_used, Unset): + last_used = UNSET + elif isinstance(self.last_used, datetime.datetime): + last_used = self.last_used.isoformat() + else: + last_used = self.last_used + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "description": description, + "id": id, + "image": image, + "internal": internal, + "name": name, + "token": token, + } + ) + if default_priority is not UNSET: + field_dict["defaultPriority"] = default_priority + if last_used is not UNSET: + field_dict["lastUsed"] = last_used + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + + def _parse_description(data: object) -> Union[None, str]: + if data is None: + return data + return cast(Union[None, str], data) + + description = _parse_description(d.pop("description")) + + id = d.pop("id") + + image = d.pop("image") + + internal = d.pop("internal") + + name = d.pop("name") + + token = d.pop("token") + + default_priority = d.pop("defaultPriority", UNSET) + + def _parse_last_used(data: object) -> Union[None, Unset, datetime.datetime]: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, str): + raise TypeError() + last_used_type_1 = isoparse(data) + + return last_used_type_1 + except: # noqa: E722 + pass + return cast(Union[None, Unset, datetime.datetime], data) + + last_used = _parse_last_used(d.pop("lastUsed", UNSET)) + + application_model = cls( + description=description, + id=id, + image=image, + internal=internal, + name=name, + token=token, + default_priority=default_priority, + last_used=last_used, + ) + + application_model.additional_properties = d + return application_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/application_params_model.py b/gotify_rest_api_client/models/application_params_model.py new file mode 100644 index 0000000..6f91c02 --- /dev/null +++ b/gotify_rest_api_client/models/application_params_model.py @@ -0,0 +1,82 @@ +from collections.abc import Mapping +from typing import Any, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ApplicationParamsModel") + + +@_attrs_define +class ApplicationParamsModel: + """Params allowed to create or update Applications. + + Attributes: + name (str): The application name. This is how the application should be displayed to the user. Example: Backup + Server. + default_priority (Union[Unset, int]): The default priority of messages sent by this application. Defaults to 0. + Example: 5. + description (Union[Unset, str]): The description of the application. Example: Backup server for the interwebs. + """ + + name: str + default_priority: Union[Unset, int] = UNSET + description: Union[Unset, str] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + name = self.name + + default_priority = self.default_priority + + description = self.description + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "name": name, + } + ) + if default_priority is not UNSET: + field_dict["defaultPriority"] = default_priority + if description is not UNSET: + field_dict["description"] = description + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + name = d.pop("name") + + default_priority = d.pop("defaultPriority", UNSET) + + description = d.pop("description", UNSET) + + application_params_model = cls( + name=name, + default_priority=default_priority, + description=description, + ) + + application_params_model.additional_properties = d + return application_params_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/client_model.py b/gotify_rest_api_client/models/client_model.py new file mode 100644 index 0000000..ad16ab2 --- /dev/null +++ b/gotify_rest_api_client/models/client_model.py @@ -0,0 +1,111 @@ +import datetime +from collections.abc import Mapping +from typing import Any, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field +from dateutil.parser import isoparse + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ClientModel") + + +@_attrs_define +class ClientModel: + """The Client holds information about a device which can receive notifications (and other stuff). + + Attributes: + id (int): The client id. Example: 5. + name (str): The client name. This is how the client should be displayed to the user. Example: Android Phone. + token (str): The client token. Can be used as `clientToken`. See Authentication. Example: CWH0wZ5r0Mbac.r. + last_used (Union[None, Unset, datetime.datetime]): The last time the client token was used. Example: 2019-01-01 + 00:00:00+00:00. + """ + + id: int + name: str + token: str + last_used: Union[None, Unset, datetime.datetime] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + id = self.id + + name = self.name + + token = self.token + + last_used: Union[None, Unset, str] + if isinstance(self.last_used, Unset): + last_used = UNSET + elif isinstance(self.last_used, datetime.datetime): + last_used = self.last_used.isoformat() + else: + last_used = self.last_used + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "id": id, + "name": name, + "token": token, + } + ) + if last_used is not UNSET: + field_dict["lastUsed"] = last_used + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + id = d.pop("id") + + name = d.pop("name") + + token = d.pop("token") + + def _parse_last_used(data: object) -> Union[None, Unset, datetime.datetime]: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, str): + raise TypeError() + last_used_type_1 = isoparse(data) + + return last_used_type_1 + except: # noqa: E722 + pass + return cast(Union[None, Unset, datetime.datetime], data) + + last_used = _parse_last_used(d.pop("lastUsed", UNSET)) + + client_model = cls( + id=id, + name=name, + token=token, + last_used=last_used, + ) + + client_model.additional_properties = d + return client_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/client_params_model.py b/gotify_rest_api_client/models/client_params_model.py new file mode 100644 index 0000000..a1c0313 --- /dev/null +++ b/gotify_rest_api_client/models/client_params_model.py @@ -0,0 +1,60 @@ +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="ClientParamsModel") + + +@_attrs_define +class ClientParamsModel: + """Params allowed to create or update Clients. + + Attributes: + name (str): The client name Example: My Client. + """ + + name: str + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + name = self.name + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "name": name, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + name = d.pop("name") + + client_params_model = cls( + name=name, + ) + + client_params_model.additional_properties = d + return client_params_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/create_user_external_model.py b/gotify_rest_api_client/models/create_user_external_model.py new file mode 100644 index 0000000..ef9d1ec --- /dev/null +++ b/gotify_rest_api_client/models/create_user_external_model.py @@ -0,0 +1,76 @@ +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="CreateUserExternalModel") + + +@_attrs_define +class CreateUserExternalModel: + """Used for user creation. + + Attributes: + admin (bool): If the user is an administrator. Example: True. + name (str): The user name. For login. Example: unicorn. + pass_ (str): The user password. For login. Example: nrocinu. + """ + + admin: bool + name: str + pass_: str + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + admin = self.admin + + name = self.name + + pass_ = self.pass_ + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "admin": admin, + "name": name, + "pass": pass_, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + admin = d.pop("admin") + + name = d.pop("name") + + pass_ = d.pop("pass") + + create_user_external_model = cls( + admin=admin, + name=name, + pass_=pass_, + ) + + create_user_external_model.additional_properties = d + return create_user_external_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/error_model.py b/gotify_rest_api_client/models/error_model.py new file mode 100644 index 0000000..32c9fe9 --- /dev/null +++ b/gotify_rest_api_client/models/error_model.py @@ -0,0 +1,77 @@ +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="ErrorModel") + + +@_attrs_define +class ErrorModel: + """The Error contains error relevant information. + + Attributes: + error (str): The general error message Example: Unauthorized. + error_code (int): The http error code. Example: 401. + error_description (str): The http error code. Example: you need to provide a valid access token or user + credentials to access this api. + """ + + error: str + error_code: int + error_description: str + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + error = self.error + + error_code = self.error_code + + error_description = self.error_description + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "error": error, + "errorCode": error_code, + "errorDescription": error_description, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + error = d.pop("error") + + error_code = d.pop("errorCode") + + error_description = d.pop("errorDescription") + + error_model = cls( + error=error, + error_code=error_code, + error_description=error_description, + ) + + error_model.additional_properties = d + return error_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/health_model.py b/gotify_rest_api_client/models/health_model.py new file mode 100644 index 0000000..577ea4b --- /dev/null +++ b/gotify_rest_api_client/models/health_model.py @@ -0,0 +1,68 @@ +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="HealthModel") + + +@_attrs_define +class HealthModel: + """Health represents how healthy the application is. + + Attributes: + database (str): The health of the database connection. Example: green. + health (str): The health of the overall application. Example: green. + """ + + database: str + health: str + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + database = self.database + + health = self.health + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "database": database, + "health": health, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + database = d.pop("database") + + health = d.pop("health") + + health_model = cls( + database=database, + health=health, + ) + + health_model.additional_properties = d + return health_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/message_external_model.py b/gotify_rest_api_client/models/message_external_model.py new file mode 100644 index 0000000..54af934 --- /dev/null +++ b/gotify_rest_api_client/models/message_external_model.py @@ -0,0 +1,139 @@ +import datetime +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field +from dateutil.parser import isoparse + +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.message_external_model_extras import MessageExternalModelExtras + + +T = TypeVar("T", bound="MessageExternalModel") + + +@_attrs_define +class MessageExternalModel: + """The MessageExternal holds information about a message which was sent by an Application. + + Attributes: + appid (int): The application id that send this message. Example: 5. + date (datetime.datetime): The date the message was created. Example: 2018-02-27 19:36:10.504504+01:00. + id (int): The message id. Example: 25. + message (str): The message. Markdown (excluding html) is allowed. Example: **Backup** was successfully + finished.. + extras (Union[Unset, MessageExternalModelExtras]): The extra data sent along the message. + + The extra fields are stored in a key-value scheme. Only accepted in CreateMessage requests with application/json + content-type. + + The keys should be in the following format: <top-namespace>::[<sub-namespace>::]<action> + + These namespaces are reserved and might be used in the official clients: gotify android ios web server client. + Do not use them for other purposes. Example: {'home::appliances::lighting::on': {'brightness': 15}, + 'home::appliances::thermostat::change_temperature': {'temperature': 23}}. + priority (Union[Unset, int]): The priority of the message. If unset, then the default priority of the + application will be used. Example: 2. + title (Union[Unset, str]): The title of the message. Example: Backup. + """ + + appid: int + date: datetime.datetime + id: int + message: str + extras: Union[Unset, "MessageExternalModelExtras"] = UNSET + priority: Union[Unset, int] = UNSET + title: Union[Unset, str] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + appid = self.appid + + date = self.date.isoformat() + + id = self.id + + message = self.message + + extras: Union[Unset, dict[str, Any]] = UNSET + if not isinstance(self.extras, Unset): + extras = self.extras.to_dict() + + priority = self.priority + + title = self.title + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "appid": appid, + "date": date, + "id": id, + "message": message, + } + ) + if extras is not UNSET: + field_dict["extras"] = extras + if priority is not UNSET: + field_dict["priority"] = priority + if title is not UNSET: + field_dict["title"] = title + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.message_external_model_extras import MessageExternalModelExtras + + d = dict(src_dict) + appid = d.pop("appid") + + date = isoparse(d.pop("date")) + + id = d.pop("id") + + message = d.pop("message") + + _extras = d.pop("extras", UNSET) + extras: Union[Unset, MessageExternalModelExtras] + if isinstance(_extras, Unset): + extras = UNSET + else: + extras = MessageExternalModelExtras.from_dict(_extras) + + priority = d.pop("priority", UNSET) + + title = d.pop("title", UNSET) + + message_external_model = cls( + appid=appid, + date=date, + id=id, + message=message, + extras=extras, + priority=priority, + title=title, + ) + + message_external_model.additional_properties = d + return message_external_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/message_external_model_extras.py b/gotify_rest_api_client/models/message_external_model_extras.py new file mode 100644 index 0000000..5d02f54 --- /dev/null +++ b/gotify_rest_api_client/models/message_external_model_extras.py @@ -0,0 +1,58 @@ +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="MessageExternalModelExtras") + + +@_attrs_define +class MessageExternalModelExtras: + """The extra data sent along the message. + + The extra fields are stored in a key-value scheme. Only accepted in CreateMessage requests with application/json + content-type. + + The keys should be in the following format: <top-namespace>::[<sub-namespace>::]<action> + + These namespaces are reserved and might be used in the official clients: gotify android ios web server client. Do + not use them for other purposes. + + Example: + {'home::appliances::lighting::on': {'brightness': 15}, 'home::appliances::thermostat::change_temperature': + {'temperature': 23}} + + """ + + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + message_external_model_extras = cls() + + message_external_model_extras.additional_properties = d + return message_external_model_extras + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/paged_messages_model.py b/gotify_rest_api_client/models/paged_messages_model.py new file mode 100644 index 0000000..cc5e406 --- /dev/null +++ b/gotify_rest_api_client/models/paged_messages_model.py @@ -0,0 +1,84 @@ +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +if TYPE_CHECKING: + from ..models.message_external_model import MessageExternalModel + from ..models.paging_model import PagingModel + + +T = TypeVar("T", bound="PagedMessagesModel") + + +@_attrs_define +class PagedMessagesModel: + """Wrapper for the paging and the messages. + + Attributes: + messages (list['MessageExternalModel']): The messages. + paging (PagingModel): The Paging holds information about the limit and making requests to the next page. + """ + + messages: list["MessageExternalModel"] + paging: "PagingModel" + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + messages = [] + for messages_item_data in self.messages: + messages_item = messages_item_data.to_dict() + messages.append(messages_item) + + paging = self.paging.to_dict() + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "messages": messages, + "paging": paging, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.message_external_model import MessageExternalModel + from ..models.paging_model import PagingModel + + d = dict(src_dict) + messages = [] + _messages = d.pop("messages") + for messages_item_data in _messages: + messages_item = MessageExternalModel.from_dict(messages_item_data) + + messages.append(messages_item) + + paging = PagingModel.from_dict(d.pop("paging")) + + paged_messages_model = cls( + messages=messages, + paging=paging, + ) + + paged_messages_model.additional_properties = d + return paged_messages_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/paging_model.py b/gotify_rest_api_client/models/paging_model.py new file mode 100644 index 0000000..f61b40c --- /dev/null +++ b/gotify_rest_api_client/models/paging_model.py @@ -0,0 +1,89 @@ +from collections.abc import Mapping +from typing import Any, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="PagingModel") + + +@_attrs_define +class PagingModel: + """The Paging holds information about the limit and making requests to the next page. + + Attributes: + limit (int): The limit of the messages for the current request. Example: 123. + since (int): The ID of the last message returned in the current request. Use this as alternative to the next + link. Example: 5. + size (int): The amount of messages that got returned in the current request. Example: 5. + next_ (Union[Unset, str]): The request url for the next page. Empty/Null when no next page is available. + Example: http://example.com/message?limit=50&since=123456. + """ + + limit: int + since: int + size: int + next_: Union[Unset, str] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + limit = self.limit + + since = self.since + + size = self.size + + next_ = self.next_ + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "limit": limit, + "since": since, + "size": size, + } + ) + if next_ is not UNSET: + field_dict["next"] = next_ + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + limit = d.pop("limit") + + since = d.pop("since") + + size = d.pop("size") + + next_ = d.pop("next", UNSET) + + paging_model = cls( + limit=limit, + since=since, + size=size, + next_=next_, + ) + + paging_model.additional_properties = d + return paging_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/plugin_conf_external_model.py b/gotify_rest_api_client/models/plugin_conf_external_model.py new file mode 100644 index 0000000..eab690f --- /dev/null +++ b/gotify_rest_api_client/models/plugin_conf_external_model.py @@ -0,0 +1,129 @@ +from collections.abc import Mapping +from typing import Any, TypeVar, Union, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="PluginConfExternalModel") + + +@_attrs_define +class PluginConfExternalModel: + """Holds information about a plugin instance for one user. + + Attributes: + capabilities (list[str]): Capabilities the plugin provides Example: ['webhook', 'display']. + enabled (bool): Whether the plugin instance is enabled. Example: True. + id (int): The plugin id. Example: 25. + module_path (str): The module path of the plugin. Example: github.com/gotify/server/plugin/example/echo. + name (str): The plugin name. Example: RSS poller. + token (str): The user name. For login. Example: P1234. + author (Union[Unset, str]): The author of the plugin. Example: jmattheis. + license_ (Union[Unset, str]): The license of the plugin. Example: MIT. + website (Union[Unset, str]): The website of the plugin. Example: gotify.net. + """ + + capabilities: list[str] + enabled: bool + id: int + module_path: str + name: str + token: str + author: Union[Unset, str] = UNSET + license_: Union[Unset, str] = UNSET + website: Union[Unset, str] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + capabilities = self.capabilities + + enabled = self.enabled + + id = self.id + + module_path = self.module_path + + name = self.name + + token = self.token + + author = self.author + + license_ = self.license_ + + website = self.website + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "capabilities": capabilities, + "enabled": enabled, + "id": id, + "modulePath": module_path, + "name": name, + "token": token, + } + ) + if author is not UNSET: + field_dict["author"] = author + if license_ is not UNSET: + field_dict["license"] = license_ + if website is not UNSET: + field_dict["website"] = website + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + capabilities = cast(list[str], d.pop("capabilities")) + + enabled = d.pop("enabled") + + id = d.pop("id") + + module_path = d.pop("modulePath") + + name = d.pop("name") + + token = d.pop("token") + + author = d.pop("author", UNSET) + + license_ = d.pop("license", UNSET) + + website = d.pop("website", UNSET) + + plugin_conf_external_model = cls( + capabilities=capabilities, + enabled=enabled, + id=id, + module_path=module_path, + name=name, + token=token, + author=author, + license_=license_, + website=website, + ) + + plugin_conf_external_model.additional_properties = d + return plugin_conf_external_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/update_user_external_model.py b/gotify_rest_api_client/models/update_user_external_model.py new file mode 100644 index 0000000..12aa0aa --- /dev/null +++ b/gotify_rest_api_client/models/update_user_external_model.py @@ -0,0 +1,79 @@ +from collections.abc import Mapping +from typing import Any, TypeVar, Union + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="UpdateUserExternalModel") + + +@_attrs_define +class UpdateUserExternalModel: + """Used for updating a user. + + Attributes: + admin (bool): If the user is an administrator. Example: True. + name (str): The user name. For login. Example: unicorn. + pass_ (Union[Unset, str]): The user password. For login. Empty for using old password Example: nrocinu. + """ + + admin: bool + name: str + pass_: Union[Unset, str] = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + admin = self.admin + + name = self.name + + pass_ = self.pass_ + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "admin": admin, + "name": name, + } + ) + if pass_ is not UNSET: + field_dict["pass"] = pass_ + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + admin = d.pop("admin") + + name = d.pop("name") + + pass_ = d.pop("pass", UNSET) + + update_user_external_model = cls( + admin=admin, + name=name, + pass_=pass_, + ) + + update_user_external_model.additional_properties = d + return update_user_external_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/upload_app_image_body.py b/gotify_rest_api_client/models/upload_app_image_body.py new file mode 100644 index 0000000..3c3fafd --- /dev/null +++ b/gotify_rest_api_client/models/upload_app_image_body.py @@ -0,0 +1,73 @@ +from collections.abc import Mapping +from io import BytesIO +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from .. import types +from ..types import File + +T = TypeVar("T", bound="UploadAppImageBody") + + +@_attrs_define +class UploadAppImageBody: + """ + Attributes: + file (File): the application image + """ + + file: File + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + file = self.file.to_tuple() + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "file": file, + } + ) + + return field_dict + + def to_multipart(self) -> types.RequestFiles: + files: types.RequestFiles = [] + + files.append(("file", self.file.to_tuple())) + + for prop_name, prop in self.additional_properties.items(): + files.append((prop_name, (None, str(prop).encode(), "text/plain"))) + + return files + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + file = File(payload=BytesIO(d.pop("file"))) + + upload_app_image_body = cls( + file=file, + ) + + upload_app_image_body.additional_properties = d + return upload_app_image_body + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/user_external_model.py b/gotify_rest_api_client/models/user_external_model.py new file mode 100644 index 0000000..ddae7aa --- /dev/null +++ b/gotify_rest_api_client/models/user_external_model.py @@ -0,0 +1,76 @@ +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="UserExternalModel") + + +@_attrs_define +class UserExternalModel: + """The User holds information about permission and other stuff. + + Attributes: + admin (bool): If the user is an administrator. Example: True. + id (int): The user id. Example: 25. + name (str): The user name. For login. Example: unicorn. + """ + + admin: bool + id: int + name: str + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + admin = self.admin + + id = self.id + + name = self.name + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "admin": admin, + "id": id, + "name": name, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + admin = d.pop("admin") + + id = d.pop("id") + + name = d.pop("name") + + user_external_model = cls( + admin=admin, + id=id, + name=name, + ) + + user_external_model.additional_properties = d + return user_external_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/user_external_pass_model.py b/gotify_rest_api_client/models/user_external_pass_model.py new file mode 100644 index 0000000..2d599ae --- /dev/null +++ b/gotify_rest_api_client/models/user_external_pass_model.py @@ -0,0 +1,60 @@ +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="UserExternalPassModel") + + +@_attrs_define +class UserExternalPassModel: + """The Password for updating the user. + + Attributes: + pass_ (str): The user password. For login. Example: nrocinu. + """ + + pass_: str + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + pass_ = self.pass_ + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "pass": pass_, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + pass_ = d.pop("pass") + + user_external_pass_model = cls( + pass_=pass_, + ) + + user_external_pass_model.additional_properties = d + return user_external_pass_model + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/models/version_info.py b/gotify_rest_api_client/models/version_info.py new file mode 100644 index 0000000..d0f0081 --- /dev/null +++ b/gotify_rest_api_client/models/version_info.py @@ -0,0 +1,77 @@ +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="VersionInfo") + + +@_attrs_define +class VersionInfo: + """VersionInfo Model + + Attributes: + build_date (str): The date on which this binary was built. Example: 2018-02-27 19:36:10.504504+01:00. + commit (str): The git commit hash on which this binary was built. Example: + ae9512b6b6feea56a110d59a3353ea3b9c293864. + version (str): The current version. Example: 5.2.6. + """ + + build_date: str + commit: str + version: str + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + build_date = self.build_date + + commit = self.commit + + version = self.version + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "buildDate": build_date, + "commit": commit, + "version": version, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + build_date = d.pop("buildDate") + + commit = d.pop("commit") + + version = d.pop("version") + + version_info = cls( + build_date=build_date, + commit=commit, + version=version, + ) + + version_info.additional_properties = d + return version_info + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/gotify_rest_api_client/py.typed b/gotify_rest_api_client/py.typed new file mode 100644 index 0000000..1aad327 --- /dev/null +++ b/gotify_rest_api_client/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561 \ No newline at end of file diff --git a/gotify_rest_api_client/types.py b/gotify_rest_api_client/types.py new file mode 100644 index 0000000..1b96ca4 --- /dev/null +++ b/gotify_rest_api_client/types.py @@ -0,0 +1,54 @@ +"""Contains some shared types for properties""" + +from collections.abc import Mapping, MutableMapping +from http import HTTPStatus +from typing import IO, BinaryIO, Generic, Literal, Optional, TypeVar, Union + +from attrs import define + + +class Unset: + def __bool__(self) -> Literal[False]: + return False + + +UNSET: Unset = Unset() + +# The types that `httpx.Client(files=)` can accept, copied from that library. +FileContent = Union[IO[bytes], bytes, str] +FileTypes = Union[ + # (filename, file (or bytes), content_type) + tuple[Optional[str], FileContent, Optional[str]], + # (filename, file (or bytes), content_type, headers) + tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], +] +RequestFiles = list[tuple[str, FileTypes]] + + +@define +class File: + """Contains information for file uploads""" + + payload: BinaryIO + file_name: Optional[str] = None + mime_type: Optional[str] = None + + def to_tuple(self) -> FileTypes: + """Return a tuple representation that httpx will accept for multipart/form-data""" + return self.file_name, self.payload, self.mime_type + + +T = TypeVar("T") + + +@define +class Response(Generic[T]): + """A response from an endpoint""" + + status_code: HTTPStatus + content: bytes + headers: MutableMapping[str, str] + parsed: Optional[T] + + +__all__ = ["UNSET", "File", "FileTypes", "RequestFiles", "Response", "Unset"] diff --git a/main/settings.py b/main/settings.py index e2bc94d..b06ac71 100644 --- a/main/settings.py +++ b/main/settings.py @@ -54,7 +54,7 @@ INSTALLED_APPS = [ 'apps.core', 'apps.users', 'apps.gooyal_oauth2', - 'apps.stores', + # 'apps.stores', ] MIDDLEWARE = [ diff --git a/utils/clients/gotify.py b/utils/clients/gotify.py new file mode 100644 index 0000000..642ca0b --- /dev/null +++ b/utils/clients/gotify.py @@ -0,0 +1,140 @@ +import time +from typing import Any + +import httpx +import requests +# from django.conf import settings +# from django.core.cache import cache +from django.db import models +from httpx import Request + +from gotify_rest_api_client import AuthenticatedClient +from gotify_rest_api_client.models import * +from gotify_rest_api_client.api.message import create_message +from gotify_rest_api_client.api.user import create_user +from gotify_rest_api_client.api.client import create_client +from gotify_rest_api_client.api.application import create_app + +ADMIN_CLIENT_TOKEN = 'CbWdsJrmRTDzbuD' + +import logging + +# logging.basicConfig( +# format="%(levelname)s [%(asctime)s] %(name)s - %(message)s", +# datefmt="%Y-%m-%d %H:%M:%S", +# level=logging.DEBUG +# ) +logger = logging.getLogger('utils.gotify_clients') + + +def log_request(request: Request): + logger.debug(f'authorization: {request.headers["authorization"]}') + logger.debug( + f"Request event hook: {request.method} {request.url} {request.method} {request.headers} - Waiting for response") + + +def log_response(response): + request = response.request + logger.debug(f"Response event hook: {request.method} {request.url} - Status {response.status_code}") + # logger.debug(f"Response event hook: {response.read()}") + + +def get_client(access_token): + client = AuthenticatedClient(base_url="https://push.gooyal.com", token=access_token, + httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}}, + ) + return client + + +def get_basic_client(username, password): + auth = httpx.BasicAuth(username=username, password=password) + prefix, token = auth._auth_header.split() + + # httpx_client = httpx.Client(auth=auth, base_url="https://push.gooyal.com") + client = AuthenticatedClient(base_url="https://push.gooyal.com", token=token, prefix=prefix, + httpx_args={ + "event_hooks": {"request": [log_request], "response": [log_response]}, + # "auth": auth, + # "base_url": "https://push.gooyal.com" + } + ) + # client.set_httpx_client(httpx_client) + return client + + +def send_notif(data): + class Tmp(): + def to_dict(self): + return data + + final_data = Tmp() + client = get_client() + response: Any = create_message.sync(client=client, body=final_data) + + return response + + +def submit_user(user_uuid): + data_dict = { + "admin": False, + "name": user_uuid, + "pass": user_uuid + } + + class Tmp(): + def to_dict(self): + return data_dict + + final_data = Tmp() + client = get_client(ADMIN_CLIENT_TOKEN) + response: Any = create_user.sync(client=client, body=final_data) + + return response + + +def submit_client(user_uuid): + data_dict = { + "name": user_uuid, + } + + class Tmp(): + def to_dict(self): + return data_dict + + final_data = Tmp() + client = get_basic_client(user_uuid, user_uuid) + response: Any = create_client.sync(client=client, body=final_data) + + return response + + +def submit_application(token, user_uuid): + data_dict = { + "defaultPriority": 5, + "description": None, + "name": user_uuid + } + + class Tmp(): + def to_dict(self): + return data_dict + + final_data = Tmp() + client = get_client(token) + response: Any = create_app.sync(client=client, body=final_data) + + return response + + +sample_data = { + "message": "**Backup** was successfully finished.", + "priority": 2, + "title": "Backup" +} + +# ClientModel(id=20, name='820c1110-a3bd-47ce-a3f4-f8d2dd70fa9f', token='CbNecn03yWNIl93', last_used=None, additional_properties={}) + +# send_notif(sample_data) +# print(submit_user('820c1110-a3bd-47ce-a3f4-f8d2dd70fa9f')) +# print(submit_client('820c1110-a3bd-47ce-a3f4-f8d2dd70fa9f')) +print(submit_application('CbNecn03yWNIl93','820c1110-a3bd-47ce-a3f4-f8d2dd70fa9f')) diff --git a/utils/clients/openapi.json b/utils/clients/openapi.json new file mode 100644 index 0000000..12045c1 --- /dev/null +++ b/utils/clients/openapi.json @@ -0,0 +1,2678 @@ +{ + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "schemes": [ + "http", + "https" + ], + "swagger": "2.0", + "info": { + "description": "This is the documentation of the Gotify REST-API.\n\n# Authentication\nIn Gotify there are two token types:\n__clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app)\n__appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script)\n\nThe token can be transmitted in a header named `X-Gotify-Key`, in a query parameter named `token` or\nthrough a header named `Authorization` with the value prefixed with `Bearer` (Ex. `Bearer randomtoken`).\nThere is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken.\n\n\\---\n\nFound a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues)", + "title": "Gotify REST-API.", + "license": { + "name": "MIT", + "url": "https://github.com/gotify/server/blob/master/LICENSE" + }, + "version": "2.0.2" + }, + "host": "push.gooyal.com", + "paths": { + "/application": { + "get": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "application" + ], + "summary": "Return all applications.", + "operationId": "getApps", + "responses": { + "200": { + "description": "Ok", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Application" + } + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "application" + ], + "summary": "Create an application.", + "operationId": "createApp", + "parameters": [ + { + "description": "the application to add", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/ApplicationParams" + } + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/Application" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/application/{id}": { + "put": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "application" + ], + "summary": "Update an application.", + "operationId": "updateApplication", + "parameters": [ + { + "description": "the application to update", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/ApplicationParams" + } + }, + { + "type": "integer", + "format": "int64", + "description": "the application id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/Application" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "delete": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "application" + ], + "summary": "Delete an application.", + "operationId": "deleteApp", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the application id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok" + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/application/{id}/image": { + "post": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "application" + ], + "summary": "Upload an image for an application.", + "operationId": "uploadAppImage", + "parameters": [ + { + "type": "file", + "description": "the application image", + "name": "file", + "in": "formData", + "required": true + }, + { + "type": "integer", + "format": "int64", + "description": "the application id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/Application" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Server Error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "delete": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "application" + ], + "summary": "Deletes an image of an application.", + "operationId": "removeAppImage", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the application id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok" + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Server Error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/application/{id}/message": { + "get": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "message" + ], + "summary": "Return all messages from a specific application.", + "operationId": "getAppMessages", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the application id", + "name": "id", + "in": "path", + "required": true + }, + { + "maximum": 200, + "minimum": 1, + "type": "integer", + "default": 100, + "description": "the maximal amount of messages to return", + "name": "limit", + "in": "query" + }, + { + "minimum": 0, + "type": "integer", + "format": "int64", + "description": "return all messages with an ID less than this value", + "name": "since", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/PagedMessages" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "delete": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "message" + ], + "summary": "Delete all messages from a specific application.", + "operationId": "deleteAppMessages", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the application id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok" + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/client": { + "get": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "client" + ], + "summary": "Return all clients.", + "operationId": "getClients", + "responses": { + "200": { + "description": "Ok", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Client" + } + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "client" + ], + "summary": "Create a client.", + "operationId": "createClient", + "parameters": [ + { + "description": "the client to add", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/ClientParams" + } + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/Client" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/client/{id}": { + "put": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "client" + ], + "summary": "Update a client.", + "operationId": "updateClient", + "parameters": [ + { + "description": "the client to update", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/ClientParams" + } + }, + { + "type": "integer", + "format": "int64", + "description": "the client id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/Client" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "delete": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "client" + ], + "summary": "Delete a client.", + "operationId": "deleteClient", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the client id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok" + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/current/user": { + "get": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Return the current user.", + "operationId": "currentUser", + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/User" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/current/user/password": { + "post": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Update the password of the current user.", + "operationId": "updateCurrentUser", + "parameters": [ + { + "description": "the user", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/UserPass" + } + } + ], + "responses": { + "200": { + "description": "Ok" + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/health": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "health" + ], + "summary": "Get health information.", + "operationId": "getHealth", + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/Health" + } + }, + "500": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/Health" + } + } + } + } + }, + "/message": { + "get": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "message" + ], + "summary": "Return all messages.", + "operationId": "getMessages", + "parameters": [ + { + "maximum": 200, + "minimum": 1, + "type": "integer", + "default": 100, + "description": "the maximal amount of messages to return", + "name": "limit", + "in": "query" + }, + { + "minimum": 0, + "type": "integer", + "format": "int64", + "description": "return all messages with an ID less than this value", + "name": "since", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/PagedMessages" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "security": [ + { + "appTokenAuthorizationHeader": [] + }, + { + "appTokenHeader": [] + }, + { + "appTokenQuery": [] + } + ], + "description": "__NOTE__: This API ONLY accepts an application token as authentication.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "message" + ], + "summary": "Create a message.", + "operationId": "createMessage", + "parameters": [ + { + "description": "the message to add", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/Message" + } + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/Message" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "delete": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "message" + ], + "summary": "Delete all messages.", + "operationId": "deleteMessages", + "responses": { + "200": { + "description": "Ok" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/message/{id}": { + "delete": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "message" + ], + "summary": "Deletes a message with an id.", + "operationId": "deleteMessage", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the message id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok" + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/plugin": { + "get": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "plugin" + ], + "summary": "Return all plugins.", + "operationId": "getPlugins", + "responses": { + "200": { + "description": "Ok", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/PluginConf" + } + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/plugin/{id}/config": { + "get": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/x-yaml" + ], + "tags": [ + "plugin" + ], + "summary": "Get YAML configuration for Configurer plugin.", + "operationId": "getPluginConfig", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the plugin id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "description": "plugin configuration", + "type": "object" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/x-yaml" + ], + "produces": [ + "application/json" + ], + "tags": [ + "plugin" + ], + "summary": "Update YAML configuration for Configurer plugin.", + "operationId": "updatePluginConfig", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the plugin id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok" + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/plugin/{id}/disable": { + "post": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "plugin" + ], + "summary": "Disable a plugin.", + "operationId": "disablePlugin", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the plugin id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/plugin/{id}/display": { + "get": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "plugin" + ], + "summary": "Get display info for a Displayer plugin.", + "operationId": "getPluginDisplay", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the plugin id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "type": "string" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/plugin/{id}/enable": { + "post": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "plugin" + ], + "summary": "Enable a plugin.", + "operationId": "enablePlugin", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the plugin id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/stream": { + "get": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "message" + ], + "summary": "Websocket, return newly created messages.", + "operationId": "streamMessages", + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/Message" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Server Error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/user": { + "get": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Return all users.", + "operationId": "getUsers", + "responses": { + "200": { + "description": "Ok", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/User" + } + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "description": "With enabled registration: non admin users can be created without authentication.\nWith disabled registrations: users can only be created by admin users.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Create a user.", + "operationId": "createUser", + "parameters": [ + { + "description": "the user to add", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/CreateUserExternal" + } + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/User" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/user/{id}": { + "get": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Get a user.", + "operationId": "getUser", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the user id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/User" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Update a user.", + "operationId": "updateUser", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the user id", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "the updated user", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/UpdateUserExternal" + } + } + ], + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/User" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "delete": { + "security": [ + { + "clientTokenAuthorizationHeader": [] + }, + { + "clientTokenHeader": [] + }, + { + "clientTokenQuery": [] + }, + { + "basicAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Deletes a user.", + "operationId": "deleteUser", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "the user id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Ok" + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/version": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "version" + ], + "summary": "Get version information.", + "operationId": "getVersion", + "responses": { + "200": { + "description": "Ok", + "schema": { + "$ref": "#/definitions/VersionInfo" + } + } + } + } + } + }, + "definitions": { + "Application": { + "description": "The Application holds information about an app which can send notifications.", + "type": "object", + "title": "Application Model", + "required": [ + "id", + "token", + "name", + "description", + "internal", + "image" + ], + "properties": { + "defaultPriority": { + "description": "The default priority of messages sent by this application. Defaults to 0.", + "type": "integer", + "format": "int64", + "x-go-name": "DefaultPriority", + "example": 4 + }, + "description": { + "description": "The description of the application.", + "type": "string", + "x-go-name": "Description", + "example": "Backup server for the interwebs" + }, + "id": { + "description": "The application id.", + "type": "integer", + "format": "int64", + "x-go-name": "ID", + "readOnly": true, + "example": 5 + }, + "image": { + "description": "The image of the application.", + "type": "string", + "x-go-name": "Image", + "readOnly": true, + "example": "image/image.jpeg" + }, + "internal": { + "description": "Whether the application is an internal application. Internal applications should not be deleted.", + "type": "boolean", + "x-go-name": "Internal", + "readOnly": true, + "example": false + }, + "lastUsed": { + "description": "The last time the application token was used.", + "type": "string", + "format": "date-time", + "x-go-name": "LastUsed", + "readOnly": true, + "example": "2019-01-01T00:00:00Z" + }, + "name": { + "description": "The application name. This is how the application should be displayed to the user.", + "type": "string", + "x-go-name": "Name", + "example": "Backup Server" + }, + "token": { + "description": "The application token. Can be used as `appToken`. See Authentication.", + "type": "string", + "x-go-name": "Token", + "readOnly": true, + "example": "AWH0wZ5r0Mbac.r" + } + }, + "x-go-package": "github.com/gotify/server/v2/model" + }, + "ApplicationParams": { + "description": "Params allowed to create or update Applications.", + "type": "object", + "title": "Application Params Model", + "required": [ + "name" + ], + "properties": { + "defaultPriority": { + "description": "The default priority of messages sent by this application. Defaults to 0.", + "type": "integer", + "format": "int64", + "x-go-name": "DefaultPriority", + "example": 5 + }, + "description": { + "description": "The description of the application.", + "type": "string", + "x-go-name": "Description", + "example": "Backup server for the interwebs" + }, + "name": { + "description": "The application name. This is how the application should be displayed to the user.", + "type": "string", + "x-go-name": "Name", + "example": "Backup Server" + } + }, + "x-go-package": "github.com/gotify/server/v2/api" + }, + "Client": { + "description": "The Client holds information about a device which can receive notifications (and other stuff).", + "type": "object", + "title": "Client Model", + "required": [ + "id", + "token", + "name" + ], + "properties": { + "id": { + "description": "The client id.", + "type": "integer", + "format": "int64", + "x-go-name": "ID", + "readOnly": true, + "example": 5 + }, + "lastUsed": { + "description": "The last time the client token was used.", + "type": "string", + "format": "date-time", + "x-go-name": "LastUsed", + "readOnly": true, + "example": "2019-01-01T00:00:00Z" + }, + "name": { + "description": "The client name. This is how the client should be displayed to the user.", + "type": "string", + "x-go-name": "Name", + "example": "Android Phone" + }, + "token": { + "description": "The client token. Can be used as `clientToken`. See Authentication.", + "type": "string", + "x-go-name": "Token", + "readOnly": true, + "example": "CWH0wZ5r0Mbac.r" + } + }, + "x-go-package": "github.com/gotify/server/v2/model" + }, + "ClientParams": { + "description": "Params allowed to create or update Clients.", + "type": "object", + "title": "Client Params Model", + "required": [ + "name" + ], + "properties": { + "name": { + "description": "The client name", + "type": "string", + "x-go-name": "Name", + "example": "My Client" + } + }, + "x-go-package": "github.com/gotify/server/v2/api" + }, + "CreateUserExternal": { + "description": "Used for user creation.", + "type": "object", + "title": "CreateUserExternal Model", + "required": [ + "name", + "admin", + "pass" + ], + "properties": { + "admin": { + "description": "If the user is an administrator.", + "type": "boolean", + "x-go-name": "Admin", + "example": true + }, + "name": { + "description": "The user name. For login.", + "type": "string", + "x-go-name": "Name", + "example": "unicorn" + }, + "pass": { + "description": "The user password. For login.", + "type": "string", + "x-go-name": "Pass", + "example": "nrocinu" + } + }, + "x-go-package": "github.com/gotify/server/v2/model" + }, + "Error": { + "description": "The Error contains error relevant information.", + "type": "object", + "title": "Error Model", + "required": [ + "error", + "errorCode", + "errorDescription" + ], + "properties": { + "error": { + "description": "The general error message", + "type": "string", + "x-go-name": "Error", + "example": "Unauthorized" + }, + "errorCode": { + "description": "The http error code.", + "type": "integer", + "format": "int64", + "x-go-name": "ErrorCode", + "example": 401 + }, + "errorDescription": { + "description": "The http error code.", + "type": "string", + "x-go-name": "ErrorDescription", + "example": "you need to provide a valid access token or user credentials to access this api" + } + }, + "x-go-package": "github.com/gotify/server/v2/model" + }, + "Health": { + "description": "Health represents how healthy the application is.", + "type": "object", + "title": "Health Model", + "required": [ + "health", + "database" + ], + "properties": { + "database": { + "description": "The health of the database connection.", + "type": "string", + "x-go-name": "Database", + "example": "green" + }, + "health": { + "description": "The health of the overall application.", + "type": "string", + "x-go-name": "Health", + "example": "green" + } + }, + "x-go-package": "github.com/gotify/server/v2/model" + }, + "Message": { + "description": "The MessageExternal holds information about a message which was sent by an Application.", + "type": "object", + "title": "MessageExternal Model", + "required": [ + "id", + "appid", + "message", + "date" + ], + "properties": { + "appid": { + "description": "The application id that send this message.", + "type": "integer", + "format": "int64", + "x-go-name": "ApplicationID", + "readOnly": true, + "example": 5 + }, + "date": { + "description": "The date the message was created.", + "type": "string", + "format": "date-time", + "x-go-name": "Date", + "readOnly": true, + "example": "2018-02-27T19:36:10.5045044+01:00" + }, + "extras": { + "description": "The extra data sent along the message.\n\nThe extra fields are stored in a key-value scheme. Only accepted in CreateMessage requests with application/json content-type.\n\nThe keys should be in the following format: \u0026lt;top-namespace\u0026gt;::[\u0026lt;sub-namespace\u0026gt;::]\u0026lt;action\u0026gt;\n\nThese namespaces are reserved and might be used in the official clients: gotify android ios web server client. Do not use them for other purposes.", + "type": "object", + "additionalProperties": {}, + "x-go-name": "Extras", + "example": { + "home::appliances::lighting::on": { + "brightness": 15 + }, + "home::appliances::thermostat::change_temperature": { + "temperature": 23 + } + } + }, + "id": { + "description": "The message id.", + "type": "integer", + "format": "int64", + "x-go-name": "ID", + "readOnly": true, + "example": 25 + }, + "message": { + "description": "The message. Markdown (excluding html) is allowed.", + "type": "string", + "x-go-name": "Message", + "example": "**Backup** was successfully finished." + }, + "priority": { + "description": "The priority of the message. If unset, then the default priority of the\napplication will be used.", + "type": "integer", + "format": "int64", + "x-go-name": "Priority", + "example": 2 + }, + "title": { + "description": "The title of the message.", + "type": "string", + "x-go-name": "Title", + "example": "Backup" + } + }, + "x-go-name": "MessageExternal", + "x-go-package": "github.com/gotify/server/v2/model" + }, + "PagedMessages": { + "description": "Wrapper for the paging and the messages.", + "type": "object", + "title": "PagedMessages Model", + "required": [ + "paging", + "messages" + ], + "properties": { + "messages": { + "description": "The messages.", + "type": "array", + "items": { + "$ref": "#/definitions/Message" + }, + "x-go-name": "Messages", + "readOnly": true + }, + "paging": { + "$ref": "#/definitions/Paging" + } + }, + "x-go-package": "github.com/gotify/server/v2/model" + }, + "Paging": { + "description": "The Paging holds information about the limit and making requests to the next page.", + "type": "object", + "title": "Paging Model", + "required": [ + "size", + "since", + "limit" + ], + "properties": { + "limit": { + "description": "The limit of the messages for the current request.", + "type": "integer", + "format": "int64", + "maximum": 200, + "minimum": 1, + "x-go-name": "Limit", + "readOnly": true, + "example": 123 + }, + "next": { + "description": "The request url for the next page. Empty/Null when no next page is available.", + "type": "string", + "x-go-name": "Next", + "readOnly": true, + "example": "http://example.com/message?limit=50\u0026since=123456" + }, + "since": { + "description": "The ID of the last message returned in the current request. Use this as alternative to the next link.", + "type": "integer", + "format": "int64", + "minimum": 0, + "x-go-name": "Since", + "readOnly": true, + "example": 5 + }, + "size": { + "description": "The amount of messages that got returned in the current request.", + "type": "integer", + "format": "int64", + "x-go-name": "Size", + "readOnly": true, + "example": 5 + } + }, + "x-go-package": "github.com/gotify/server/v2/model" + }, + "PluginConf": { + "description": "Holds information about a plugin instance for one user.", + "type": "object", + "title": "PluginConfExternal Model", + "required": [ + "id", + "name", + "token", + "modulePath", + "enabled", + "capabilities" + ], + "properties": { + "author": { + "description": "The author of the plugin.", + "type": "string", + "x-go-name": "Author", + "readOnly": true, + "example": "jmattheis" + }, + "capabilities": { + "description": "Capabilities the plugin provides", + "type": "array", + "items": { + "type": "string" + }, + "x-go-name": "Capabilities", + "example": [ + "webhook", + "display" + ] + }, + "enabled": { + "description": "Whether the plugin instance is enabled.", + "type": "boolean", + "x-go-name": "Enabled", + "example": true + }, + "id": { + "description": "The plugin id.", + "type": "integer", + "format": "int64", + "x-go-name": "ID", + "readOnly": true, + "example": 25 + }, + "license": { + "description": "The license of the plugin.", + "type": "string", + "x-go-name": "License", + "readOnly": true, + "example": "MIT" + }, + "modulePath": { + "description": "The module path of the plugin.", + "type": "string", + "x-go-name": "ModulePath", + "readOnly": true, + "example": "github.com/gotify/server/plugin/example/echo" + }, + "name": { + "description": "The plugin name.", + "type": "string", + "x-go-name": "Name", + "readOnly": true, + "example": "RSS poller" + }, + "token": { + "description": "The user name. For login.", + "type": "string", + "x-go-name": "Token", + "example": "P1234" + }, + "website": { + "description": "The website of the plugin.", + "type": "string", + "x-go-name": "Website", + "readOnly": true, + "example": "gotify.net" + } + }, + "x-go-name": "PluginConfExternal", + "x-go-package": "github.com/gotify/server/v2/model" + }, + "UpdateUserExternal": { + "description": "Used for updating a user.", + "type": "object", + "title": "UpdateUserExternal Model", + "required": [ + "name", + "admin" + ], + "properties": { + "admin": { + "description": "If the user is an administrator.", + "type": "boolean", + "x-go-name": "Admin", + "example": true + }, + "name": { + "description": "The user name. For login.", + "type": "string", + "x-go-name": "Name", + "example": "unicorn" + }, + "pass": { + "description": "The user password. For login. Empty for using old password", + "type": "string", + "x-go-name": "Pass", + "example": "nrocinu" + } + }, + "x-go-package": "github.com/gotify/server/v2/model" + }, + "User": { + "description": "The User holds information about permission and other stuff.", + "type": "object", + "title": "UserExternal Model", + "required": [ + "id", + "name", + "admin" + ], + "properties": { + "admin": { + "description": "If the user is an administrator.", + "type": "boolean", + "x-go-name": "Admin", + "example": true + }, + "id": { + "description": "The user id.", + "type": "integer", + "format": "int64", + "x-go-name": "ID", + "readOnly": true, + "example": 25 + }, + "name": { + "description": "The user name. For login.", + "type": "string", + "x-go-name": "Name", + "example": "unicorn" + } + }, + "x-go-name": "UserExternal", + "x-go-package": "github.com/gotify/server/v2/model" + }, + "UserPass": { + "description": "The Password for updating the user.", + "type": "object", + "title": "UserExternalPass Model", + "required": [ + "pass" + ], + "properties": { + "pass": { + "description": "The user password. For login.", + "type": "string", + "x-go-name": "Pass", + "example": "nrocinu" + } + }, + "x-go-name": "UserExternalPass", + "x-go-package": "github.com/gotify/server/v2/model" + }, + "VersionInfo": { + "description": "VersionInfo Model", + "type": "object", + "required": [ + "version", + "commit", + "buildDate" + ], + "properties": { + "buildDate": { + "description": "The date on which this binary was built.", + "type": "string", + "x-go-name": "BuildDate", + "example": "2018-02-27T19:36:10.5045044+01:00" + }, + "commit": { + "description": "The git commit hash on which this binary was built.", + "type": "string", + "x-go-name": "Commit", + "example": "ae9512b6b6feea56a110d59a3353ea3b9c293864" + }, + "version": { + "description": "The current version.", + "type": "string", + "x-go-name": "Version", + "example": "5.2.6" + } + }, + "x-go-package": "github.com/gotify/server/v2/model" + } + }, + "securityDefinitions": { + "appTokenAuthorizationHeader": { + "description": "Enter an application token with the `Bearer` prefix, e.g. `Bearer Axxxxxxxxxx`.", + "type": "apiKey", + "name": "Authorization", + "in": "header" + }, + "appTokenHeader": { + "type": "apiKey", + "name": "X-Gotify-Key", + "in": "header" + }, + "appTokenQuery": { + "type": "apiKey", + "name": "token", + "in": "query" + }, + "basicAuth": { + "type": "basic" + }, + "clientTokenAuthorizationHeader": { + "description": "Enter a client token with the `Bearer` prefix, e.g. `Bearer Cxxxxxxxxxx`.", + "type": "apiKey", + "name": "Authorization", + "in": "header" + }, + "clientTokenHeader": { + "type": "apiKey", + "name": "X-Gotify-Key", + "in": "header" + }, + "clientTokenQuery": { + "type": "apiKey", + "name": "token", + "in": "query" + } + } +} \ No newline at end of file diff --git a/utils/clients/openapi.yaml b/utils/clients/openapi.yaml new file mode 100644 index 0000000..478cc55 --- /dev/null +++ b/utils/clients/openapi.yaml @@ -0,0 +1,2002 @@ +openapi: 3.0.0 +x-origin: + - url: https://push.gooyal.com/swagger?base=push.gooyal.com%2F + format: swagger + version: "2.0" + converter: + url: https://github.com/mermade/oas-kit + version: 7.0.8 +info: + description: >- + This is the documentation of the Gotify REST-API. + + + # Authentication + + In Gotify there are two token types: + + __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app) + + __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script) + + + The token can be transmitted in a header named `X-Gotify-Key`, in a query parameter named `token` or + + through a header named `Authorization` with the value prefixed with `Bearer` (Ex. `Bearer randomtoken`). + + There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken. + + + \--- + + + Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues) + title: Gotify REST-API. + license: + name: MIT + url: https://github.com/gotify/server/blob/master/LICENSE + version: 2.0.2 +paths: + /application: + get: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - application + summary: Return all applications. + operationId: getApps + responses: + "200": + description: Ok + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/Application" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + post: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - application + summary: Create an application. + operationId: createApp + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/ApplicationParams" + description: the application to add + required: true + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/Application" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "/application/{id}": + put: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - application + summary: Update an application. + operationId: updateApplication + parameters: + - description: the application id + name: id + in: path + required: true + schema: + type: integer + format: int64 + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/ApplicationParams" + description: the application to update + required: true + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/Application" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + delete: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - application + summary: Delete an application. + operationId: deleteApp + parameters: + - description: the application id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "/application/{id}/image": + post: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - application + summary: Upload an image for an application. + operationId: uploadAppImage + parameters: + - description: the application id + name: id + in: path + required: true + schema: + type: integer + format: int64 + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + file: + description: the application image + type: string + format: binary + required: + - file + required: true + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/Application" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "500": + description: Server Error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + delete: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - application + summary: Deletes an image of an application. + operationId: removeAppImage + parameters: + - description: the application id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "500": + description: Server Error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "/application/{id}/message": + get: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - message + summary: Return all messages from a specific application. + operationId: getAppMessages + parameters: + - description: the application id + name: id + in: path + required: true + schema: + type: integer + format: int64 + - description: the maximal amount of messages to return + name: limit + in: query + schema: + type: integer + minimum: 1 + maximum: 200 + default: 100 + - description: return all messages with an ID less than this value + name: since + in: query + schema: + type: integer + format: int64 + minimum: 0 + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/PagedMessages" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + delete: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - message + summary: Delete all messages from a specific application. + operationId: deleteAppMessages + parameters: + - description: the application id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /client: + get: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - client + summary: Return all clients. + operationId: getClients + responses: + "200": + description: Ok + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/Client" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + post: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - client + summary: Create a client. + operationId: createClient + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/ClientParams" + description: the client to add + required: true + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/Client" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "/client/{id}": + put: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - client + summary: Update a client. + operationId: updateClient + parameters: + - description: the client id + name: id + in: path + required: true + schema: + type: integer + format: int64 + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/ClientParams" + description: the client to update + required: true + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/Client" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + delete: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - client + summary: Delete a client. + operationId: deleteClient + parameters: + - description: the client id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /current/user: + get: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - user + summary: Return the current user. + operationId: currentUser + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/User" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /current/user/password: + post: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - user + summary: Update the password of the current user. + operationId: updateCurrentUser + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/UserPass" + description: the user + required: true + responses: + "200": + description: Ok + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /health: + get: + tags: + - health + summary: Get health information. + operationId: getHealth + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/Health" + "500": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/Health" + /message: + get: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - message + summary: Return all messages. + operationId: getMessages + parameters: + - description: the maximal amount of messages to return + name: limit + in: query + schema: + type: integer + minimum: 1 + maximum: 200 + default: 100 + - description: return all messages with an ID less than this value + name: since + in: query + schema: + type: integer + format: int64 + minimum: 0 + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/PagedMessages" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + post: + security: + - appTokenAuthorizationHeader: [] + - appTokenHeader: [] + - appTokenQuery: [] + description: "__NOTE__: This API ONLY accepts an application token as authentication." + tags: + - message + summary: Create a message. + operationId: createMessage + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/Message" + description: the message to add + required: true + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/Message" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + delete: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - message + summary: Delete all messages. + operationId: deleteMessages + responses: + "200": + description: Ok + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "/message/{id}": + delete: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - message + summary: Deletes a message with an id. + operationId: deleteMessage + parameters: + - description: the message id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /plugin: + get: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - plugin + summary: Return all plugins. + operationId: getPlugins + responses: + "200": + description: Ok + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/PluginConf" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "500": + description: Internal Server Error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "/plugin/{id}/config": + get: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - plugin + summary: Get YAML configuration for Configurer plugin. + operationId: getPluginConfig + parameters: + - description: the plugin id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + content: + application/x-yaml: + schema: + description: plugin configuration + type: object + "400": + description: Bad Request + content: + application/x-yaml: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/x-yaml: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/x-yaml: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/x-yaml: + schema: + $ref: "#/components/schemas/Error" + "500": + description: Internal Server Error + content: + application/x-yaml: + schema: + $ref: "#/components/schemas/Error" + post: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - plugin + summary: Update YAML configuration for Configurer plugin. + operationId: updatePluginConfig + parameters: + - description: the plugin id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "500": + description: Internal Server Error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "/plugin/{id}/disable": + post: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - plugin + summary: Disable a plugin. + operationId: disablePlugin + parameters: + - description: the plugin id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "500": + description: Internal Server Error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "/plugin/{id}/display": + get: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - plugin + summary: Get display info for a Displayer plugin. + operationId: getPluginDisplay + parameters: + - description: the plugin id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + content: + application/json: + schema: + type: string + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "500": + description: Internal Server Error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "/plugin/{id}/enable": + post: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - plugin + summary: Enable a plugin. + operationId: enablePlugin + parameters: + - description: the plugin id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "500": + description: Internal Server Error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /stream: + get: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - message + summary: Websocket, return newly created messages. + operationId: streamMessages + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/Message" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "500": + description: Server Error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /user: + get: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - user + summary: Return all users. + operationId: getUsers + responses: + "200": + description: Ok + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/User" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + post: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + description: >- + With enabled registration: non admin users can be created without + authentication. + + With disabled registrations: users can only be created by admin users. + tags: + - user + summary: Create a user. + operationId: createUser + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/CreateUserExternal" + description: the user to add + required: true + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/User" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "/user/{id}": + get: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - user + summary: Get a user. + operationId: getUser + parameters: + - description: the user id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/User" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + post: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - user + summary: Update a user. + operationId: updateUser + parameters: + - description: the user id + name: id + in: path + required: true + schema: + type: integer + format: int64 + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/UpdateUserExternal" + description: the updated user + required: true + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/User" + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + delete: + security: + - clientTokenAuthorizationHeader: [] + - clientTokenHeader: [] + - clientTokenQuery: [] + - basicAuth: [] + tags: + - user + summary: Deletes a user. + operationId: deleteUser + parameters: + - description: the user id + name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Ok + "400": + description: Bad Request + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "401": + description: Unauthorized + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "403": + description: Forbidden + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + "404": + description: Not Found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /version: + get: + tags: + - version + summary: Get version information. + operationId: getVersion + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/VersionInfo" +servers: + - url: http://push.gooyal.com/ + - url: https://push.gooyal.com/ +components: + securitySchemes: + appTokenAuthorizationHeader: + description: Enter an application token with the `Bearer` prefix, e.g. `Bearer + Axxxxxxxxxx`. + type: apiKey + name: Authorization + in: header + appTokenHeader: + type: apiKey + name: X-Gotify-Key + in: header + appTokenQuery: + type: apiKey + name: token + in: query + basicAuth: + type: http + scheme: basic + clientTokenAuthorizationHeader: + description: Enter a client token with the `Bearer` prefix, e.g. `Bearer Cxxxxxxxxxx`. + type: apiKey + name: Authorization + in: header + clientTokenHeader: + type: apiKey + name: X-Gotify-Key + in: header + clientTokenQuery: + type: apiKey + name: token + in: query + schemas: + Application: + description: The Application holds information about an app which can send + notifications. + type: object + title: Application Model + required: + - id + - token + - name + - description + - internal + - image + properties: + defaultPriority: + description: The default priority of messages sent by this application. Defaults + to 0. + type: integer + format: int64 + x-go-name: DefaultPriority + example: 4 + description: + description: The description of the application. + type: + - "null" + - string + x-go-name: Description + example: Backup server for the interwebs + id: + description: The application id. + type: integer + format: int64 + x-go-name: ID + readOnly: true + example: 5 + image: + description: The image of the application. + type: string + x-go-name: Image + readOnly: true + example: image/image.jpeg + internal: + description: Whether the application is an internal application. Internal + applications should not be deleted. + type: boolean + x-go-name: Internal + readOnly: true + example: false + lastUsed: + description: The last time the application token was used. + type: + - "null" + - string + format: date-time + x-go-name: LastUsed + readOnly: true + example: 2019-01-01T00:00:00Z + name: + description: The application name. This is how the application should be + displayed to the user. + type: string + x-go-name: Name + example: Backup Server + token: + description: The application token. Can be used as `appToken`. See Authentication. + type: string + x-go-name: Token + readOnly: true + example: AWH0wZ5r0Mbac.r + x-go-package: github.com/gotify/server/v2/model + ApplicationParams: + description: Params allowed to create or update Applications. + type: object + title: Application Params Model + required: + - name + properties: + defaultPriority: + description: The default priority of messages sent by this application. Defaults + to 0. + type: integer + format: int64 + x-go-name: DefaultPriority + example: 5 + description: + description: The description of the application. + type: string + x-go-name: Description + example: Backup server for the interwebs + name: + description: The application name. This is how the application should be + displayed to the user. + type: string + x-go-name: Name + example: Backup Server + x-go-package: github.com/gotify/server/v2/api + Client: + description: The Client holds information about a device which can receive + notifications (and other stuff). + type: object + title: Client Model + required: + - id + - token + - name + properties: + id: + description: The client id. + type: integer + format: int64 + x-go-name: ID + readOnly: true + example: 5 + lastUsed: + description: The last time the client token was used. + type: + - "null" + - string + format: date-time + x-go-name: LastUsed + readOnly: true + example: 2019-01-01T00:00:00Z + name: + description: The client name. This is how the client should be displayed to the + user. + type: string + x-go-name: Name + example: Android Phone + token: + description: The client token. Can be used as `clientToken`. See Authentication. + type: string + x-go-name: Token + readOnly: true + example: CWH0wZ5r0Mbac.r + x-go-package: github.com/gotify/server/v2/model + ClientParams: + description: Params allowed to create or update Clients. + type: object + title: Client Params Model + required: + - name + properties: + name: + description: The client name + type: string + x-go-name: Name + example: My Client + x-go-package: github.com/gotify/server/v2/api + CreateUserExternal: + description: Used for user creation. + type: object + title: CreateUserExternal Model + required: + - name + - admin + - pass + properties: + admin: + description: If the user is an administrator. + type: boolean + x-go-name: Admin + example: true + name: + description: The user name. For login. + type: string + x-go-name: Name + example: unicorn + pass: + description: The user password. For login. + type: string + x-go-name: Pass + example: nrocinu + x-go-package: github.com/gotify/server/v2/model + Error: + description: The Error contains error relevant information. + type: object + title: Error Model + required: + - error + - errorCode + - errorDescription + properties: + error: + description: The general error message + type: string + x-go-name: Error + example: Unauthorized + errorCode: + description: The http error code. + type: integer + format: int64 + x-go-name: ErrorCode + example: 401 + errorDescription: + description: The http error code. + type: string + x-go-name: ErrorDescription + example: you need to provide a valid access token or user credentials to access + this api + x-go-package: github.com/gotify/server/v2/model + Health: + description: Health represents how healthy the application is. + type: object + title: Health Model + required: + - health + - database + properties: + database: + description: The health of the database connection. + type: string + x-go-name: Database + example: green + health: + description: The health of the overall application. + type: string + x-go-name: Health + example: green + x-go-package: github.com/gotify/server/v2/model + Message: + description: The MessageExternal holds information about a message which was + sent by an Application. + type: object + title: MessageExternal Model + required: + - id + - appid + - message + - date + properties: + appid: + description: The application id that send this message. + type: integer + format: int64 + x-go-name: ApplicationID + readOnly: true + example: 5 + date: + description: The date the message was created. + type: string + format: date-time + x-go-name: Date + readOnly: true + example: 2018-02-27T19:36:10.5045044+01:00 + extras: + description: >- + The extra data sent along the message. + + + The extra fields are stored in a key-value scheme. Only accepted in CreateMessage requests with application/json content-type. + + + The keys should be in the following format: <top-namespace>::[<sub-namespace>::]<action> + + + These namespaces are reserved and might be used in the official clients: gotify android ios web server client. Do not use them for other purposes. + type: object + additionalProperties: {} + x-go-name: Extras + example: + home::appliances::lighting::on: + brightness: 15 + home::appliances::thermostat::change_temperature: + temperature: 23 + id: + description: The message id. + type: integer + format: int64 + x-go-name: ID + readOnly: true + example: 25 + message: + description: The message. Markdown (excluding html) is allowed. + type: string + x-go-name: Message + example: "**Backup** was successfully finished." + priority: + description: >- + The priority of the message. If unset, then the default priority of + the + + application will be used. + type: integer + format: int64 + x-go-name: Priority + example: 2 + title: + description: The title of the message. + type: string + x-go-name: Title + example: Backup + x-go-name: MessageExternal + x-go-package: github.com/gotify/server/v2/model + PagedMessages: + description: Wrapper for the paging and the messages. + type: object + title: PagedMessages Model + required: + - paging + - messages + properties: + messages: + description: The messages. + type: array + items: + $ref: "#/components/schemas/Message" + x-go-name: Messages + readOnly: true + paging: + $ref: "#/components/schemas/Paging" + x-go-package: github.com/gotify/server/v2/model + Paging: + description: The Paging holds information about the limit and making requests to + the next page. + type: object + title: Paging Model + required: + - size + - since + - limit + properties: + limit: + description: The limit of the messages for the current request. + type: integer + format: int64 + maximum: 200 + minimum: 1 + x-go-name: Limit + readOnly: true + example: 123 + next: + description: The request url for the next page. Empty/Null when no next page is + available. + type: string + x-go-name: Next + readOnly: true + example: http://example.com/message?limit=50&since=123456 + since: + description: The ID of the last message returned in the current request. Use + this as alternative to the next link. + type: integer + format: int64 + minimum: 0 + x-go-name: Since + readOnly: true + example: 5 + size: + description: The amount of messages that got returned in the current request. + type: integer + format: int64 + x-go-name: Size + readOnly: true + example: 5 + x-go-package: github.com/gotify/server/v2/model + PluginConf: + description: Holds information about a plugin instance for one user. + type: object + title: PluginConfExternal Model + required: + - id + - name + - token + - modulePath + - enabled + - capabilities + properties: + author: + description: The author of the plugin. + type: string + x-go-name: Author + readOnly: true + example: jmattheis + capabilities: + description: Capabilities the plugin provides + type: array + items: + type: string + x-go-name: Capabilities + example: + - webhook + - display + enabled: + description: Whether the plugin instance is enabled. + type: boolean + x-go-name: Enabled + example: true + id: + description: The plugin id. + type: integer + format: int64 + x-go-name: ID + readOnly: true + example: 25 + license: + description: The license of the plugin. + type: string + x-go-name: License + readOnly: true + example: MIT + modulePath: + description: The module path of the plugin. + type: string + x-go-name: ModulePath + readOnly: true + example: github.com/gotify/server/plugin/example/echo + name: + description: The plugin name. + type: string + x-go-name: Name + readOnly: true + example: RSS poller + token: + description: The user name. For login. + type: string + x-go-name: Token + example: P1234 + website: + description: The website of the plugin. + type: string + x-go-name: Website + readOnly: true + example: gotify.net + x-go-name: PluginConfExternal + x-go-package: github.com/gotify/server/v2/model + UpdateUserExternal: + description: Used for updating a user. + type: object + title: UpdateUserExternal Model + required: + - name + - admin + properties: + admin: + description: If the user is an administrator. + type: boolean + x-go-name: Admin + example: true + name: + description: The user name. For login. + type: string + x-go-name: Name + example: unicorn + pass: + description: The user password. For login. Empty for using old password + type: string + x-go-name: Pass + example: nrocinu + x-go-package: github.com/gotify/server/v2/model + User: + description: The User holds information about permission and other stuff. + type: object + title: UserExternal Model + required: + - id + - name + - admin + properties: + admin: + description: If the user is an administrator. + type: boolean + x-go-name: Admin + example: true + id: + description: The user id. + type: integer + format: int64 + x-go-name: ID + readOnly: true + example: 25 + name: + description: The user name. For login. + type: string + x-go-name: Name + example: unicorn + x-go-name: UserExternal + x-go-package: github.com/gotify/server/v2/model + UserPass: + description: The Password for updating the user. + type: object + title: UserExternalPass Model + required: + - pass + properties: + pass: + description: The user password. For login. + type: string + x-go-name: Pass + example: nrocinu + x-go-name: UserExternalPass + x-go-package: github.com/gotify/server/v2/model + VersionInfo: + description: VersionInfo Model + type: object + required: + - version + - commit + - buildDate + properties: + buildDate: + description: The date on which this binary was built. + type: string + x-go-name: BuildDate + example: 2018-02-27T19:36:10.5045044+01:00 + commit: + description: The git commit hash on which this binary was built. + type: string + x-go-name: Commit + example: ae9512b6b6feea56a110d59a3353ea3b9c293864 + version: + description: The current version. + type: string + x-go-name: Version + example: 5.2.6 + x-go-package: github.com/gotify/server/v2/model