blob: 969c2bdb6b6778f44bff0926037e9bff9f3b6011 [file] [log] [blame]
Joe Gregorioc204b642010-09-21 12:01:23 -04001#!/usr/bin/env python
2#
3# Copyright 2007 Google Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18__author__ = 'jcgregorio@google.com (Joe Gregorio)'
19
20
21import httplib2
22import logging
23import os
24import pydoc
25import re
26
27from apiclient.discovery import build
28
29from google.appengine.api import users
30from google.appengine.ext import webapp
31from google.appengine.ext.webapp import template
32from google.appengine.ext.webapp import util
33
34STEP2_URI = 'http://%s.appspot.com/auth_return' % os.environ['APPLICATION_ID']
35
36class MainHandler(webapp.RequestHandler):
37
38 def get(self):
39 self.response.out.write("""
40 <ul>
41 <li><a href='/buzz/v1'>buzz</a>
42 <li><a href='/moderator/v1'>moderator</a>
43 <li><a href='/latitude/v1'>latitude</a>
44 </ul>
45 """)
46
47class ServiceHandler(webapp.RequestHandler):
48
49 def get(self, service_name, version):
50 service = build(service_name, version)
51 page = "<pre>%s</pre>" % pydoc.plain(pydoc.render_doc(service))
52
53 collections = []
54 for name in dir(service):
55 if not "_" in name and callable(getattr(service, name)):
56 collections.append(name)
57
58 for name in collections:
59 page = re.sub('(%s) =' % name, r'<a href="/%s/%s/%s">\1</a> =' % (service_name, version, name), page)
60
61 self.response.out.write(page)
62
63class CollectionHandler(webapp.RequestHandler):
64
65 def get(self, service_name, version, collection):
66 service = build(service_name, version)
67 page = "<pre>%s</pre>" % pydoc.plain(pydoc.render_doc(getattr(service, collection)()))
68 self.response.out.write(page)
69
70def main():
71 application = webapp.WSGIApplication(
72 [
73 (r'/', MainHandler),
74 (r'/(\w*)/(\w*)', ServiceHandler),
75 (r'/(\w*)/(\w*)/(\w*)', CollectionHandler),
76 ],
77 debug=True)
78 util.run_wsgi_app(application)
79
80
81if __name__ == '__main__':
82 main()