Skip to content

Commit f15a7cf

Browse files
committed
define GitlabObject.as_dict() to dump object as a dict
1 parent 81be3cf commit f15a7cf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

gitlab/objects.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
class jsonEncoder(json.JSONEncoder):
3535
def default(self, obj):
3636
if isinstance(obj, GitlabObject):
37-
return {k: v for k, v in six.iteritems(obj.__dict__)
38-
if (not isinstance(v, BaseManager)
39-
and not k[0] == '_')}
37+
return obj.as_dict()
4038
elif isinstance(obj, gitlab.Gitlab):
4139
return {'url': obj._url}
4240
return json.JSONEncoder.default(self, obj)
@@ -488,6 +486,11 @@ def json(self):
488486
"""
489487
return json.dumps(self, cls=jsonEncoder)
490488

489+
def as_dict(self):
490+
"""Dump the object as a dict."""
491+
return {k: v for k, v in six.iteritems(self.__dict__)
492+
if (not isinstance(v, BaseManager) and not k[0] == '_')}
493+
491494

492495
class UserKey(GitlabObject):
493496
_url = '/users/%(user_id)s/keys'

0 commit comments

Comments
 (0)