diff options
| author | Gauvain Pocentek <gauvain@pocentek.net> | 2013-02-08 10:24:36 +0100 |
|---|---|---|
| committer | Gauvain Pocentek <gauvain@pocentek.net> | 2013-02-08 10:24:36 +0100 |
| commit | f188dcb5eda4f5b638356501687477f0cc0177e9 (patch) | |
| tree | 47dbc103673db5116b55d615277965c463f22b72 /gitlab.py | |
| parent | ab822269c02cefa1557635523db948fe496aea2b (diff) | |
| download | gitlab-f188dcb5eda4f5b638356501687477f0cc0177e9.tar.gz | |
implement the Session() method
Diffstat (limited to 'gitlab.py')
| -rw-r--r-- | gitlab.py | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -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' |
