Exemplo n.º 1
0
 def GET(self, *vpath, **params):
     self.paramMap = {}
     for k,v in params.items():
         self.paramMap[k] = v
     
     ridesList = []
     cherrypy.response.headers["Content-Type"] = "application/json"    
     if vpath:
         if (vpath[0] == "near"):
             if not (self._validate_param("lat") and self._validate_param("lon")):
                 cherrypy.response.status = 400
                 return json.dumps({"Error":True,"Message":PMIP.REQUEST_PARAM_MISSING})
             
             if (self.paramMap.has_key("limit")):                    
                 rideDocs = self._find_near(self.paramMap["lat"], self.paramMap["lon"], self.paramMap["limit"])
             else:
                 rideDocs = self._find_near(self.paramMap["lat"], self.paramMap["lon"])
         elif(vpath[0] == "within"):
             if not (self._validate_param("lat") and self._validate_param("lon") and self._validate_param("radius")):
                 cherrypy.response.status = 400
                 return json.dumps({"Error":True,"Message":PMIP.REQUEST_PARAM_MISSING})
             
             if (self.paramMap.has_key("limit")):                    
                 rideDocs = self._find_within_circle(self.paramMap["lat"], self.paramMap["lon"], self.paramMap["radius"], self.paramMap["limit"])
             else:
                 rideDocs = self._find_within_circle(self.paramMap["lat"], self.paramMap["lon"], self.paramMap["radius"])
         elif(vpath[0] == "tags"):
             if not (self._validate_param("tag")):
                 cherrypy.response.status = 400
                 return json.dumps({"Error":True,"Message":PMIP.REQUEST_PARAM_MISSING})
             else:
                 rideDocs = self._find_with_tags(self.paramMap["tag"])
         # elif(vpath[0] == "route"):
             # if not (self._validate_param("from") and self._validate_param("to") and self._validate_param("from")):
                 # cherrypy.response.status = 400
                 # return json.dumps({"Error":True,"Message":PMIP.REQUEST_PARAM_MISSING})
             # else:
                  # rideDocs = self._find_for_route(self.paramMap["from"],self.paramMap["to"])
         else:
             cherrypy.response.status = 400
             return json.dumps({"Error":True,"Message":PMIP.INVALID_URI})
             
         for rideDoc in rideDocs :
             result = Utility.getRide(rideDoc)               
             ridesList.append(result)
         return json.dumps(ridesList);