aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2018-06-05 01:54:12 +0200
committerLorenz Diener <[email protected]>2018-06-05 01:54:12 +0200
commit85ca59993582ea54ac5843671d755e5337a2d599 (patch)
tree9af28f03146e266f2b00f835ef0205a4e78d8393 /mastodon
parent465981ea9a5e56e6a8b2cebcc6102849e5bc5acf (diff)
downloadmastodon.py-85ca59993582ea54ac5843671d755e5337a2d599.tar.gz
Add fields support, tests
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py27
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
7import random 7import random
8import string 8import string
9import datetime 9import datetime
10import collections
10from contextlib import closing 11from contextlib import closing
11import pytz 12import pytz
12import requests 13import 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
Powered by cgit v1.2.3 (git 2.41.0)