summaryrefslogtreecommitdiff
path: root/gitlab/__init__.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2017-05-27 21:45:02 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2017-06-02 15:41:37 +0200
commit993d576ba794a29aacd56a7610e79a331789773d (patch)
tree287b12c668ac0d776e12c3a4f04e8caca5c293ec /gitlab/__init__.py
parentd809fefaf5b382f13f8f9da344320741e553ced1 (diff)
downloadgitlab-993d576ba794a29aacd56a7610e79a331789773d.tar.gz
Rework the manager and object classes
Add new RESTObject and RESTManager base class, linked to a bunch of Mixin class to implement the actual CRUD methods. Object are generated by the managers, and special cases are handled in the derivated classes. Both ways (old and new) can be used together, migrate only a few v4 objects to the new method as a POC. TODO: handle managers on generated objects (have to deal with attributes in the URLs).
Diffstat (limited to 'gitlab/__init__.py')
-rw-r--r--gitlab/__init__.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index dbb7f85..d27fcf7 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -644,9 +644,12 @@ class Gitlab(object):
opts = self._get_session_opts(content_type='application/json')
result = self.session.request(verb, url, json=post_data,
params=params, stream=streamed, **opts)
- if not (200 <= result.status_code < 300):
- raise GitlabHttpError(response_code=result.status_code)
- return result
+ if 200 <= result.status_code < 300:
+ return result
+
+
+ raise GitlabHttpError(response_code=result.status_code,
+ error_message=result.content)
def http_get(self, path, query_data={}, streamed=False, **kwargs):
"""Make a GET request to the Gitlab server.
@@ -748,7 +751,7 @@ class Gitlab(object):
GitlabHttpError: When the return code is not 2xx
GitlabParsingError: IF the json data could not be parsed
"""
- result = self.hhtp_request('put', path, query_data=query_data,
+ result = self.http_request('put', path, query_data=query_data,
post_data=post_data, **kwargs)
try:
return result.json()
@@ -808,6 +811,9 @@ class GitlabList(object):
def __iter__(self):
return self
+ def __len__(self):
+ return self._total_pages
+
def __next__(self):
return self.next()
@@ -819,6 +825,6 @@ class GitlabList(object):
except IndexError:
if self._next_url:
self._query(self._next_url)
- return self._data[self._current]
+ return self.next()
raise StopIteration