diff options
Diffstat (limited to 'src/mailman/rest/root.py')
| -rw-r--r-- | src/mailman/rest/root.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/mailman/rest/root.py b/src/mailman/rest/root.py new file mode 100644 index 000000000..e3ba1b62e --- /dev/null +++ b/src/mailman/rest/root.py @@ -0,0 +1,88 @@ +# Copyright (C) 2010 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""The root of the REST API.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'Root', + ] + + +import json +import hashlib + +from restish import http, resource + +from mailman.config import config +from mailman.core.system import system +from mailman.rest.helpers import etag, path_to +from mailman.rest.webservice import ( + ADomain, AList, AllDomains, AllLists, AllMembers) + + + +class Root(resource.Resource): + """The RESTful root resource. + + At the root of the tree are the API version numbers. Everything else + lives underneath those. Currently there is only one API version number, + and we start at 3.0 to match the Mailman version number. That may not + always be the case though. + """ + @resource.child(config.webservice.api_version) + def api_version(self, request, segments): + return TopLevel() + + +class TopLevel(resource.Resource): + """Top level collections and entries.""" + + @resource.child() + def system(self, request, segments): + """/<api>/system""" + resource = dict( + mailman_version=system.mailman_version, + python_version=system.python_version, + self_link=path_to('system'), + ) + return http.ok([], etag(resource)) + + @resource.child() + def domains(self, request, segments): + if len(segments) == 0: + return AllDomains() + elif len(segments) == 1: + return ADomain(segments[0]), [] + else: + return http.bad_request() + + @resource.child() + def lists(self, request, segments): + if len(segments) == 0: + return AllLists() + else: + list_name = segments.pop(0) + return AList(list_name), segments + + @resource.child() + def members(self, request, segments): + if len(segments) == 0: + return AllMembers() + return http.bad_request() |
