/ github / Referrer.py
Referrer.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2018 Justin Kufro <jkufro@andrew.cmu.edu>                          #
 4  # Copyright 2018 Ivan Minno <iminno@andrew.cmu.edu>                            #
 5  # Copyright 2018 Zilei Gu <zileig@andrew.cmu.edu>                              #
 6  # Copyright 2018 Yves Zumbach <yzumbach@andrew.cmu.edu>                        #
 7  # Copyright 2018 Leying Chen <leyingc@andrew.cmu.edu>                          #
 8  #                                                                              #
 9  # This file is part of PyGithub.                                               #
10  # http://pygithub.readthedocs.io/                                              #
11  #                                                                              #
12  # PyGithub is free software: you can redistribute it and/or modify it under    #
13  # the terms of the GNU Lesser General Public License as published by the Free  #
14  # Software Foundation, either version 3 of the License, or (at your option)    #
15  # any later version.                                                           #
16  #                                                                              #
17  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
18  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
19  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
20  # details.                                                                     #
21  #                                                                              #
22  # You should have received a copy of the GNU Lesser General Public License     #
23  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
24  #                                                                              #
25  ################################################################################
26  from typing import Any, Dict
27  
28  from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet
29  
30  
31  class Referrer(NonCompletableGithubObject):
32      """
33      This class represents a popylar Referrer for a GitHub repository.
34      The reference can be found here https://docs.github.com/en/rest/reference/repos#traffic
35      """
36  
37      def _initAttributes(self) -> None:
38          self._referrer: Attribute[str] = NotSet
39          self._count: Attribute[int] = NotSet
40          self._uniques: Attribute[int] = NotSet
41  
42      def __repr__(self) -> str:
43          return self.get__repr__(
44              {
45                  "referrer": self._referrer.value,
46                  "count": self._count.value,
47                  "uniques": self._uniques.value,
48              }
49          )
50  
51      @property
52      def referrer(self) -> str:
53          return self._referrer.value
54  
55      @property
56      def count(self) -> int:
57          return self._count.value
58  
59      @property
60      def uniques(self) -> int:
61          return self._uniques.value
62  
63      def _useAttributes(self, attributes: Dict[str, Any]) -> None:
64          if "referrer" in attributes:  # pragma no branch
65              self._referrer = self._makeStringAttribute(attributes["referrer"])
66          if "count" in attributes:  # pragma no branch
67              self._count = self._makeIntAttribute(attributes["count"])
68          if "uniques" in attributes:  # pragma no branch
69              self._uniques = self._makeIntAttribute(attributes["uniques"])