summaryrefslogtreecommitdiff
path: root/gitlab.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2013-02-08 09:38:19 +0100
committerGauvain Pocentek <gauvain@pocentek.net>2013-02-08 09:38:19 +0100
commit1fddcd2359801ca41d614bf39249ee8f4c9005d1 (patch)
treecc9ad1a9db6c0865d8e2448f36fcf6edbdb3f9cb /gitlab.py
parent1d7e85db13e74b7c056c0b59795b177fc2f6cbb7 (diff)
downloadgitlab-1fddcd2359801ca41d614bf39249ee8f4c9005d1.tar.gz
Rework object creation from json
Diffstat (limited to 'gitlab.py')
-rw-r--r--gitlab.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/gitlab.py b/gitlab.py
index 7d3100e..0e39b55 100644
--- a/gitlab.py
+++ b/gitlab.py
@@ -193,12 +193,21 @@ class GitlabObject(object):
return gl.delete(cls, id, **kwargs)
+ def getObject(self, k, v):
+ if self.constructorTypes and k in self.constructorTypes:
+ return globals()[self.constructorTypes[k]](v)
+ else:
+ return v
+
def __init__(self, data):
for k, v in data.items():
- if self.constructorTypes and k in self.constructorTypes:
- self.__dict__[k] = self.constructorTypes[k](v)
+ if isinstance (v, list):
+ self.__dict__[k] = []
+ for i in v:
+ self.__dict__[k].append(self.getObject(k,i))
+
else:
- self.__dict__[k] = v
+ self.__dict__[k] = self.getObject(k,v)
def __str__(self):
return '%s => %s'%(type(self), str(self.__dict__))
@@ -207,9 +216,13 @@ class GitlabObject(object):
class User(GitlabObject):
url = '/users'
+class Group(GitlabObject):
+ url = '/groups'
+ constructorTypes = {'projects': 'Project'}
+
class Project(GitlabObject):
url = '/projects'
- constructorTypes = {'owner': User}
+ constructorTypes = {'owner': 'User', 'namespace': 'Group'}
canUpdate = False
canDelete = False
@@ -246,10 +259,13 @@ class ProjectMilestone(GitlabObject):
class ProjectMergeRequest(GitlabObject):
url = '/projects/%(project_id)d/merge_request'
+ constructorTypes = {'author': 'User', 'assignee': 'User'}
canDelete = False
class Issue(GitlabObject):
url = '/issues'
+ constructorTypes = {'author': 'User', 'assignee': 'User',
+ 'milestone': 'ProjectMilestone'}
canGet = False
canDelete = False
canUpdate = False
@@ -260,15 +276,13 @@ class ProjectIssue(GitlabObject):
returnClass = Issue
canDelete = False
-class Group(GitlabObject):
- url = '/groups'
-
class Session(object):
def __init__(self):
raise NotImplementedError
-class Snippet(GitlabObject):
+class ProjectSnippet(GitlabObject):
url = '/projects/%(project_id)d/snippets'
+ constructorTypes = {'author': 'User'}
class User(GitlabObject):
url = '/users'