Reaction.py
1 ############################ Copyrights and license ############################ 2 # # 3 # Copyright 2017 Nicolas AgustÃn Torres <nicolastrres@gmail.com> # 4 # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # 5 # Copyright 2018 sfdye <tsfdye@gmail.com> # 6 # # 7 # This file is part of PyGithub. # 8 # http://pygithub.readthedocs.io/ # 9 # # 10 # PyGithub is free software: you can redistribute it and/or modify it under # 11 # the terms of the GNU Lesser General Public License as published by the Free # 12 # Software Foundation, either version 3 of the License, or (at your option) # 13 # any later version. # 14 # # 15 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # 16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # 17 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # 18 # details. # 19 # # 20 # You should have received a copy of the GNU Lesser General Public License # 21 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # 22 # # 23 ################################################################################ 24 from __future__ import annotations 25 26 from datetime import datetime 27 from typing import TYPE_CHECKING, Any 28 29 import github.NamedUser 30 from github.GithubObject import Attribute, CompletableGithubObject, NotSet 31 32 from . import Consts 33 34 if TYPE_CHECKING: 35 from github.NamedUser import NamedUser 36 37 38 class Reaction(CompletableGithubObject): 39 """ 40 This class represents Reactions. The reference can be found here https://docs.github.com/en/rest/reference/reactions 41 """ 42 43 def _initAttributes(self) -> None: 44 self._content: Attribute[str] = NotSet 45 self._created_at: Attribute[datetime] = NotSet 46 self._id: Attribute[int] = NotSet 47 self._user: Attribute[NamedUser] = NotSet 48 49 def __repr__(self) -> str: 50 return self.get__repr__({"id": self._id.value, "user": self._user.value}) 51 52 @property 53 def content(self) -> str: 54 self._completeIfNotSet(self._content) 55 return self._content.value 56 57 @property 58 def created_at(self) -> datetime: 59 self._completeIfNotSet(self._created_at) 60 return self._created_at.value 61 62 @property 63 def id(self) -> int: 64 self._completeIfNotSet(self._id) 65 return self._id.value 66 67 @property 68 def user(self) -> NamedUser: 69 self._completeIfNotSet(self._user) 70 return self._user.value 71 72 def delete(self) -> None: 73 """ 74 :calls: `DELETE /reactions/{id} <https://docs.github.com/en/rest/reference/reactions#delete-a-reaction-legacy>`_ 75 :rtype: None 76 """ 77 self._requester.requestJsonAndCheck( 78 "DELETE", 79 f"{self._parentUrl('')}/reactions/{self.id}", 80 headers={"Accept": Consts.mediaTypeReactionsPreview}, 81 ) 82 83 def _useAttributes(self, attributes: dict[str, Any]) -> None: 84 if "content" in attributes: # pragma no branch 85 self._content = self._makeStringAttribute(attributes["content"]) 86 if "created_at" in attributes: # pragma no branch 87 self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) 88 if "id" in attributes: # pragma no branch 89 self._id = self._makeIntAttribute(attributes["id"]) 90 if "user" in attributes: # pragma no branch 91 self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])