diff options
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index df90a57..17f059f 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -7,6 +7,7 @@ import time | |||
7 | import random | 7 | import random |
8 | import string | 8 | import string |
9 | import datetime | 9 | import datetime |
10 | import collections | ||
10 | from contextlib import closing | 11 | from contextlib import closing |
11 | import pytz | 12 | import pytz |
12 | import requests | 13 | import requests |
@@ -104,13 +105,13 @@ class Mastodon: | |||
104 | __DEFAULT_TIMEOUT = 300 | 105 | __DEFAULT_TIMEOUT = 300 |
105 | __DEFAULT_STREAM_TIMEOUT = 300 | 106 | __DEFAULT_STREAM_TIMEOUT = 300 |
106 | __DEFAULT_STREAM_RECONNECT_WAIT_SEC = 5 | 107 | __DEFAULT_STREAM_RECONNECT_WAIT_SEC = 5 |
107 | __SUPPORTED_MASTODON_VERSION = "2.3.0" | 108 | __SUPPORTED_MASTODON_VERSION = "2.4.0" |
108 | 109 | ||
109 | # Dict versions | 110 | # Dict versions |
110 | __DICT_VERSION_APPLICATION = "1.0.0" | 111 | __DICT_VERSION_APPLICATION = "1.0.0" |
111 | __DICT_VERSION_MENTION = "1.0.0" | 112 | __DICT_VERSION_MENTION = "1.0.0" |
112 | __DICT_VERSION_MEDIA = "2.3.0" | 113 | __DICT_VERSION_MEDIA = "2.3.0" |
113 | __DICT_VERSION_ACCOUNT = "2.3.0" | 114 | __DICT_VERSION_ACCOUNT = "2.4.0" |
114 | __DICT_VERSION_STATUS = bigger_version(bigger_version(bigger_version(bigger_version("2.1.0", | 115 | __DICT_VERSION_STATUS = bigger_version(bigger_version(bigger_version(bigger_version("2.1.0", |
115 | __DICT_VERSION_MEDIA), __DICT_VERSION_ACCOUNT), __DICT_VERSION_APPLICATION), __DICT_VERSION_MENTION) | 116 | __DICT_VERSION_MEDIA), __DICT_VERSION_ACCOUNT), __DICT_VERSION_APPLICATION), __DICT_VERSION_MENTION) |
116 | __DICT_VERSION_INSTANCE = bigger_version("2.3.0", __DICT_VERSION_ACCOUNT) | 117 | __DICT_VERSION_INSTANCE = bigger_version("2.3.0", __DICT_VERSION_ACCOUNT) |
@@ -1239,10 +1240,11 @@ class Mastodon: | |||
1239 | url = '/api/v1/accounts/{0}/unmute'.format(str(id)) | 1240 | url = '/api/v1/accounts/{0}/unmute'.format(str(id)) |
1240 | return self.__api_request('POST', url) | 1241 | return self.__api_request('POST', url) |
1241 | 1242 | ||
1242 | @api_version("1.1.1", "2.3.0", __DICT_VERSION_ACCOUNT) | 1243 | @api_version("1.1.1", "2.4.0", __DICT_VERSION_ACCOUNT) |
1243 | def account_update_credentials(self, display_name=None, note=None, | 1244 | def account_update_credentials(self, display_name=None, note=None, |
1244 | avatar=None, avatar_mime_type=None, | 1245 | avatar=None, avatar_mime_type=None, |
1245 | header=None, header_mime_type=None, locked=None): | 1246 | header=None, header_mime_type=None, |
1247 | locked=None, fields=None): | ||
1246 | """ | 1248 | """ |
1247 | Update the profile for the currently logged-in user. | 1249 | Update the profile for the currently logged-in user. |
1248 | 1250 | ||
@@ -1253,9 +1255,12 @@ class Mastodon: | |||
1253 | 1255 | ||
1254 | 'locked' specifies whether the user needs to manually approve follow requests. | 1256 | 'locked' specifies whether the user needs to manually approve follow requests. |
1255 | 1257 | ||
1258 | 'fields' can be a list of up to four name-value pairs (specified as tuples) to | ||
1259 | appear as semi-structured information in the users profile. | ||
1260 | |||
1256 | Returns the updated `user dict` of the logged-in user. | 1261 | Returns the updated `user dict` of the logged-in user. |
1257 | """ | 1262 | """ |
1258 | params_initial = locals() | 1263 | params_initial = collections.OrderedDict(locals()) |
1259 | 1264 | ||
1260 | # Load avatar, if specified | 1265 | # Load avatar, if specified |
1261 | if not avatar is None: | 1266 | if not avatar is None: |
@@ -1275,8 +1280,18 @@ class Mastodon: | |||
1275 | if header_mime_type is None: | 1280 | if header_mime_type is None: |
1276 | raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.') | 1281 | raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.') |
1277 | 1282 | ||
1283 | # Convert fields | ||
1284 | if fields != None: | ||
1285 | if len(fields) > 4: | ||
1286 | raise MastodonIllegalArgumentError('A maximum of four fields are allowed.') | ||
1287 | |||
1288 | fields_attributes = [] | ||
1289 | for idx, (field_name, field_value) in enumerate(fields): | ||
1290 | params_initial['fields_attributes[' + str(idx) + '][name]'] = field_name | ||
1291 | params_initial['fields_attributes[' + str(idx) + '][value]'] = field_value | ||
1292 | |||
1278 | # Clean up params | 1293 | # Clean up params |
1279 | for param in ["avatar", "avatar_mime_type", "header", "header_mime_type"]: | 1294 | for param in ["avatar", "avatar_mime_type", "header", "header_mime_type", "fields"]: |
1280 | if param in params_initial: | 1295 | if param in params_initial: |
1281 | del params_initial[param] | 1296 | del params_initial[param] |
1282 | 1297 | ||