Skip to content

Commit

Permalink
add a json() method to GitlabObject's
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Mar 24, 2013
1 parent 1625e55 commit 8d65870
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gitlab.py
Expand Up @@ -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'
Expand All @@ -26,6 +27,14 @@
__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

Expand Down Expand Up @@ -421,6 +430,9 @@ def __init__(self, gl, data=None, **kwargs):
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'
Expand Down

0 comments on commit 8d65870

Please sign in to comment.