Skip to content

Commit

Permalink
link GitLab and User classes to their possible children
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Feb 11, 2013
1 parent 01152da commit d1f80da
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions gitlab.py
Expand Up @@ -52,9 +52,9 @@ def authenticate(self, email=None, password=None):

r = self.rawPost('/session', {'email': email, 'password': password})
if r.status_code == 201:
self.user = User(self, r.json)
self.user = CurrentUser(self, r.json)
else:
raise GitlabAuthenticationError()
raise GitlabAuthenticationError(r.json['message'])

self.private_token = self.user.private_token

Expand Down Expand Up @@ -189,6 +189,24 @@ def update(self, objClass, id, objData, **kwargs):
else:
raise GitlabUpdateError('%d: %s'%(r.status_code, r.text))

def getListOrObject(self, cls, id, **kwargs):
if id == None:
return cls.list(self, **kwargs)
else:
return cls.get(self, id, **kwargs)

def Project(self, id=None):
return self.getListOrObject(Project, id)

def Group(self, id=None):
return self.getListOrObject(Group, id)

def Issue(self, id=None):
return self.getListOrObject(Issue, id)

def User(self, id=None):
return self.getListOrObject(User, id)


class GitlabObject(object):
url = None
Expand Down Expand Up @@ -282,18 +300,22 @@ def __str__(self):
class User(GitlabObject):
url = '/users'

class CurrentUserKey(GitlabObject):
url = '/user/keys'
canUpdate = False

class CurrentUser(GitlabObject):
url = '/user'
canGetList = False
canCreate = False
canUpdate = False
canDelete = False

class CurrentUserKey(GitlabObject):
url = '/user/keys'
canUpdate = False

url = '/users'
def Key(self, id=None):
if id == None:
return CurrentUserKey.list(self.gitlab)
else:
return CurrentUserKey.get(self.gitlab, id)

class Group(GitlabObject):
url = '/groups'
Expand Down

0 comments on commit d1f80da

Please sign in to comment.