summaryrefslogtreecommitdiff
path: root/gitlab/mixins.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2019-01-14 07:16:43 +0100
committerGauvain Pocentek <gauvain@pocentek.net>2019-01-14 07:30:03 +0100
commitf404d394960683d68ccaf3c129f75a2582a2fb77 (patch)
treed1303b44b3291db3088c9ac978db7c8efc23d0ca /gitlab/mixins.py
parent89679ce5ee502e57dbe7cec2b78f4f70b85fd3a5 (diff)
downloadgitlab-feat/count.tar.gz
[WIP] feat(api): Implement a count() methodfeat/count
Diffstat (limited to 'gitlab/mixins.py')
-rw-r--r--gitlab/mixins.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/gitlab/mixins.py b/gitlab/mixins.py
index ca68658..98c3185 100644
--- a/gitlab/mixins.py
+++ b/gitlab/mixins.py
@@ -136,6 +136,26 @@ class ListMixin(object):
else:
return base.RESTObjectList(self, self._obj_cls, obj)
+ @exc.on_http_error(exc.GitlabListError)
+ def count(self, **kwargs):
+ """Retrieve the number of available objects.
+
+ Args:
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Returns:
+ int: The number of objects
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabCountError: If the server cannot perform the request
+ """
+ # Allow to overwrite the path, handy for custom calls
+ path = kwargs.pop('path', self.path)
+
+ headers = self.gitlab.http_head(path, **kwargs)
+ return int(headers['x-total'])
+
class RetrieveMixin(ListMixin, GetMixin):
pass