1# -*- coding: utf-8 -*-
2
3############################ Copyrights and license ############################
4#                                                                              #
5# Copyright 2017 Jannis Gebauer <ja.geb@me.com>                                #
6# Copyright 2017 Simon <spam@esemi.ru>                                         #
7# Copyright 2018 Wan Liuyang <tsfdye@gmail.com>                                #
8# Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
9# Copyright 2019 Rigas Papathanasopoulos <rigaspapas@gmail.com>                #
10#                                                                              #
11# This file is part of PyGithub.                                               #
12# http://pygithub.readthedocs.io/                                              #
13#                                                                              #
14# PyGithub is free software: you can redistribute it and/or modify it under    #
15# the terms of the GNU Lesser General Public License as published by the Free  #
16# Software Foundation, either version 3 of the License, or (at your option)    #
17# any later version.                                                           #
18#                                                                              #
19# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
20# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
21# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
22# details.                                                                     #
23#                                                                              #
24# You should have received a copy of the GNU Lesser General Public License     #
25# along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
26#                                                                              #
27################################################################################
28
29import github.Authorization
30import github.Event
31import github.Gist
32import github.GithubObject
33import github.Issue
34import github.Notification
35import github.Organization
36import github.PaginatedList
37import github.Plan
38import github.Repository
39import github.UserKey
40
41from . import Consts
42
43INTEGRATION_PREVIEW_HEADERS = {"Accept": Consts.mediaTypeIntegrationPreview}
44
45
46class Installation(github.GithubObject.NonCompletableGithubObject):
47    """
48    This class represents Installations. The reference can be found here https://developer.github.com/v3/apps/installations/
49    """
50
51    def __repr__(self):
52        return self.get__repr__({"id": self._id.value})
53
54    @property
55    def id(self):
56        """
57        :type: integer
58        """
59        return self._id.value
60
61    @property
62    def app_id(self):
63        """
64        :type: integer
65        """
66        return self._app_id.value
67
68    @property
69    def target_id(self):
70        """
71        :type: integer
72        """
73        return self._target_id.value
74
75    @property
76    def target_type(self):
77        """
78        :type: string
79        """
80        return self._target_type.value
81
82    def get_repos(self):
83        """
84        :calls: `GET /installation/repositories <https://developer.github.com/v3/integrations/installations/#list-repositories>`_
85        :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
86        """
87        url_parameters = dict()
88
89        return github.PaginatedList.PaginatedList(
90            contentClass=github.Repository.Repository,
91            requester=self._requester,
92            firstUrl="/installation/repositories",
93            firstParams=url_parameters,
94            headers=INTEGRATION_PREVIEW_HEADERS,
95            list_item="repositories",
96        )
97
98    def _initAttributes(self):
99        self._id = github.GithubObject.NotSet
100        self._app_id = github.GithubObject.NotSet
101        self._target_id = github.GithubObject.NotSet
102        self._target_type = github.GithubObject.NotSet
103
104    def _useAttributes(self, attributes):
105        if "id" in attributes:  # pragma no branch
106            self._id = self._makeIntAttribute(attributes["id"])
107        if "app_id" in attributes:  # pragma no branch
108            self._app_id = self._makeIntAttribute(attributes["app_id"])
109        if "target_id" in attributes:  # pragma no branch
110            self._target_id = self._makeIntAttribute(attributes["target_id"])
111        if "target_type" in attributes:  # pragma no branch
112            self._target_type = self._makeStringAttribute(attributes["target_type"])
113