def invoke(self, apiParams, body=None, sessionId=None, requestHash=None): # API parameters self.logger.debug("apiParams: " + str(apiParams) + " body: " + str(body)) #if body == None or len(body) < 1: # # fail # return "No body" if len(apiParams) < 1: return '{"error": "Missing content ID"}' if len(body) < 1: return '{"error": "Missing request body"}' contentId = apiParams[0] # get the notes validator = SessionValidator(sessionId, requestHash) if self.conn: if validator.authenticateRequest(body): cursor = self.conn.cursor() sql = "delete from notes where id=%s" self.logger.debug("deleting note: " + sql % (contentId)) cursor.execute(sql, (contentId)) else: self.logger.debug("Couldn't delete note -- failed request validation") return '{"error": "Failed request validation"}' else: self.logger.debug("Couldn't delete note -- no database connection") return '{"results": "OK"}'
def invoke(self, apiParams, body="", sessionId=None, requestHash=None): # API parameters self.logger.debug("apiParams: " + str(apiParams) + " body: " + str(body) + " sessionId: " + str(sessionId) + " requestHash: " + str(requestHash)) if sessionId == None or len(sessionId) < 1: # fail loginHandler = GetLogin.GetLogin() return loginHandler.invoke(apiParams, body, sessionId, requestHash) notes = [] output = {} # get the notes validator = SessionValidator(sessionId, requestHash) if self.conn: if validator.authenticateRequest(body, noBody = True): cursor = self.conn.cursor() sql = "select id, topPx, leftPx, heightPx, widthPx, html, zIndex from notes" self.logger.debug("getting notes: " + sql) cursor.execute(sql) results = cursor.fetchall() self.logger.debug("rows: " + str(results)) for row in results: self.logger.debug("row: " + str(row)) note = {} note["id"] = row[0] note["top"] = row[1] note["left"] = row[2] note["height"] = row[3] note["width"] = row[4] note["html"] = row[5] note["zIndex"] = row[6] notes.append(note) self.logger.debug("note: " + str(note)) self.logger.debug("retrieved " + str(len(notes)) + " notes") output["results"] = "OK" output["notes"] = notes else: self.logger.debug("Couldn't retrieve notes -- failed request validation") return '{"error": "Failed request validation"}' else: self.logger.debug("Couldn't retrieve notes -- no database connection") output["error"] = "No database connection" return JSONEncoder().encode(output)
def invoke(self, apiParams, body=None, sessionId=None, requestHash=None): # API parameters self.logger.debug("apiParams: " + str(apiParams) + " body: " + str(body)) if body == None or len(body) < 1: # fail return "No body" validator = SessionValidator(sessionId, requestHash) if self.conn: if validator.authenticateRequest(body): # decode the body self.logger.debug("body='" + str(body) + "'") message = JSONDecoder().decode(body) self.logger.debug("message='" + str(message) + "'") self.logger.debug("message length: " + str(len(message))) for note in message: self.logger.debug("note='" + str(note) + "'") self.logger.debug("type: " + str(type(note))) self.logger.debug("keys: " + str(note.keys())) self.logger.debug( "note: " + note["top"] + " " + note["left"] + " " + note["height"] + " " + note["width"] + " " + note["id"] + " " + note["html"] + " " + str(note["zIndex"]) ) cursor = self.conn.cursor() sql = "select count(1) from notes where id='" + note["id"] + "'" self.logger.debug("check note count: " + sql) cursor.execute(sql) results = cursor.fetchone() self.logger.debug("note count: " + str(results)) count = int(results[0]) try: if count > 0: # update # sql = """update notes set topPx=%s, leftPx=%s, heightPx=%s, # widthPx=%s, html=%s, zIndex=%s where id=%s""" # cursor.execute(sql, # (note["top"], note["left"], note["height"], # note["width"], note["html"], note["id"], # note["zIndex"])) sql = "delete from notes where id=%s" self.logger.debug("deleting note: " + sql) cursor.execute(sql, (note["id"])) # else: # insert sql = """insert into notes (id, topPx, leftPx, heightPx, widthPx, html, zIndex) values (%s, %s, %s, %s, %s, %s, %s)""" cursor.execute( sql, ( note["id"], note["top"], note["left"], note["height"], note["width"], note["html"], note["zIndex"], ), ) self.logger.debug("writing note: " + sql) except Exception, e: self.logger.error("Couldn't write note: " + str(e)) else: self.logger.debug("Couldn't update -- failed request validation") return '{"error": "Failed request validation"}'