def save_statements(self, statements): """Save statements to LRS and update their statement id's :param statements: A list of statement objects to be saved :type statements: :class:`StatementList` :return: LRS Response object with the saved list of statements as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(statements, StatementList): statements = StatementList(statements) request = HTTPRequest(method="POST", resource="statements") request.headers["Content-Type"] = "application/json" request.content = statements.to_json() lrs_response = self._send_request(request) if lrs_response.success: id_list = json.loads(lrs_response.data) for s, statement_id in zip(statements, id_list): s.id = statement_id lrs_response.content = statements return lrs_response
def save_statements(self, statements): """Save statements to LRS and update their statement id's :param statements: A list of statement objects to be saved :type statements: :class:`StatementList` :return: LRS Response object with the saved list of statements as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(statements, StatementList): statements = StatementList(statements) request = HTTPRequest( method="POST", resource="statements" ) request.headers["Content-Type"] = "application/json" request.content = statements.to_json() lrs_response = self._send_request(request) if lrs_response.success: id_list = json.loads(lrs_response.data) for s, statement_id in zip(statements, id_list): s.id = statement_id lrs_response.content = statements return lrs_response
def save_statement(self, statement): """Save statement to LRS and update statement id if necessary :param statement: Statement object to be saved :type statement: :class:`tincan.statement.Statement` :return: LRS Response object with the saved statement as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(statement, Statement): statement = Statement(statement) request = HTTPRequest(method="POST", resource="statements") if statement.id is not None: request.method = "PUT" request.query_params["statementId"] = statement.id request.headers["Content-Type"] = "application/json" request.content = statement.to_json(self.version) lrs_response = self._send_request(request) if lrs_response.success: if statement.id is None: statement.id = json.loads(lrs_response.data)[0] lrs_response.content = statement return lrs_response
def save_statement(self, statement): """Save statement to LRS and update statement id if necessary :param statement: Statement object to be saved :type statement: :class:`tincan.statement.Statement` :return: LRS Response object with the saved statement as content :rtype: :class:`tincan.lrs_response.LRSResponse` """ if not isinstance(statement, Statement): statement = Statement(statement) request = HTTPRequest( method="POST", resource="statements" ) if statement.id is not None: request.method = "PUT" request.query_params["statementId"] = statement.id request.headers["Content-Type"] = "application/json" request.content = statement.to_json(self.version) lrs_response = self._send_request(request) if lrs_response.success: if statement.id is None: statement.id = json.loads(lrs_response.data)[0] lrs_response.content = statement return lrs_response