aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2020-02-29 18:48:01 +0100
committerLorenz Diener <[email protected]>2020-02-29 18:48:01 +0100
commitefb1ebb8ce8a3a99732012ae53da89d836c712bf (patch)
treedb8bbcdaba7ce95a5928bc7f36ea4305d1c37bdc /mastodon/Mastodon.py
parent7994a857db80134ac562dcd22c323306f698321d (diff)
downloadmastodon.py-efb1ebb8ce8a3a99732012ae53da89d836c712bf.tar.gz
Add reaction support
Diffstat (limited to 'mastodon/Mastodon.py')
-rw-r--r--mastodon/Mastodon.py95
1 files changed, 76 insertions, 19 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 5b676f3..a6ed111 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -216,6 +216,8 @@ class Mastodon:
216 __DICT_VERSION_ADMIN_ACCOUNT = bigger_version("2.9.1", __DICT_VERSION_ACCOUNT) 216 __DICT_VERSION_ADMIN_ACCOUNT = bigger_version("2.9.1", __DICT_VERSION_ACCOUNT)
217 __DICT_VERSION_FEATURED_TAG = "3.0.0" 217 __DICT_VERSION_FEATURED_TAG = "3.0.0"
218 __DICT_VERSION_MARKER = "3.0.0" 218 __DICT_VERSION_MARKER = "3.0.0"
219 __DICT_VERSION_REACTION = "3.1.0"
220 __DICT_VERSION_ANNOUNCEMENT = bigger_version("3.1.0", __DICT_VERSION_REACTION)
219 221
220 ### 222 ###
221 # Registering apps 223 # Registering apps
@@ -361,23 +363,6 @@ class Mastodon:
361 if not self.feature_set in ["mainline", "fedibird", "pleroma"]: 363 if not self.feature_set in ["mainline", "fedibird", "pleroma"]:
362 raise MastodonIllegalArgumentError('Requested invalid feature set') 364 raise MastodonIllegalArgumentError('Requested invalid feature set')
363 365
364 # Versioning
365 if mastodon_version == None:
366 self.retrieve_mastodon_version()
367 else:
368 try:
369 self.mastodon_major, self.mastodon_minor, self.mastodon_patch = parse_version_string(mastodon_version)
370 except:
371 raise MastodonVersionError("Bad version specified")
372
373 if not version_check_mode in ["created", "changed", "none"]:
374 raise MastodonIllegalArgumentError("Invalid version check method.")
375 self.version_check_mode = version_check_mode
376
377 # Ratelimiting parameter check
378 if ratelimit_method not in ["throw", "wait", "pace"]:
379 raise MastodonIllegalArgumentError("Invalid ratelimit method.")
380
381 # Token loading 366 # Token loading
382 if self.client_id is not None: 367 if self.client_id is not None:
383 if os.path.isfile(self.client_id): 368 if os.path.isfile(self.client_id):
@@ -405,7 +390,25 @@ class Mastodon:
405 if not (self.api_base_url is None or try_base_url == self.api_base_url): 390 if not (self.api_base_url is None or try_base_url == self.api_base_url):
406 raise MastodonIllegalArgumentError('Mismatch in base URLs between files and/or specified') 391 raise MastodonIllegalArgumentError('Mismatch in base URLs between files and/or specified')
407 self.api_base_url = try_base_url 392 self.api_base_url = try_base_url
408 393
394 # Versioning
395 if mastodon_version == None:
396 self.retrieve_mastodon_version()
397 else:
398 try:
399 self.mastodon_major, self.mastodon_minor, self.mastodon_patch = parse_version_string(mastodon_version)
400 except:
401 raise MastodonVersionError("Bad version specified")
402
403 if not version_check_mode in ["created", "changed", "none"]:
404 raise MastodonIllegalArgumentError("Invalid version check method.")
405 self.version_check_mode = version_check_mode
406
407 # Ratelimiting parameter check
408 if ratelimit_method not in ["throw", "wait", "pace"]:
409 raise MastodonIllegalArgumentError("Invalid ratelimit method.")
410
411
409 def retrieve_mastodon_version(self): 412 def retrieve_mastodon_version(self):
410 """ 413 """
411 Determine installed mastodon version and set major, minor and patch (not including RC info) accordingly. 414 Determine installed mastodon version and set major, minor and patch (not including RC info) accordingly.
@@ -1594,6 +1597,20 @@ class Mastodon:
1594 return self.__api_request('GET', '/api/v1/preferences') 1597 return self.__api_request('GET', '/api/v1/preferences')
1595 1598
1596 ## 1599 ##
1600 # Reading data: Announcements
1601 ##
1602
1603 #/api/v1/announcements
1604 @api_version("3.1.0", "3.1.0", __DICT_VERSION_ANNOUNCEMENT)
1605 def announcements(self):
1606 """
1607 Fetch currently active annoucements.
1608
1609 Returns a list of `annoucement dicts`_.
1610 """
1611 return self.__api_request('GET', '/api/v1/announcements')
1612
1613 ##
1597 # Reading data: Read markers 1614 # Reading data: Read markers
1598 ## 1615 ##
1599 @api_version("3.0.0", "3.0.0", __DICT_VERSION_MARKER) 1616 @api_version("3.0.0", "3.0.0", __DICT_VERSION_MARKER)
@@ -2643,7 +2660,47 @@ class Mastodon:
2643 Remove the current push subscription the logged-in user has for this app. 2660 Remove the current push subscription the logged-in user has for this app.
2644 """ 2661 """
2645 self.__api_request('DELETE', '/api/v1/push/subscription') 2662 self.__api_request('DELETE', '/api/v1/push/subscription')
2663
2664 ###
2665 # Writing data: Annoucements
2666 ###
2667 @api_version("3.1.0", "3.1.0", "3.1.0")
2668 def announcement_dismiss(self, id):
2669 """
2670 Set the given annoucement to read.
2671 """
2672 id = self.__unpack_id(id)
2673
2674 url = '/api/v1/announcements/{0}/dismiss'.format(str(id))
2675 self.__api_request('POST', url)
2676
2677 @api_version("3.1.0", "3.1.0", "3.1.0")
2678 def announcement_reaction_create(self, id, reaction):
2679 """
2680 Add a reaction to an announcement. `reaction` can either be a unicode emoji
2681 or the name of one of the instances custom emoji.
2682
2683 Will throw an API error if the reaction name is not one of the allowed things
2684 or when trying to add a reaction that the user has already added (adding a
2685 reaction that a different user added is legal and increments the count).
2686 """
2687 id = self.__unpack_id(id)
2688
2689 url = '/api/v1/announcements/{0}/reactions/{1}'.format(str(id), reaction)
2690 self.__api_request('PUT', url)
2646 2691
2692 @api_version("3.1.0", "3.1.0", "3.1.0")
2693 def announcement_reaction_delete(self, id, reaction):
2694 """
2695 Remove a reaction to an announcement.
2696
2697 Will throw an API error if the reaction does not exist.
2698 """
2699 id = self.__unpack_id(id)
2700
2701 url = '/api/v1/announcements/{0}/reactions/{1}'.format(str(id), reaction)
2702 self.__api_request('DELETE', url)
2703
2647 ### 2704 ###
2648 # Moderation API 2705 # Moderation API
2649 ### 2706 ###
@@ -3151,7 +3208,7 @@ class Mastodon:
3151 """ 3208 """
3152 Parse dates in certain known json fields, if possible. 3209 Parse dates in certain known json fields, if possible.
3153 """ 3210 """
3154 known_date_fields = ["created_at", "week", "day", "expires_at", "scheduled_at", "updated_at", "last_status_at"] 3211 known_date_fields = ["created_at", "week", "day", "expires_at", "scheduled_at", "updated_at", "last_status_at", "starts_at", "ends_at", "published_at"]
3155 for k, v in json_object.items(): 3212 for k, v in json_object.items():
3156 if k in known_date_fields: 3213 if k in known_date_fields:
3157 if v != None: 3214 if v != None:
Powered by cgit v1.2.3 (git 2.41.0)