diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2013-03-24 14:25:13 +0100 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2013-03-24 14:25:13 +0100 |
commit | 8d65870a24e0f28b19bef86f4e0a72782c20c2b8 (patch) | |
tree | 9179a96d5082ef02c6fa643b9bea89cd5503e777 /gitlab.py | |
parent | 1625e55f7afe0080fbc9ddcebdbfb0702e38ded6 (diff) | |
download | gitlab-8d65870a24e0f28b19bef86f4e0a72782c20c2b8.tar.gz |
add a json() method to GitlabObject's
Diffstat (limited to 'gitlab.py')
-rw-r--r-- | gitlab.py | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import json import requests __title__ = 'python-gitlab' @@ -26,6 +27,14 @@ __license__ = 'LGPL3' __copyright__ = 'Copyright 2013 Gauvain Pocentek' +class jsonEncoder(json.JSONEncoder): + def default(self, obj): + if isinstance(obj, GitlabObject): + return obj.__dict__ + elif isinstance(obj, Gitlab): + return {'url': obj._url} + return json.JSONEncoder.default(self, obj) + class GitlabConnectionError(Exception): pass @@ -421,6 +430,9 @@ class GitlabObject(object): def __str__(self): return '%s => %s' % (type(self), str(self.__dict__)) + def json(self): + return json.dumps(self.__dict__, cls=jsonEncoder) + class User(GitlabObject): _url = '/users' |