summaryrefslogtreecommitdiff
path: root/gitlab.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2014-10-14 18:34:19 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2014-10-14 18:34:19 +0200
commit221f41806d0dad67adada158a9352aa9e2f2036f (patch)
tree53abf0d5a6d57f1c09b16609a6d35a2f23b58ee0 /gitlab.py
parent9736e0b0893e298712d1ad356e3f8341852ef0f7 (diff)
parente14e3bf0f675c54930af53c832ccd7ab98df89f3 (diff)
downloadgitlab-221f41806d0dad67adada158a9352aa9e2f2036f.tar.gz
Merge pull request #42 from mjmaenpaa/constructUrl
Moved url-construction to separate function
Diffstat (limited to 'gitlab.py')
-rw-r--r--gitlab.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/gitlab.py b/gitlab.py
index c6cb6d7..43ba543 100644
--- a/gitlab.py
+++ b/gitlab.py
@@ -126,6 +126,15 @@ class Gitlab(object):
"""Updates the gitlab URL"""
self._url = '%s/api/v3' % url
+ def constructUrl(self, id_, obj, parameters):
+ args = _sanitize_dict(parameters)
+ url = obj._url % args
+ if id_ is not None:
+ url = '%s%s/%s' % (self._url, url, str(id_))
+ else:
+ url = '%s%s' % (self._url, url)
+ return url
+
def setToken(self, token):
"""Sets the private token for authentication"""
self.private_token = token if token else None
@@ -195,9 +204,8 @@ class Gitlab(object):
raise GitlabListError('Missing attribute(s): %s' %
", ".join(missing))
+ url = self.constructUrl(id_=None, obj=obj_class, parameters=kwargs)
args = _sanitize_dict(kwargs)
- url = obj_class._url % args
- url = '%s%s' % (self._url, url)
if args:
url += "?%s" % ("&".join(
["%s=%s" % (k, v) for k, v in args.items()]))
@@ -235,11 +243,7 @@ class Gitlab(object):
raise GitlabGetError('Missing attribute(s): %s' %
", ".join(missing))
- url = obj_class._url % _sanitize_dict(kwargs)
- if id is not None:
- url = '%s%s/%s' % (self._url, url, str(id))
- else:
- url = '%s%s' % (self._url, url)
+ url = self.constructUrl(id_=id, obj=obj_class, parameters=kwargs)
try:
r = requests.get(url, headers=self.headers, verify=self.ssl_verify,
@@ -258,9 +262,7 @@ class Gitlab(object):
raise GitlabGetError('%d: %s' % (r.status_code, r.text))
def delete(self, obj):
- args = _sanitize_dict(obj.__dict__)
- url = obj._url % args
- url = '%s%s/%s' % (self._url, url, args['id'])
+ url = self.constructUrl(id_=obj.id, obj=obj, parameters=obj.__dict__)
try:
r = requests.delete(url,
@@ -288,9 +290,7 @@ class Gitlab(object):
raise GitlabCreateError('Missing attribute(s): %s' %
", ".join(missing))
- args = _sanitize_dict(obj.__dict__)
- url = obj._url % args
- url = '%s%s' % (self._url, url)
+ url = self.constructUrl(id_=None, obj=obj, parameters=obj.__dict__)
for k, v in obj.__dict__.items():
if type(v) == bool:
@@ -313,9 +313,7 @@ class Gitlab(object):
raise GitlabCreateError('%d: %s' % (r.status_code, r.text))
def update(self, obj):
- args = _sanitize_dict(obj.__dict__)
- url = obj._url % args
- url = '%s%s/%s' % (self._url, url, str(obj.id))
+ url = self.constructUrl(id_=obj.id, obj=obj, parameters=obj.__dict__)
# build a dict of data that can really be sent to server
d = {}