Skip to content

Commit f188dcb

Browse files
author
Gauvain Pocentek
committed
implement the Session() method
1 parent ab82226 commit f188dcb

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

gitlab.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,29 @@ class GitlabCreateError(Exception):
3030
class GitlabUpdateError(Exception):
3131
pass
3232

33+
class GitlabSessionError(Exception):
34+
pass
35+
3336
class Gitlab(object):
3437
def __init__(self, url, private_token):
3538
self.url = '%s/api/v3'%url
3639
self.private_token = private_token
3740

41+
def setUrl(self, url):
42+
self.url = '%s/api/v3'%url
43+
44+
def setToken(self, token):
45+
self.private_token = token
46+
47+
def rawPost(self, path, data):
48+
url = '%s%s'%(self.url, path)
49+
try:
50+
r = requests.post(url, data)
51+
except:
52+
GitlabConnectionError('Can\'t connect to GitLab server (%s)'%self.url)
53+
54+
return r
55+
3856
def list(self, objClass, **kwargs):
3957
url = objClass.url
4058
if kwargs:
@@ -243,9 +261,12 @@ class Issue(GitlabObject):
243261
canUpdate = False
244262
canCreate = False
245263

246-
class Session(object):
247-
def __init__(self):
248-
raise NotImplementedError
264+
def Session(gl, email, password):
265+
r = gl.rawPost('/session', {'email': email, 'password': password})
266+
if r.status_code == 201:
267+
return User(gl, r.json)
268+
else:
269+
raise GitlabSessionError()
249270

250271
class ProjectBranch(GitlabObject):
251272
url = '/projects/%(project_id)d/repository/branches'

0 commit comments

Comments
 (0)