From 11679b74a9d68ec073b6c6b5180563747108aa64 Mon Sep 17 00:00:00 2001 From: Conor Walsh Date: Tue, 21 Oct 2025 11:45:41 +0100 Subject: [PATCH] [FEATURE] Add Consumer and Action to request metadata - LRN-48802 --- README.md | 1 + .../assessment/standalone_assessment.py | 212 ++++++++++++++---- docs/quickstart/css/style.css | 136 ++++++++++- learnosity_sdk/request/dataapi.py | 58 ++++- tests/unit/test_dataapi.py | 97 ++++++++ 5 files changed, 445 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 7b9f8b7..61585b7 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ Following are the routes to access our APIs. * Items API : http://localhost:8000/itemsapi * Reports API : http://localhost:8000/reportsapi * Question Editor API : http://localhost:8000/questioneditorapi +* Data API : http://localhost:8000/dataapi Open these pages with your web browser. These are all basic examples of Learnosity's integration. You can interact with these demo pages to try out the various APIs. The Items API example is a basic example of an assessment loaded into a web page with Learnosity's assessment player. You can interact with this demo assessment to try out the various Question types. diff --git a/docs/quickstart/assessment/standalone_assessment.py b/docs/quickstart/assessment/standalone_assessment.py index deec11d..aef0274 100644 --- a/docs/quickstart/assessment/standalone_assessment.py +++ b/docs/quickstart/assessment/standalone_assessment.py @@ -5,12 +5,14 @@ # with `rendering_type: "assess"`. # Include server side Learnosity SDK, and set up variables related to user access -from learnosity_sdk.request import Init +from learnosity_sdk.request import Init, DataApi from learnosity_sdk.utils import Uuid from .. import config # Load consumer key and secret from config.py # Include web server and Jinja templating libraries. from http.server import BaseHTTPRequestHandler, HTTPServer from jinja2 import Template +import json +import os # - - - - - - Section 1: Learnosity server-side configuration - - - - - - # @@ -32,13 +34,6 @@ "domain": host, } -# Author Aide does not accept user_id so we need a separate security object -authorAideSecurity = { - "consumer_key": config.consumer_key, - # Change to the domain used in the browser, e.g. 127.0.0.1, learnosity.com - "domain": host, -} - # Items API configuration parameters. items_request = { # Unique student identifier, a UUID generated above. @@ -268,16 +263,6 @@ } } -# Author Aide API configuration parameters. -author_aide_request = { - "user": { - "id": 'python-demo-user', - "firstname": 'Demos', - "lastname": 'User', - "email": 'demos@learnosity.com' - } -} - # Set up Learnosity initialization data. initItems = Init( "items", security, config.consumer_secret, @@ -304,18 +289,12 @@ request = question_editor_request ) -initAuthorAide = Init( - "authoraide", authorAideSecurity, config.consumer_secret, - request = author_aide_request -) - # Generated request(initOptions) w.r.t all apis generated_request_Items = initItems.generate() generated_request_Questions = initQuestions.generate() generated_request_Author = initAuthor.generate() generated_request_Reports = initReports.generate() generated_request_QuestionEditor = initQuestionEditor.generate() -generated_request_AuthorAide = initAuthorAide.generate() # - - - - - - Section 2: your web page configuration - - - - - -# @@ -332,12 +311,36 @@ def createResponse(self, response: str) -> None: def do_GET(self) -> None: + # Serve CSS file + if self.path == "/css/style.css": + try: + # Get the directory where this script is located + script_dir = os.path.dirname(os.path.abspath(__file__)) + # Navigate to the CSS file location + css_path = os.path.join(script_dir, "..", "css", "style.css") + + with open(css_path, 'r') as f: + css_content = f.read() + + self.send_response(200) + self.send_header("Content-type", "text/css") + self.end_headers() + self.wfile.write(css_content.encode("utf-8")) + return + except FileNotFoundError: + self.send_response(404) + self.send_header("Content-type", "text/plain") + self.end_headers() + self.wfile.write(b"CSS file not found") + return + if self.path.endswith("/"): # Define the page HTML, as a Jinja template, with {{variables}} passed in. template = Template(""" +