|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | + ActivitySmith API |
| 5 | +
|
| 6 | + Send push notifications and Live Activities to your own devices via a single API key. |
| 7 | +
|
| 8 | + The version of the OpenAPI document: 1.0.0 |
| 9 | + Generated by OpenAPI Generator (https://openapi-generator.tech) |
| 10 | +
|
| 11 | + Do not edit the class manually. |
| 12 | +""" # noqa: E501 |
| 13 | + |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | +import pprint |
| 17 | +import re # noqa: F401 |
| 18 | +import json |
| 19 | + |
| 20 | +from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator |
| 21 | +from typing import Any, ClassVar, Dict, List, Optional |
| 22 | +from typing_extensions import Annotated |
| 23 | +from activitysmith_openapi.models.push_notification_action_type import PushNotificationActionType |
| 24 | +from activitysmith_openapi.models.push_notification_webhook_method import PushNotificationWebhookMethod |
| 25 | +from typing import Optional, Set |
| 26 | +from typing_extensions import Self |
| 27 | + |
| 28 | +class PushNotificationAction(BaseModel): |
| 29 | + """ |
| 30 | + PushNotificationAction |
| 31 | + """ # noqa: E501 |
| 32 | + title: StrictStr = Field(description="Button title displayed in iOS expanded notification UI.") |
| 33 | + type: PushNotificationActionType |
| 34 | + url: Annotated[str, Field(strict=True)] = Field(description="HTTPS URL. For open_url it is opened in browser. For webhook it is called by ActivitySmith backend.") |
| 35 | + method: Optional[PushNotificationWebhookMethod] = Field(default=PushNotificationWebhookMethod.POST, description="Webhook HTTP method. Used only when type=webhook.") |
| 36 | + body: Optional[Dict[str, Any]] = Field(default=None, description="Optional webhook payload body. Used only when type=webhook.") |
| 37 | + additional_properties: Dict[str, Any] = {} |
| 38 | + __properties: ClassVar[List[str]] = ["title", "type", "url", "method", "body"] |
| 39 | + |
| 40 | + @field_validator('url') |
| 41 | + def url_validate_regular_expression(cls, value): |
| 42 | + """Validates the regular expression""" |
| 43 | + if not re.match(r"^https:\/\/", value): |
| 44 | + raise ValueError(r"must validate the regular expression /^https:\/\//") |
| 45 | + return value |
| 46 | + |
| 47 | + model_config = ConfigDict( |
| 48 | + populate_by_name=True, |
| 49 | + validate_assignment=True, |
| 50 | + protected_namespaces=(), |
| 51 | + ) |
| 52 | + |
| 53 | + |
| 54 | + def to_str(self) -> str: |
| 55 | + """Returns the string representation of the model using alias""" |
| 56 | + return pprint.pformat(self.model_dump(by_alias=True)) |
| 57 | + |
| 58 | + def to_json(self) -> str: |
| 59 | + """Returns the JSON representation of the model using alias""" |
| 60 | + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead |
| 61 | + return json.dumps(self.to_dict()) |
| 62 | + |
| 63 | + @classmethod |
| 64 | + def from_json(cls, json_str: str) -> Optional[Self]: |
| 65 | + """Create an instance of PushNotificationAction from a JSON string""" |
| 66 | + return cls.from_dict(json.loads(json_str)) |
| 67 | + |
| 68 | + def to_dict(self) -> Dict[str, Any]: |
| 69 | + """Return the dictionary representation of the model using alias. |
| 70 | +
|
| 71 | + This has the following differences from calling pydantic's |
| 72 | + `self.model_dump(by_alias=True)`: |
| 73 | +
|
| 74 | + * `None` is only added to the output dict for nullable fields that |
| 75 | + were set at model initialization. Other fields with value `None` |
| 76 | + are ignored. |
| 77 | + * Fields in `self.additional_properties` are added to the output dict. |
| 78 | + """ |
| 79 | + excluded_fields: Set[str] = set([ |
| 80 | + "additional_properties", |
| 81 | + ]) |
| 82 | + |
| 83 | + _dict = self.model_dump( |
| 84 | + by_alias=True, |
| 85 | + exclude=excluded_fields, |
| 86 | + exclude_none=True, |
| 87 | + ) |
| 88 | + # puts key-value pairs in additional_properties in the top level |
| 89 | + if self.additional_properties is not None: |
| 90 | + for _key, _value in self.additional_properties.items(): |
| 91 | + _dict[_key] = _value |
| 92 | + |
| 93 | + return _dict |
| 94 | + |
| 95 | + @classmethod |
| 96 | + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: |
| 97 | + """Create an instance of PushNotificationAction from a dict""" |
| 98 | + if obj is None: |
| 99 | + return None |
| 100 | + |
| 101 | + if not isinstance(obj, dict): |
| 102 | + return cls.model_validate(obj) |
| 103 | + |
| 104 | + _obj = cls.model_validate({ |
| 105 | + "title": obj.get("title"), |
| 106 | + "type": obj.get("type"), |
| 107 | + "url": obj.get("url"), |
| 108 | + "method": obj.get("method") if obj.get("method") is not None else PushNotificationWebhookMethod.POST, |
| 109 | + "body": obj.get("body") |
| 110 | + }) |
| 111 | + # store additional fields in additional_properties |
| 112 | + for _key in obj.keys(): |
| 113 | + if _key not in cls.__properties: |
| 114 | + _obj.additional_properties[_key] = obj.get(_key) |
| 115 | + |
| 116 | + return _obj |
| 117 | + |
| 118 | + |
0 commit comments