def newAuthor(self): username = raw_input("Author username? ") email = raw_input("Author email? ") data = {"designator": username, "email": email} r = self.session.post(lsrh.getAuthorURL(), data=json.dumps(data)) self.author_id = lsrh.getIdFromResponse(r) print 'Set author to', self.author_id
def addAnswer(self, text): data = { "author": lsrh.getAuthorURL(self.author_id), "prompt": lsrh.getPromptURL(self.prompt_id), "text": text } r = self.session.post(lsrh.getAnswerURL(), data=json.dumps(data)) lsrh.checkStatus(r, (201,), "Failed to upload answer.")
def setAuthor(self, author_id): r = self.session.get(lsrh.getAuthorURL(author_id), headers=self.headers) if r.status_code != 200: # if failure print 'Author id not found on remote server.' self.newAuthor() else: self.author_id = lsrh.getIdFromResponse(r) print 'Set author to', self.author_id