Submit a request
Submit a request

Delivering an Offline Assessment Within an App Environment

Please note: This is a premium product feature. If you're unsure if your license provides you access to this, please contact your Learnosity Account manager.

Learnosity's Items API can operate in an offline mode to deliver preloaded learning content without an active Internet connection. The offline features may also be useful for applications catering for low bandwidth or intermittent connectivity, since content can be loaded in advance and served later from local storage.

Customers wishing to implement offline functionality can contact us to discuss their use case and the latest guidance. We can provide sample offline implementations for iOS, Chrome OS, generic Webview/JavaScript containers and other platforms upon request, to help kick start your project.

Learnosity assessments can be delivered offline using the following integration:

  • Create an offline package to be included within your iOS/Android/Chrome App. The offline package will contain a local version of the assessment API libraries (provided by Learnosity) and a static copy of the assessment content to be served offline.
  • Load the Items API module from the local filesystem into your app via any webview or HTML/JavaScript container. Use script tags, a module loader or a build tool to include the local script.
  • Generate a signed security packet by making a one-time remote call to a signing service.
    • Do not distribute your Learnosity consumer key/secret within the application! Instead, implement the signing service external to the application.
    • The signing service will simply return a signed security packet to your app. See below for signature details.
  • Call LearnosityItems.primeOffline() and pass the signed security packet. This requires a network connection, and pre-authorizes future offline calls to LearnosityItems.init() for the consumer_key and user_id provided in the security packet.
  • Call LearnosityItems.init() and pass "type": "offline_app" in your initialization options. Specify the Activity/Item references as normal.
    • Items API assumes the required content has been prepared via Data API's offline package endpoint and stored in the app's directory structure according to the offline package structure.
    • Items API content in the correct location will be served from the local filesystem.
    • Items API will persist all assessment data and responses to local storage using the IndexedDB support of the JavaScript container.
  • Call LearnosityItems.needsPushing() to determine whether pending session data needs to be synchronised to Learnosity.
  • When a network connection is available, call LearnosityItems.push() to push local session data to Learnosity's servers.

The offline package consists of two parts:

  • Item bank content as a collection of static JSON files, retrieved using Data API's offline package endpoint.
  • A copy of the library code for Learnosity's assessment APIs. This will usually include Items API and Questions API.

The Item bank content and library code should be included in your app with the following directory structure:

Static build of Item bank content

Path
.../vendor/learnosity/itembank
Description
Static export of Item bank content retrieved from Data API's offline package endpoint. May include Activities, assets and Items subfolders.

 

Static build of Items API

Path
.../vendor/learnosity/itemsApi
Description

Static build of Items API.

Include the Items API in your app using eg. <script src="../vendor/learnosity/itemsApi/v1.39.0/primer.js"></script>, then access the LearnosityItemsglobal as usual.

 

Static build of Assess API

Path
.../vendor/learnosity/assessApi
Description
Static build of Assess API. This will be loaded by Items API as needed.

 

Static build of Questions API

Path
.../vendor/learnosity/questionsApi
Description
Static build of Questions API. This will be loaded by Items API as needed.

 

The sample implementations available from Learnosity will include this skeleton structure for you.

 

Directory tree for the offline package Directory tree for the offline package

 

Implement a signing service to authorize offline assessment content in your app. The signing service will need to generate a security signature for the combination of domain, user_id and consumer_key to be used within the offline assessment. The domain parameter must match the domain of the HTML/JavaScript container in which the assessment will be delivered.

This sample PHP implementation demonstrates how to create the signed security packet:

<?php    header("Content-type: application/json");
    header("Access-Control-Allow-Origin: *");

    $user_id = $_POST["userid"];
    $domain = $_POST["domain"];

    $consumer_key = "YOUR_CONSUMER_KEY";
    $consumer_secret = "YOUR_CONSUMER_SECRET";

    $timestamp = gmdate("Ymd-Hi");
    $signature = hash("sha256",
            $consumer_key
            . "_" . $domain
            . "_" . $timestamp
            . "_" . $user_id
            . "_" . $consumer_secret
        );

    $security = [
        "timestamp"     => $timestamp,
        "domain"        => $domain,
        "consumer_key"  => $consumer_key,
        "user_id"       => $user_id,
        "signature"     => $signature
    ];

    echo json_encode($security);
?>

This section details the special methods and parameters in Items API for delivering offline assessment, including:

  • Support for initializing Items API with "type": "offline_app".
  • LearnosityItems.primeOffline().
  • LearnosityItems.needsPushing().
  • LearnosityItems.push().

 

Items API can be initialized in offline mode by passing "type": "offline_app" in the initialization options. The offline mode causes Items API to load and persist assessment data locally without requiring an Internet connection.

The consumer_key and user_id for the offline session(s) must have been primed using LearnosityItems.primeOffline() before calling LearnosityItems.init().

Items API assumes the Activity and/or Item references in the initialization options have been prepared via Data API's offline package endpoint and stored in the app's directory structure according to the offline package structure.

When an Internet connection is available, the host application can call LearnosityItems.push() to push any locally stored sessions to Learnosity's servers. Once pushed, the session data is available via Reports API and Data API as usual.

This example demonstrates how to call LearnosityItems.init() in offline mode:

function initOfflineActivity(consumerKey, userId, itemRefs, sessionId) {
    itemsApp = window.LearnosityItems.init({
            // Simplified security params. Assumes the full packet with domain,
            // timestamp, etc. has already been passed to primeOffline().
            security: {
                consumer_key: consumerKey
            },
            request: {
                rendering_type: 'inline'
                type:       'offline_app',
                user_id:    userId,
                session_id: sessionId,
                items:      itemRefs,
                state:      'initial',

            }
        });
}

Prepares Items API to work offline for the consumer_key and user_id provided in the signed securityobject.

Parameters

  • security <Object> - required

    This object contains the security parameters with which Items API will be pre-authorized.

    The required attributes are: consumer_keyuser_iddomaintimestamp and signature.

    See the signed security packet section for details on generating the signature.

  • success <Function>

    This function will be called when primeOffline() completes successfully.

  • error <Function>

    This function will be called if an error occurs while primeOffline() is executing.

Provides a way to check if there are pending sessions that need to be synchronised to Learnosity. The successcallback will be passed an array of pending session_ids for the given consumer and user that have not been pushed to Learnosity's servers. An error is thrown if the provided consumer_key and user_id have not already been primed using primeOffline().

Parameters

  • consumer_key <String> - required

    Specifies which consumer should be checked be checked for pending sessions.

  • user_id <String> - required

    Specifies which user should be checked for pending sessions.

  • success <Function> - required

    This function is called when needsPushing() has completed successfully. The function is passed an array of session_ids that have not been synchronised to Learnosity servers for the given consumer_key and user_id.

  • error <Function>

    This function is called if an error occurs while needsPushing() is executing.

Sends all pending sessions for the specified user to Learnosity's servers. Only sessions that were initialized with the provided combination of consumer_id and user_id will be pushed. An error is thrown if the provided consumer_key and user_id have not already been primed using primeOffline().

Parameters

  • consumer_key <String> - required

    Specifies the consumer for which pending sessions should be pushed.

  • user_id <String> - required

    Specifies the user for which pending sessions should be pushed.

  • success <Function> - required

    This function will be called when push() has completed successfully.

  • error <Function>

    This function will be called if an error occurs while push() is executing.

Was this article helpful?
0 out of 0 found this helpful