Compare commits

...

8 Commits

Author SHA1 Message Date
Ben Lopatin 227c3fb469 Bump version and add changelog 2022-07-28 20:09:22 -04:00
Ben Lopatin 0378a38d87 Merge pull request #65 from Natureshadow/add-group-owners
Add group owners
2022-07-28 20:04:58 -04:00
Ben Lopatin 5c12e06e58 Merge pull request #62 from Natureshadow/fix-429-not-json
Handle HTTP 429 errors that are not JSON-encoded
2022-07-28 20:04:43 -04:00
Ben Lopatin 27363e5fa7 Merge pull request #63 from Natureshadow/fix-add-group-owner
Use new API for add_group_owner
2022-07-28 20:03:10 -04:00
Dominik George 8be16c34ff Allow adding multiple group owners by list 2022-07-28 22:26:38 +02:00
Dominik George 8971629bcb Use new API for add_group_owner
Closes #61
2022-07-28 22:22:03 +02:00
Dominik George 7e237c6b68 Handle HTTP 429 errors that are not JSON-encoded
Closes #60
2022-07-28 22:19:11 +02:00
Ben Lopatin 062904fd2a Fix URL
Must not have quotes...
2022-04-18 14:15:56 -04:00
5 changed files with 38 additions and 8 deletions
+1
View File
@@ -12,3 +12,4 @@ Karl Goetz
Alex Kerney
Gustav <https://github.com/dkgv>
Sebastian2023 <https://github.com/Sebastian2023>
Dominik George <https://github.com/Natureshadow>
+7
View File
@@ -3,6 +3,13 @@
Release history
===============
1.3.0
-----
- Add fix for handling global Discourse timeouts
- Add group owners
- Update API for add_group_owner
1.2.0
-----
+1 -1
View File
@@ -4,7 +4,7 @@ version = attr: pydiscourse.__version__
author = "Marc Sibson and contributors"
author_email = "ben@benlopatin.com"
license = "MIT"
url = "https://github.com/bennylope/pydiscourse"
url = https://github.com/bennylope/pydiscourse
description = "A Python library for the Discourse API"
long_description = file: README.rst, HISTORY.rst
platforms =
+1 -1
View File
@@ -2,7 +2,7 @@
"""Python client for the Discourse API."""
__version__ = "1.2.0"
__version__ = "1.3.0"
from pydiscourse.client import DiscourseClient
+28 -6
View File
@@ -1119,7 +1119,24 @@ class DiscourseClient(object):
"""
return self._put(
"/admin/groups/{0}/owners.json".format(groupid), usernames=username
"/admin/groups/{0}/owners.json".format(groupid), **{"group[usernames]": username}
)
def add_group_owners(self, groupid, usernames):
"""
Add a list of owners to a group by usernames
Args:
groupid: the ID of the group
username: the list of new owner usernames
Returns:
JSON API response
"""
usernames = ",".join(usernames)
return self._put(
"/admin/groups/{0}/owners.json".format(groupid), **{"group[usernames]": usernames}
)
def delete_group_owner(self, groupid, userid):
@@ -1544,10 +1561,15 @@ class DiscourseClient(object):
if 400 <= response.status_code < 500:
if 429 == response.status_code:
# This codepath relies on wait_seconds from Discourse v2.0.0.beta3 / v1.9.3 or higher.
rj = response.json()
wait_delay = (
retry_backoff + rj["extras"]["wait_seconds"]
) # how long to back off for.
if "application/json" in response.headers.get("Content-Type"):
ret = response.json()
wait_delay = (
retry_backoff + ret["extras"]["wait_seconds"]
) # how long to back off for.
else:
# We got an early 429 error without a proper JSON body
ret = response.content
wait_delay = retry_backoff + 10
if retry_count > 1:
time.sleep(wait_delay)
@@ -1557,7 +1579,7 @@ class DiscourseClient(object):
wait_delay, retry_count
)
)
log.debug("API returned {0}".format(rj))
log.debug("API returned {0}".format(ret))
continue
else:
raise DiscourseClientError(msg, response=response)