3838from google .appengine .ext .webapp import util
3939
4040
41+ DISCOVERY_URI = 'https://www.googleapis.com/discovery/v1/apis?preferred=true'
42+
43+
44+ def get_directory_doc ():
45+ http = httplib2 .Http (memcache )
46+ ip = os .environ .get ('REMOTE_ADDR' , None )
47+ uri = DISCOVERY_URI
48+ if ip :
49+ uri += ('&userIp=' + ip )
50+ resp , content = http .request (uri )
51+ directory = simplejson .loads (content )['items' ]
52+ return directory
53+
54+
4155class MainHandler (webapp .RequestHandler ):
4256 """Handles serving the main landing page.
4357 """
4458
4559 def get (self ):
46- http = httplib2 .Http (memcache )
47- resp , content = http .request ('https://www.googleapis.com/discovery/v1/apis?preferred=true' )
48- directory = simplejson .loads (content )['items' ]
60+ directory = get_directory_doc ()
4961 for item in directory :
5062 item ['title' ] = item .get ('title' , item .get ('description' , '' ))
5163 path = os .path .join (os .path .dirname (__file__ ), 'index.html' )
@@ -60,9 +72,7 @@ class GadgetHandler(webapp.RequestHandler):
6072 """
6173
6274 def get (self ):
63- http = httplib2 .Http (memcache )
64- resp , content = http .request ('https://www.googleapis.com/discovery/v1/apis?preferred=true' )
65- directory = simplejson .loads (content )['items' ]
75+ directory = get_directory_doc ()
6676 for item in directory :
6777 item ['title' ] = item .get ('title' , item .get ('description' , '' ))
6878 path = os .path .join (os .path .dirname (__file__ ), 'gadget.html' )
@@ -86,7 +96,8 @@ class ResourceHandler(webapp.RequestHandler):
8696 """
8797
8898 def get (self , service_name , version , collection ):
89- resource = discovery .build (service_name , version )
99+ http = httplib2 .Http (memcache )
100+ resource = discovery .build (service_name , version , http = http )
90101 # descend the object path
91102 if collection :
92103 path = collection .split ('/' )
0 commit comments