aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/services/repos/watchers.py
blob: cdc3624ae64d2db98d834c9c5ee96c7cd403eaaf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from . import Service


class Watchers(Service):
    """ Consume `Watching API
    <http://developer.github.com/v3/repos/watching>`_ """

    def list(self, user=None, repo=None):
        """ Get repository's watchers

        :param str user: Username
        :param str repo: Repository
        :returns: A :doc:`result`

        .. note::
            Remember :ref:`config precedence`
        """
        request = self.make_request('repos.watchers.list',
            user=user, repo=repo)
        return self._get_result(request)

    def list_repos(self, user=None):
        """ Get repositories being watched by a user

        :param str user: Username
        :returns: A :doc:`result`

        If you call it without user and you are authenticated, get the
        repositories being watched by the authenticated user.

        .. warning::
            If you aren't authenticated and call without user, it returns 403

        ::

            watchers_service.list_repos('copitux')
            watchers_service.list_repos()
        """
        request = self.request_builder('repos.watchers.list_repos', user=user)
        return self._get_result(request)

    def is_watching(self, user=None, repo=None):
        """ Check if authenticated user is watching a repository

        :param str user: Username
        :param str repo: Repository

        .. note::
            Remember :ref:`config precedence`

        .. warning::
            You must be authenticated
        """
        request = self.make_request('repos.watchers.is_watching',
            user=user, repo=repo)
        return self._bool(request)

    def watch(self, user=None, repo=None):
        """ Watch a repository

        :param str user: Username
        :param str repo: Repository

        .. note::
            Remember :ref:`config precedence`

        .. warning::
            You must be authenticated
        """
        request = self.make_request('repos.watchers.watch',
            user=user, repo=repo)
        self._put(request)

    def unwatch(self, user=None, repo=None):
        """ Stop watching a repository

        :param str user: Username
        :param str repo: Repository

        .. note::
            Remember :ref:`config precedence`

        .. warning::
            You must be authenticated
        """
        request = self.make_request('repos.watchers.unwatch',
            user=user, repo=repo)
        self._delete(request)