From d4ad626ec0a9e93e611b9e39f8a58b0fa070af21 Mon Sep 17 00:00:00 2001 From: Julien Langlois Date: Wed, 6 Dec 2023 13:27:50 -0800 Subject: [PATCH 1/2] Add methods for the user_subscriptions_read and user_subscriptions_create API end points --- shotgun_api3/shotgun.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index e0af1cf4..5d01229c 100644 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -3261,6 +3261,42 @@ def preferences_read(self, prefs=None): return self._call_rpc("preferences_read", {"prefs": prefs}) + def user_subscriptions_read(self): + """ + Get the list of user subscriptions. + + :returns: A list of user subscriptions where each subscription is a + dictionary containing the ``humanUserId`` and ``subscription`` + fields. + :rtype: list + """ + + return self._call_rpc("user_subscriptions_read", None) + + def user_subscriptions_create(self, users: list): + """ + Assign subscriptions to users. + + :param list users: list of user subscriptions to assign. + Each subscription must be a dictionary with the ``humanUserId`` and + ``subscription`` fields. + The ``subscription`` is either ``None``, a single string, or an + array of strings with subscription info that the user. + + :returns: ``True`` if the request succedeed, ``False`` otherwise. + :rtype: bool + """ + + response = self._call_rpc( + "user_subscriptions_create", + {"users": users} + ) + + if not isinstance(response, dict): + return False + + return response.get("status") == "success" + def _build_opener(self, handler): """ Build urllib2 opener with appropriate proxy handler. From d51facf2256c6903f64f60c4c63b1cf783db0011 Mon Sep 17 00:00:00 2001 From: Julien Langlois <16244608+julien-lang@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:28:56 -0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Shayna Duguid --- shotgun_api3/shotgun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index 5d01229c..50439f2a 100644 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -3281,9 +3281,9 @@ def user_subscriptions_create(self, users: list): Each subscription must be a dictionary with the ``humanUserId`` and ``subscription`` fields. The ``subscription`` is either ``None``, a single string, or an - array of strings with subscription info that the user. + array of strings with subscription information. - :returns: ``True`` if the request succedeed, ``False`` otherwise. + :returns: ``True`` if the request succedeed, ``False`` if otherwise. :rtype: bool """