summaryrefslogtreecommitdiff
path: root/gitlab/mixins.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2017-11-11 15:40:13 +0100
committerGauvain Pocentek <gauvain@pocentek.net>2017-11-11 15:40:13 +0100
commita1b097ce1811d320322a225d22183c36125b4a3c (patch)
tree89cfa2801fb806fcf592a72a3552a40c495307e7 /gitlab/mixins.py
parent397d67745f573f1d6bcf9399e3ee602640b019c8 (diff)
downloadgitlab-a1b097ce1811d320322a225d22183c36125b4a3c.tar.gz
Add a SetMixin
Use it for UserCustomAttribute, will be useful for {Project,Group}CustomAttribute (#367)
Diffstat (limited to 'gitlab/mixins.py')
-rw-r--r--gitlab/mixins.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/gitlab/mixins.py b/gitlab/mixins.py
index d017152..3d6e321 100644
--- a/gitlab/mixins.py
+++ b/gitlab/mixins.py
@@ -222,6 +222,29 @@ class UpdateMixin(object):
return self.gitlab.http_put(path, post_data=data, **kwargs)
+class SetMixin(object):
+ @exc.on_http_error(exc.GitlabSetError)
+ def set(self, key, value, **kwargs):
+ """Create or update the object.
+
+ Args:
+ key (str): The key of the object to create/update
+ value (str): The value to set for the object
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabSetError: If an error occured
+
+ Returns:
+ UserCustomAttribute: The created/updated user attribute
+ """
+ path = '%s/%s' % (self.path, key.replace('/', '%2F'))
+ data = {'value': value}
+ server_data = self.gitlab.http_put(path, post_data=data, **kwargs)
+ return self._obj_cls(self, server_data)
+
+
class DeleteMixin(object):
@exc.on_http_error(exc.GitlabDeleteError)
def delete(self, id, **kwargs):