File: relationships.py

package info (click to toggle)
python-mastodon 2.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,836 kB
  • sloc: python: 9,438; makefile: 206; sql: 98; sh: 27
file content (93 lines) | stat: -rw-r--r-- 3,841 bytes parent folder | download | duplicates (2)
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
92
93
# relationships.py - endpoints for user and domain blocks and mutes as well as follow requests

from mastodon.utility import api_version

from mastodon.internals import Mastodon as Internals
from mastodon.return_types import Account, Relationship, PaginatableList, IdType
from typing import Optional, Union

class Mastodon(Internals):
    ###
    # Reading data: Mutes and Blocks
    ###
    @api_version("1.1.0", "2.6.0")
    def mutes(self, max_id: Optional[IdType] = None, min_id: Optional[IdType] = None, since_id: 
              Optional[IdType] = None, limit: Optional[int] = None) -> PaginatableList[Account]:
        """
        Fetch a list of users muted by the logged-in user.
        """
        params = self.__generate_params(locals())
        return self.__api_request('GET', '/api/v1/mutes', params)

    @api_version("1.0.0", "2.6.0")
    def blocks(self, max_id: Optional[IdType] = None, min_id: Optional[IdType] = None, since_id: 
              Optional[IdType] = None, limit: Optional[int] = None) -> PaginatableList[Account]:
        """
        Fetch a list of users blocked by the logged-in user.
        """
        params = self.__generate_params(locals())
        return self.__api_request('GET', '/api/v1/blocks', params)

    ###
    # Reading data: Follow requests
    ###
    @api_version("1.0.0", "2.6.0")
    def follow_requests(self, max_id: Optional[IdType] = None, min_id: Optional[IdType] = None, since_id: 
              Optional[IdType] = None, limit: Optional[int] = None) -> PaginatableList[Account]:
        """
        Fetch the logged-in user's incoming follow requests.
        """
        params = self.__generate_params(locals())
        return self.__api_request('GET', '/api/v1/follow_requests', params)

    ###
    # Reading data: Domain blocks
    ###
    @api_version("1.4.0", "2.6.0")
    def domain_blocks(self, max_id: Optional[IdType] = None, min_id: Optional[IdType] = None, since_id: 
              Optional[IdType] = None, limit: Optional[int] = None) -> PaginatableList[str]:
        """
        Fetch the logged-in user's blocked domains.

        Returns a list of blocked domain URLs (as strings, without protocol specifier).
        """
        params = self.__generate_params(locals())
        return self.__api_request('GET', '/api/v1/domain_blocks', params)

    ###
    # Writing data: Follow requests
    ###
    @api_version("1.0.0", "3.0.0")
    def follow_request_authorize(self, id: Union[Account, IdType]) -> Relationship:
        """
        Accept an incoming follow request from the given Account and returns the updated Relationship.
        """
        id = self.__unpack_id(id)
        return self.__api_request('POST', f'/api/v1/follow_requests/{id}/authorize')

    @api_version("1.0.0", "3.0.0")
    def follow_request_reject(self, id: Union[Account, IdType]) -> Relationship:
        """
        Reject an incoming follow request from the given Account and returns the updated Relationship.
        """
        id = self.__unpack_id(id)
        return self.__api_request('POST', f'/api/v1/follow_requests/{id}/reject')

    ###
    # Writing data: Domain blocks
    ###
    @api_version("1.4.0", "1.4.0")
    def domain_block(self, domain: str):
        """
        Add a block for all statuses originating from the specified domain for the logged-in user.
        """
        params = self.__generate_params(locals())
        self.__api_request('POST', '/api/v1/domain_blocks', params)

    @api_version("1.4.0", "1.4.0")
    def domain_unblock(self, domain: str):
        """
        Remove a domain block for the logged-in user.
        """
        params = self.__generate_params(locals())
        self.__api_request('DELETE', '/api/v1/domain_blocks', params)