aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon/instance.py')
-rw-r--r--mastodon/instance.py97
1 files changed, 95 insertions, 2 deletions
diff --git a/mastodon/instance.py b/mastodon/instance.py
index 88445d1..dfbbefb 100644
--- a/mastodon/instance.py
+++ b/mastodon/instance.py
@@ -1,5 +1,7 @@
1from .versions import _DICT_VERSION_INSTANCE, _DICT_VERSION_ACTIVITY 1# instance.py - instance-level endpoints, directory, emoji, announcements
2from .error import MastodonIllegalArgumentError, MastodonNotFoundError 2
3from .versions import _DICT_VERSION_INSTANCE, _DICT_VERSION_ACTIVITY, _DICT_VERSION_ACCOUNT, _DICT_VERSION_EMOJI, _DICT_VERSION_ANNOUNCEMENT
4from .errors import MastodonIllegalArgumentError, MastodonNotFoundError
3from .utility import api_version 5from .utility import api_version
4from .compat import urlparse 6from .compat import urlparse
5 7
@@ -94,3 +96,94 @@ class Mastodon(Internals):
94 Returns a list of `id` + `text` dicts, same as the `rules` field in the :ref:`instance dicts <instance dicts>`. 96 Returns a list of `id` + `text` dicts, same as the `rules` field in the :ref:`instance dicts <instance dicts>`.
95 """ 97 """
96 return self.__api_request('GET', '/api/v1/instance/rules') 98 return self.__api_request('GET', '/api/v1/instance/rules')
99
100 ###
101 # Reading data: Directory
102 ###
103 @api_version("3.0.0", "3.0.0", _DICT_VERSION_ACCOUNT)
104 def directory(self, offset=None, limit=None, order=None, local=None):
105 """
106 Fetch the contents of the profile directory, if enabled on the server.
107
108 `offset` how many accounts to skip before returning results. Default 0.
109
110 `limit` how many accounts to load. Default 40.
111
112 `order` "active" to sort by most recently posted statuses (default) or
113 "new" to sort by most recently created profiles.
114
115 `local` True to return only local accounts.
116
117 Returns a list of :ref:`account dicts <account dicts>`.
118
119 """
120 params = self.__generate_params(locals())
121 return self.__api_request('GET', '/api/v1/directory', params)
122
123 ###
124 # Reading data: Emoji
125 ###
126 @api_version("2.1.0", "2.1.0", _DICT_VERSION_EMOJI)
127 def custom_emojis(self):
128 """
129 Fetch the list of custom emoji the instance has installed.
130
131 Does not require authentication unless locked down by the administrator.
132
133 Returns a list of :ref:`emoji dicts <emoji dicts>`.
134 """
135 return self.__api_request('GET', '/api/v1/custom_emojis')
136
137 ##
138 # Reading data: Announcements
139 ##
140 @api_version("3.1.0", "3.1.0", _DICT_VERSION_ANNOUNCEMENT)
141 def announcements(self):
142 """
143 Fetch currently active announcements.
144
145 Returns a list of :ref:`announcement dicts <announcement dicts>`.
146 """
147 return self.__api_request('GET', '/api/v1/announcements')
148
149 ###
150 # Writing data: Annoucements
151 ###
152 @api_version("3.1.0", "3.1.0", "3.1.0")
153 def announcement_dismiss(self, id):
154 """
155 Set the given annoucement to read.
156 """
157 id = self.__unpack_id(id)
158
159 url = '/api/v1/announcements/{0}/dismiss'.format(str(id))
160 self.__api_request('POST', url)
161
162 @api_version("3.1.0", "3.1.0", "3.1.0")
163 def announcement_reaction_create(self, id, reaction):
164 """
165 Add a reaction to an announcement. `reaction` can either be a unicode emoji
166 or the name of one of the instances custom emoji.
167
168 Will throw an API error if the reaction name is not one of the allowed things
169 or when trying to add a reaction that the user has already added (adding a
170 reaction that a different user added is legal and increments the count).
171 """
172 id = self.__unpack_id(id)
173
174 url = '/api/v1/announcements/{0}/reactions/{1}'.format(
175 str(id), reaction)
176 self.__api_request('PUT', url)
177
178 @api_version("3.1.0", "3.1.0", "3.1.0")
179 def announcement_reaction_delete(self, id, reaction):
180 """
181 Remove a reaction to an announcement.
182
183 Will throw an API error if the reaction does not exist.
184 """
185 id = self.__unpack_id(id)
186
187 url = '/api/v1/announcements/{0}/reactions/{1}'.format(
188 str(id), reaction)
189 self.__api_request('DELETE', url)
Powered by cgit v1.2.3 (git 2.41.0)