summaryrefslogtreecommitdiff
path: root/gitlab.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2013-02-08 10:24:36 +0100
committerGauvain Pocentek <gauvain@pocentek.net>2013-02-08 10:24:36 +0100
commitf188dcb5eda4f5b638356501687477f0cc0177e9 (patch)
tree47dbc103673db5116b55d615277965c463f22b72 /gitlab.py
parentab822269c02cefa1557635523db948fe496aea2b (diff)
downloadgitlab-f188dcb5eda4f5b638356501687477f0cc0177e9.tar.gz
implement the Session() method
Diffstat (limited to 'gitlab.py')
-rw-r--r--gitlab.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/gitlab.py b/gitlab.py
index 85ee62b..7820736 100644
--- a/gitlab.py
+++ b/gitlab.py
@@ -30,11 +30,29 @@ class GitlabCreateError(Exception):
class GitlabUpdateError(Exception):
pass
+class GitlabSessionError(Exception):
+ pass
+
class Gitlab(object):
def __init__(self, url, private_token):
self.url = '%s/api/v3'%url
self.private_token = private_token
+ def setUrl(self, url):
+ self.url = '%s/api/v3'%url
+
+ def setToken(self, token):
+ self.private_token = token
+
+ def rawPost(self, path, data):
+ url = '%s%s'%(self.url, path)
+ try:
+ r = requests.post(url, data)
+ except:
+ GitlabConnectionError('Can\'t connect to GitLab server (%s)'%self.url)
+
+ return r
+
def list(self, objClass, **kwargs):
url = objClass.url
if kwargs:
@@ -243,9 +261,12 @@ class Issue(GitlabObject):
canUpdate = False
canCreate = False
-class Session(object):
- def __init__(self):
- raise NotImplementedError
+def Session(gl, email, password):
+ r = gl.rawPost('/session', {'email': email, 'password': password})
+ if r.status_code == 201:
+ return User(gl, r.json)
+ else:
+ raise GitlabSessionError()
class ProjectBranch(GitlabObject):
url = '/projects/%(project_id)d/repository/branches'