Skip to content

Commit

Permalink
define GitlabObject.as_dict() to dump object as a dict
Browse files Browse the repository at this point in the history
  • Loading branch information
rhansen committed Feb 12, 2016
1 parent 81be3cf commit f15a7cf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gitlab/objects.py
Expand Up @@ -34,9 +34,7 @@
class jsonEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, GitlabObject):
return {k: v for k, v in six.iteritems(obj.__dict__)
if (not isinstance(v, BaseManager)
and not k[0] == '_')}
return obj.as_dict()
elif isinstance(obj, gitlab.Gitlab):
return {'url': obj._url}
return json.JSONEncoder.default(self, obj)
Expand Down Expand Up @@ -488,6 +486,11 @@ def json(self):
"""
return json.dumps(self, cls=jsonEncoder)

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


class UserKey(GitlabObject):
_url = '/users/%(user_id)s/keys'
Expand Down

0 comments on commit f15a7cf

Please sign in to comment.