aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/index.rst194
-rw-r--r--mastodon/Mastodon.py134
2 files changed, 172 insertions, 156 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 2d61f14..f388182 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1,5 +1,7 @@
1Mastodon.py 1Mastodon.py
2=========== 2===========
3.. py:module:: mastodon
4.. py:class: Mastodon
3 5
4.. code-block:: python 6.. code-block:: python
5 7
@@ -37,14 +39,96 @@ as a single python module. By default, it talks to the
37`Mastodon flagship instance`_, but it can be set to talk to any 39`Mastodon flagship instance`_, but it can be set to talk to any
38node running Mastodon. 40node running Mastodon.
39 41
42Return values
43-------------
44
40Unless otherwise specified, all data is returned as python 45Unless otherwise specified, all data is returned as python
41dictionaries, matching the JSON format used by the API. 46dictionaries, matching the JSON format used by the API.
42For complete documentation on what every function returns,
43check the `Mastodon API docs`_, or just play around a bit - the
44format of the data is generally very easy to understand.
45 47
46.. py:module:: mastodon 48User dicts
47.. py:class: Mastodon 49~~~~~~~~~~
50
51.. code-block:: python
52
53 {
54 'display_name': The user's display name
55 'acct': The user's account name as username@domain (@domain omitted for local users)
56 'following_count': How many people they follow
57 'url': Their URL; usually 'https://mastodon.social/users/<acct>'
58 'statuses_count': How many statuses they have
59 'followers_count': How many followers they have
60 'avatar': URL for their avatar
61 'note': Their bio
62 'header': URL for their header image
63 'id': Same as <numerical id>
64 'username': The username (what you @ them with)
65 }
66
67Toot dicts
68~~~~~~~~~~
69.. code-block:: python
70
71 mastodon.toot("Hello from Python")
72 # Returns the following dictionary:
73 {
74 'sensitive': Denotes whether the toot is marked sensitive
75 'created_at': Creation time
76 'mentions': A list of account dicts mentioned in the toot
77 'uri': Descriptor for the toot
78 EG 'tag:mastodon.social,2016-11-25:objectId=<id>:objectType=Status'
79 'tags': A list of hashtag dicts used in the toot
80 'in_reply_to_id': Numerical id of the toot this toot is in response to
81 'id': Numerical id of this toot
82 'reblogs_count': Number of reblogs
83 'favourites_count': Number of favourites
84 'reblog': Denotes whether the toot is a reblog
85 'url': URL of the toot
86 'content': Content of the toot, as HTML: '<p>Hello from Python</p>'
87 'favourited': Denotes whether the logged in user has favourited this toot
88 'account': Account dict for the logged in account
89 }
90
91Relationship dicts
92~~~~~~~~~~~~~~~~~~
93
94.. code-block:: python
95
96 mastodon.account_follow(<numerical id>)
97 # Returns
98 {
99 'followed_by': Boolean denoting whether they follow you back
100 'following': Boolean denoting whether you follow them
101 'id': Numerical id (same one as <numerical id>)
102 'blocking': Boolean denoting whether you are blocking them
103 }
104
105Context dicts
106~~~~~~~~~~~~~
107
108.. code-block:: python
109
110 mastodon.status_context(<numerical id>)
111 # Returns
112 {
113 'descendants': A list of toot dicts
114 'ancestors': A list of toot dicts
115 }
116
117Media dicts
118~~~~~~~~~~~
119
120.. code-block:: python
121
122 mastodon.media_post("image.jpg", "image/jpeg")
123 # Returns
124 {
125 'text_url': The display text for the media (what shows up in toots)
126 'preview_url': The URL for the media preview
127 'type': Media type, EG 'image'
128 'url': The URL for the media
129 }
130
131
48 132
49App registration and user authentication 133App registration and user authentication
50---------------------------------------- 134----------------------------------------
@@ -81,20 +165,7 @@ Reading data: Statuses
81These functions allow you to get information about single statuses. 165These functions allow you to get information about single statuses.
82 166
83.. automethod:: Mastodon.status 167.. automethod:: Mastodon.status
84
85Returns a single toot dict for the given status.
86
87.. automethod:: Mastodon.status_context 168.. automethod:: Mastodon.status_context
88
89.. code-block:: python
90
91 mastodon.status_context(<numerical id>)
92 # Returns
93 {
94 'descendants': A list of toot dicts
95 'ancestors': A list of toot dicts
96 }
97
98.. automethod:: Mastodon.status_reblogged_by 169.. automethod:: Mastodon.status_reblogged_by
99.. automethod:: Mastodon.status_favourited_by 170.. automethod:: Mastodon.status_favourited_by
100 171
@@ -104,9 +175,6 @@ This function allows you to get information about a users notifications.
104 175
105.. automethod:: Mastodon.notifications 176.. automethod:: Mastodon.notifications
106 177
107Returns a list of toot dicts for toots mentioning the current logged-in user.
108
109
110Reading data: Accounts 178Reading data: Accounts
111---------------------- 179----------------------
112These functions allow you to get information about accounts and 180These functions allow you to get information about accounts and
@@ -114,39 +182,12 @@ their relationships.
114 182
115.. automethod:: Mastodon.account 183.. automethod:: Mastodon.account
116.. automethod:: Mastodon.account_verify_credentials 184.. automethod:: Mastodon.account_verify_credentials
117
118These methods return an account dict:
119
120.. code-block:: python
121
122 mastodon.account(<numerical id>)
123 # Returns
124 {
125 'display_name': The user's display name
126 'acct': The user's account name as username@domain (@domain omitted for local users)
127 'following_count': How many people they follow
128 'url': Their URL; usually 'https://mastodon.social/users/<acct>'
129 'statuses_count': How many statuses they have
130 'followers_count': How many followers they have
131 'avatar': URL for their avatar
132 'note': Their bio
133 'header': URL for their header image
134 'id': Same as <numerical id>
135 'username': The username (what you @ them with)
136 }
137
138.. automethod:: Mastodon.account_statuses 185.. automethod:: Mastodon.account_statuses
139.. automethod:: Mastodon.account_following 186.. automethod:: Mastodon.account_following
140.. automethod:: Mastodon.account_followers 187.. automethod:: Mastodon.account_followers
141.. automethod:: Mastodon.account_relationships 188.. automethod:: Mastodon.account_relationships
142
143See following below for format of relationship dicts.
144
145.. automethod:: Mastodon.account_suggestions
146.. automethod:: Mastodon.account_search 189.. automethod:: Mastodon.account_search
147 190
148Returns a list of user dicts.
149
150Writing data: Statuses 191Writing data: Statuses
151---------------------- 192----------------------
152These functions allow you to post statuses to Mastodon and to 193These functions allow you to post statuses to Mastodon and to
@@ -158,58 +199,13 @@ interact with already posted statuses.
158.. automethod:: Mastodon.status_unreblog 199.. automethod:: Mastodon.status_unreblog
159.. automethod:: Mastodon.status_favourite 200.. automethod:: Mastodon.status_favourite
160.. automethod:: Mastodon.status_unfavourite 201.. automethod:: Mastodon.status_unfavourite
161
162These methods return a toot dict:
163
164.. code-block:: python
165
166 mastodon.toot("Hello from Python")
167 # Returns the following dictionary:
168 {
169 'sensitive': Denotes whether the toot is marked sensitive
170 'created_at': Creation time
171 'mentions': A list of account dicts mentioned in the toot
172 'uri': Descriptor for the toot
173 EG 'tag:mastodon.social,2016-11-25:objectId=<id>:objectType=Status'
174 'tags': A list of hashtag dicts used in the toot
175 'in_reply_to_id': Numerical id of the toot this toot is in response to
176 'id': Numerical id of this toot
177 'reblogs_count': Number of reblogs
178 'favourites_count': Number of favourites
179 'reblog': Denotes whether the toot is a reblog
180 'url': URL of the toot
181 'content': Content of the toot, as HTML: '<p>Hello from Python</p>'
182 'favourited': Denotes whether the logged in user has favourited this toot
183 'account': Account dict for the logged in account
184 }
185
186.. automethod:: Mastodon.status_delete 202.. automethod:: Mastodon.status_delete
187Returns an empty dict:
188
189.. code-block:: python
190
191 mastodon.delete_status(<numerical id>)
192 # Returns
193 {}
194 203
195Writing data: Accounts 204Writing data: Accounts
196---------------------- 205----------------------
197These functions allow you to interact with other accounts: To (un)follow and 206These functions allow you to interact with other accounts: To (un)follow and
198(un)block. 207(un)block.
199 208
200They return a relationship dict:
201
202.. code-block:: python
203
204 mastodon.account_follow(<numerical id>)
205 # Returns
206 {
207 'followed_by': Boolean denoting whether they follow you back
208 'following': Boolean denoting whether you follow them
209 'id': Numerical id (same one as <numerical id>)
210 'blocking': Boolean denoting whether you are blocking them
211 }
212
213.. automethod:: Mastodon.account_follow 209.. automethod:: Mastodon.account_follow
214.. automethod:: Mastodon.account_unfollow 210.. automethod:: Mastodon.account_unfollow
215.. automethod:: Mastodon.account_block 211.. automethod:: Mastodon.account_block
@@ -223,18 +219,6 @@ to attach media to statuses.
223 219
224.. automethod:: Mastodon.media_post 220.. automethod:: Mastodon.media_post
225 221
226Returns a media dict:
227
228.. code-block:: python
229
230 mastodon.media_post("image.jpg", "image/jpeg")
231 # Returns
232 {
233 'text_url': The display text for the media (what shows up in toots)
234 'preview_url': The URL for the media preview
235 'type': Media type, EG 'image'
236 'url': The URL for the media
237 }
238 222
239.. _Mastodon: https://github.com/Gargron/mastodon 223.. _Mastodon: https://github.com/Gargron/mastodon
240.. _Mastodon flagship instance: http://mastodon.social/ 224.. _Mastodon flagship instance: http://mastodon.social/
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 7bd6473..36f20d2 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -27,7 +27,7 @@ class Mastodon:
27 @staticmethod 27 @staticmethod
28 def create_app(client_name, scopes = ['read', 'write', 'follow'], redirect_uris = None, to_file = None, api_base_url = __DEFAULT_BASE_URL): 28 def create_app(client_name, scopes = ['read', 'write', 'follow'], redirect_uris = None, to_file = None, api_base_url = __DEFAULT_BASE_URL):
29 """ 29 """
30 Creates a new app with given client_name and scopes (read, write, follow) 30 Create a new app with given client_name and scopes (read, write, follow)
31 31
32 Specify redirect_uris if you want users to be redirected to a certain page after authenticating. 32 Specify redirect_uris if you want users to be redirected to a certain page after authenticating.
33 Specify to_file to persist your apps info to a file so you can use them in the constructor. 33 Specify to_file to persist your apps info to a file so you can use them in the constructor.
@@ -59,7 +59,7 @@ class Mastodon:
59 ### 59 ###
60 def __init__(self, client_id, client_secret = None, access_token = None, api_base_url = __DEFAULT_BASE_URL, debug_requests = False): 60 def __init__(self, client_id, client_secret = None, access_token = None, api_base_url = __DEFAULT_BASE_URL, debug_requests = False):
61 """ 61 """
62 Creates a new API wrapper instance based on the given client_secret and client_id. If you 62 Create a new API wrapper instance based on the given client_secret and client_id. If you
63 give a client_id and it is not a file, you must also give a secret. 63 give a client_id and it is not a file, you must also give a secret.
64 64
65 You can also directly specify an access_token, directly or as a file. 65 You can also directly specify an access_token, directly or as a file.
@@ -87,7 +87,7 @@ class Mastodon:
87 87
88 def log_in(self, username, password, scopes = ['read', 'write', 'follow'], to_file = None): 88 def log_in(self, username, password, scopes = ['read', 'write', 'follow'], to_file = None):
89 """ 89 """
90 Logs in and sets access_token to what was returned. 90 Log in and set access_token to what was returned.
91 Can persist access token to file. 91 Can persist access token to file.
92 92
93 Will throw an exception if username / password are wrong, scopes are not 93 Will throw an exception if username / password are wrong, scopes are not
@@ -124,35 +124,45 @@ class Mastodon:
124 ## 124 ##
125 def timeline(self, timeline = "home", max_id = None, since_id = None, limit = None): 125 def timeline(self, timeline = "home", max_id = None, since_id = None, limit = None):
126 """ 126 """
127 Returns statuses, most recent ones first. Timeline can be home, mentions, public 127 Fetch statuses, most recent ones first. Timeline can be home, mentions, public
128 or tag/hashtag. See the following functions documentation for what those do. 128 or tag/hashtag. See the following functions documentation for what those do.
129 129
130 The default timeline is the "home" timeline. 130 The default timeline is the "home" timeline.
131
132 Returns a list of toot dicts.
131 """ 133 """
132 params = self.__generate_params(locals(), ['timeline']) 134 params = self.__generate_params(locals(), ['timeline'])
133 return self.__api_request('GET', '/api/v1/timelines/' + timeline, params) 135 return self.__api_request('GET', '/api/v1/timelines/' + timeline, params)
134 136
135 def timeline_home(self, max_id = None, since_id = None, limit = None): 137 def timeline_home(self, max_id = None, since_id = None, limit = None):
136 """ 138 """
137 Returns the authenticated users home timeline (i.e. followed users and self). 139 Fetch the authenticated users home timeline (i.e. followed users and self).
140
141 Returns a list of toot dicts.
138 """ 142 """
139 return self.timeline('home', max_id = max_id, since_id = since_id, limit = limit) 143 return self.timeline('home', max_id = max_id, since_id = since_id, limit = limit)
140 144
141 def timeline_mentions(self, max_id = None, since_id = None, limit = None): 145 def timeline_mentions(self, max_id = None, since_id = None, limit = None):
142 """ 146 """
143 Returns the authenticated users mentions. 147 Fetches the authenticated users mentions.
148
149 Returns a list of toot dicts.
144 """ 150 """
145 return self.timeline('mentions', max_id = max_id, since_id = since_id, limit = limit) 151 return self.timeline('mentions', max_id = max_id, since_id = since_id, limit = limit)
146 152
147 def timeline_public(self, max_id = None, since_id = None, limit = None): 153 def timeline_public(self, max_id = None, since_id = None, limit = None):
148 """ 154 """
149 Returns the public / visible-network timeline. 155 Fetches the public / visible-network timeline.
156
157 Returns a list of toot dicts.
150 """ 158 """
151 return self.timeline('public', max_id = max_id, since_id = since_id, limit = limit) 159 return self.timeline('public', max_id = max_id, since_id = since_id, limit = limit)
152 160
153 def timeline_hashtag(self, hashtag, max_id = None, since_id = None, limit = None): 161 def timeline_hashtag(self, hashtag, max_id = None, since_id = None, limit = None):
154 """ 162 """
155 Returns all toots with a given hashtag. 163 Fetch a timeline of toots with a given hashtag.
164
165 Returns a list of toot dicts.
156 """ 166 """
157 return self.timeline('tag/' + str(hashtag), max_id = max_id, since_id = since_id, limit = limit) 167 return self.timeline('tag/' + str(hashtag), max_id = max_id, since_id = since_id, limit = limit)
158 168
@@ -161,25 +171,33 @@ class Mastodon:
161 ### 171 ###
162 def status(self, id): 172 def status(self, id):
163 """ 173 """
164 Returns a status. 174 Fetch information about a single toot.
175
176 Returns a toot dict.
165 """ 177 """
166 return self.__api_request('GET', '/api/v1/statuses/' + str(id)) 178 return self.__api_request('GET', '/api/v1/statuses/' + str(id))
167 179
168 def status_context(self, id): 180 def status_context(self, id):
169 """ 181 """
170 Returns ancestors and descendants of the status. 182 Fetch information about ancestors and descendants of a toot.
183
184 Returns a context dict.
171 """ 185 """
172 return self.__api_request('GET', '/api/v1/statuses/' + str(id) + '/context') 186 return self.__api_request('GET', '/api/v1/statuses/' + str(id) + '/context')
173 187
174 def status_reblogged_by(self, id): 188 def status_reblogged_by(self, id):
175 """ 189 """
176 Returns a list of users that have reblogged a status. 190 Fetch a list of users that have reblogged a status.
191
192 Returns a list of user dicts.
177 """ 193 """
178 return self.__api_request('GET', '/api/v1/statuses/' + str(id) + '/reblogged_by') 194 return self.__api_request('GET', '/api/v1/statuses/' + str(id) + '/reblogged_by')
179 195
180 def status_favourited_by(self, id): 196 def status_favourited_by(self, id):
181 """ 197 """
182 Returns a list of users that have favourited a status. 198 Fetch a list of users that have favourited a status.
199
200 Returns a list of user dicts.
183 """ 201 """
184 return self.__api_request('GET', '/api/v1/statuses/' + str(id) + '/favourited_by') 202 return self.__api_request('GET', '/api/v1/statuses/' + str(id) + '/favourited_by')
185 203
@@ -188,8 +206,10 @@ class Mastodon:
188 ### 206 ###
189 def notifications(self): 207 def notifications(self):
190 """ 208 """
191 Returns notifications (mentions, favourites, reblogs, follows) for the authenticated 209 Fetch notifications (mentions, favourites, reblogs, follows) for the authenticated
192 user. 210 user.
211
212 Returns: TODO
193 """ 213 """
194 return self.__api_request('GET', '/api/v1/notifications') 214 return self.__api_request('GET', '/api/v1/notifications')
195 215
@@ -198,53 +218,61 @@ class Mastodon:
198 ### 218 ###
199 def account(self, id): 219 def account(self, id):
200 """ 220 """
201 Returns account. 221 Fetch account information by user id.
222
223 Returns a user dict.
202 """ 224 """
203 return self.__api_request('GET', '/api/v1/accounts/' + str(id)) 225 return self.__api_request('GET', '/api/v1/accounts/' + str(id))
204 226
205 def account_verify_credentials(self): 227 def account_verify_credentials(self):
206 """ 228 """
207 Returns authenticated user's account. 229 Fetch authenticated user's account information.
230
231 Returns a user dict.
208 """ 232 """
209 return self.__api_request('GET', '/api/v1/accounts/verify_credentials') 233 return self.__api_request('GET', '/api/v1/accounts/verify_credentials')
210 234
211 def account_statuses(self, id, max_id = None, since_id = None, limit = None): 235 def account_statuses(self, id, max_id = None, since_id = None, limit = None):
212 """ 236 """
213 Returns statuses by user. Same options as timeline are permitted. 237 Fetch statuses by user id. Same options as timeline are permitted.
238
239 Returns a list of toot dicts.
214 """ 240 """
215 params = self.__generate_params(locals(), ['id']) 241 params = self.__generate_params(locals(), ['id'])
216 return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/statuses', params) 242 return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/statuses', params)
217 243
218 def account_following(self, id): 244 def account_following(self, id):
219 """ 245 """
220 Returns users the given user is following. 246 Fetch users the given user is following.
247
248 Returns a list of user dicts.
221 """ 249 """
222 return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/following') 250 return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/following')
223 251
224 def account_followers(self, id): 252 def account_followers(self, id):
225 """ 253 """
226 Returns users the given user is followed by. 254 Fetch users the given user is followed by.
255
256 Returns a list of user dicts.
227 """ 257 """
228 return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/followers') 258 return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/followers')
229 259
230 def account_relationships(self, id): 260 def account_relationships(self, id):
231 """ 261 """
232 Returns relationships (following, followed_by, blocking) of the logged in user to 262 Fetch relationships (following, followed_by, blocking) of the logged in user to
233 a given account. id can be a list. 263 a given account. id can be a list.
264
265 Returns a list of relationship dicts.
234 """ 266 """
235 params = self.__generate_params(locals()) 267 params = self.__generate_params(locals())
236 return self.__api_request('GET', '/api/v1/accounts/relationships', params) 268 return self.__api_request('GET', '/api/v1/accounts/relationships', params)
237
238 def account_suggestions(self):
239 """
240 Returns accounts that the system suggests the authenticated user to follow.
241 """
242 return self.__api_request('GET', '/api/v1/accounts/suggestions')
243 269
244 def account_search(self, q, limit = None): 270 def account_search(self, q, limit = None):
245 """ 271 """
246 Returns matching accounts. Will lookup an account remotely if the search term is 272 Fetch matching accounts. Will lookup an account remotely if the search term is
247 in the username@domain format and not yet in the database. 273 in the username@domain format and not yet in the database.
274
275 Returns a list of user dicts.
248 """ 276 """
249 params = self.__generate_params(locals()) 277 params = self.__generate_params(locals())
250 return self.__api_request('GET', '/api/v1/accounts/search', params) 278 return self.__api_request('GET', '/api/v1/accounts/search', params)
@@ -254,10 +282,10 @@ class Mastodon:
254 ### 282 ###
255 def status_post(self, status, in_reply_to_id = None, media_ids = None): 283 def status_post(self, status, in_reply_to_id = None, media_ids = None):
256 """ 284 """
257 Posts a status. Can optionally be in reply to another status and contain 285 Post a status. Can optionally be in reply to another status and contain
258 up to four pieces of media (Uploaded via media_post()). 286 up to four pieces of media (Uploaded via media_post()).
259 287
260 Returns the new status. 288 Returns a toot dict with the new status.
261 """ 289 """
262 params = self.__generate_params(locals()) 290 params = self.__generate_params(locals())
263 return self.__api_request('POST', '/api/v1/statuses', params) 291 return self.__api_request('POST', '/api/v1/statuses', params)
@@ -265,41 +293,46 @@ class Mastodon:
265 def toot(self, status): 293 def toot(self, status):
266 """ 294 """
267 Synonym for status_post that only takes the status text as input. 295 Synonym for status_post that only takes the status text as input.
296
297 Returns a toot dict with the new status.
268 """ 298 """
269 return self.status_post(status) 299 return self.status_post(status)
270 300
271 def status_delete(self, id): 301 def status_delete(self, id):
272 """ 302 """
273 Deletes a status 303 Delete a status
304
305 Returns an empty dict for good measure.
274 """ 306 """
275 return self.__api_request('DELETE', '/api/v1/statuses/' + str(id)) 307 return self.__api_request('DELETE', '/api/v1/statuses/' + str(id))
276 308
277 def status_reblog(self, id): 309 def status_reblog(self, id):
278 """Reblogs a status. 310 """Reblog a status.
279 311
280 Returns a new status that wraps around the reblogged one.""" 312 Returns a toot with with a new status that wraps around the reblogged one.
313 """
281 return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/reblog") 314 return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/reblog")
282 315
283 def status_unreblog(self, id): 316 def status_unreblog(self, id):
284 """ 317 """
285 Un-reblogs a status. 318 Un-reblog a status.
286 319
287 Returns the status that used to be reblogged. 320 Returns a toot dict with the status that used to be reblogged.
288 """ 321 """
289 return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/unreblog") 322 return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/unreblog")
290 323
291 def status_favourite(self, id): 324 def status_favourite(self, id):
292 """ 325 """
293 Favourites a status. 326 Favourite a status.
294 327
295 Returns the favourited status. 328 Returns a toot dict with the favourited status.
296 """ 329 """
297 return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/favourite") 330 return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/favourite")
298 331
299 def status_unfavourite(self, id): 332 def status_unfavourite(self, id):
300 """Favourites a status. 333 """Favourite a status.
301 334
302 Returns the un-favourited status. 335 Returns a toot dict with the un-favourited status.
303 """ 336 """
304 return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/unfavourite") 337 return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/unfavourite")
305 338
@@ -308,33 +341,33 @@ class Mastodon:
308 ### 341 ###
309 def account_follow(self, id): 342 def account_follow(self, id):
310 """ 343 """
311 Follows a user. 344 Follow a user.
312 345
313 Returns the updated relationship to the user. 346 Returns a relationship dict containing the updated relationship to the user.
314 """ 347 """
315 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/follow") 348 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/follow")
316 349
317 def account_unfollow(self, id): 350 def account_unfollow(self, id):
318 """ 351 """
319 Unfollows a user. 352 Unfollow a user.
320 353
321 Returns the updated relationship to the user. 354 Returns a relationship dict containing the updated relationship to the user.
322 """ 355 """
323 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unfollow") 356 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unfollow")
324 357
325 def account_block(self, id): 358 def account_block(self, id):
326 """ 359 """
327 Blocks a user. 360 Block a user.
328 361
329 Returns the updated relationship to the user. 362 Returns a relationship dict containing the updated relationship to the user.
330 """ 363 """
331 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/block") 364 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/block")
332 365
333 def account_unblock(self, id): 366 def account_unblock(self, id):
334 """ 367 """
335 Unblocks a user. 368 Unblock a user.
336 369
337 Returns the updated relationship to the user. 370 Returns a relationship dict containing the updated relationship to the user.
338 """ 371 """
339 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unblock") 372 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unblock")
340 373
@@ -343,20 +376,19 @@ class Mastodon:
343 ### 376 ###
344 def media_post(self, media_file, mime_type = None): 377 def media_post(self, media_file, mime_type = None):
345 """ 378 """
346 Posts an image. media_file can either be image data or 379 Post an image. media_file can either be image data or
347 a file name. If image data is passed directly, the mime 380 a file name. If image data is passed directly, the mime
348 type has to be specified manually, otherwise, it is 381 type has to be specified manually, otherwise, it is
349 determined from the file name. 382 determined from the file name.
350 383
351 Returns the uploaded media metadata object. Importantly, this contains
352 the ID that can then be used in status_post() to attach the media to
353 a toot.
354
355 Throws a ValueError if the mime type of the passed data or file can 384 Throws a ValueError if the mime type of the passed data or file can
356 not be determined properly. 385 not be determined properly.
386
387 Returns a media dict. This contains the id that can be used in
388 status_post to attach the media file to a toot.
357 """ 389 """
358 390
359 if os.path.isfile(media_file): 391 if os.path.isfile(media_file) and mime_type == None:
360 mime_type = mimetypes.guess_type(media_file)[0] 392 mime_type = mimetypes.guess_type(media_file)[0]
361 media_file = open(media_file, 'rb') 393 media_file = open(media_file, 'rb')
362 394
Powered by cgit v1.2.3 (git 2.41.0)