### Start moreStatements method Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Starts the moreStatements method, which fetches more statements from a previous query using the RESTful interface when in a browser. Logs the URL from the configuration object. ```javascript moreStatements: function (cfg) { this.log("moreStatements: " + cfg.url); ``` -------------------------------- ### retrieveState method - build request parameters Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Starts the retrieveState method, building request parameters for state retrieval. Uses 'actor' for version 0.9 and 'agent' otherwise, and includes registrationId for 0.9 when registration is provided. ```javascript retrieveState: function (key, cfg) { this.log("retrieveState"); var requestParams = {}, requestCfg = {}, requestResult, callbackWrapper, requestHeaders, self = this; requestHeaders = cfg.requestHeaders || {}; requestParams = { stateId: key, activityId: cfg.activity.id }; if (this.version === "0.9") { requestParams.actor = JSON.stringify(cfg.agent.asVersion(this.version)); } else { requestParams.agent = JSON.stringify(cfg.agent.asVersion(this.version)); } if ((typeof cfg.registration !== "undefined") && (cfg.registration !== null)) { if (this.version === "0.9") { requestParams.registrationId = cfg.registration; } else { ``` -------------------------------- ### retrieveState: GET activities/state with callback and synchronous handling Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Retrieves an activity state from the LRS using a GET request to 'activities/state'. The callback path wraps the XHR response into a TinCan.State object, handling 404 as null, extracting ETag and Content-Type, and parsing JSON when the content type is application/json. The synchronous path (no callback) sets requestResult.state to null on 404 or error, otherwise constructs the State object similarly. ```javascript requestCfg = { url: "activities/state", method: "GET", params: requestParams, ignore404: true, headers: requestHeaders }; ``` ```javascript if (typeof cfg.callback !== "undefined") { callbackWrapper = function (err, xhr) { var result = xhr; if (err === null) { if (xhr.status === 404) { result = null; } else { result = new TinCan.State( { id: key, contents: xhr.responseText } ); if (typeof xhr.getResponseHeader !== "undefined" && xhr.getResponseHeader("ETag") !== null && xhr.getResponseHeader("ETag") !== "") { result.etag = xhr.getResponseHeader("ETag"); } else { // // either XHR didn't have getResponseHeader (probably cause it is an IE // XDomainRequest object which doesn't) or not populated by LRS so create // the hash ourselves // // the LRS is responsible for quoting the Etag value so we need to mimic // that behavior here as well // result.etag = "\"" + TinCan.Utils.getSHA1String(xhr.responseText) + "\""; } if (typeof xhr.contentType !== "undefined") { // most likely an XDomainRequest which has .contentType, // for the ones that it supports result.contentType = xhr.contentType; } else if (typeof xhr.getResponseHeader !== "undefined" && xhr.getResponseHeader("Content-Type") !== null && xhr.getResponseHeader("Content-Type") !== "") { result.contentType = xhr.getResponseHeader("Content-Type"); } if (TinCan.Utils.isApplicationJSON(result.contentType)) { try { result.contents = JSON.parse(result.contents); } catch (ex) { self.log("retrieveState - failed to deserialize JSON: " + ex); } } } } cfg.callback(err, result); }; requestCfg.callback = callbackWrapper; } ``` ```javascript requestResult = this.sendRequest(requestCfg); if (! callbackWrapper) { requestResult.state = null; if (requestResult.err === null && requestResult.xhr.status !== 404) { requestResult.state = new TinCan.State( { id: key, contents: requestResult.xhr.responseText } ); if (typeof requestResult.xhr.getResponseHeader !== "undefined" && requestResult.xhr.getResponseHeader("ETag") !== null && requestResult.xhr.getResponseHeader("ETag") !== "") { requestResult.state.etag = requestResult.xhr.getResponseHeader("ETag"); } else { // // either XHR didn't have getResponseHeader (probably cause it is an IE // XDomainRequest object which doesn't) or not populated by LRS so create // the hash ourselves // // the LRS is responsible for quoting the Etag value so we need to mimic // that behavior here as well // requestResult.state.etag = "\"" + TinCan.Utils.getSHA1String(requestResult.xhr.responseText) + "\""; } } } ``` -------------------------------- ### GET activities/profile Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Retrieves a list of profile IDs for a given activity. This method sends a GET request to the activities/profile endpoint with the activityId parameter. If a callback is provided, the result is passed to it; otherwise, the result is returned directly. ```APIDOC ## GET activities/profile ### Description Retrieves a list of profile IDs for a given activity. ### Method GET ### Endpoint activities/profile ### Parameters #### Query Parameters - **activityId** (string) - Required - The activity ID to retrieve profile IDs for. - **since** (string) - Optional - Only return IDs that have been updated since the specified timestamp. ### Response #### Success Response (200) - **profileIds** (array of strings) - List of profile IDs. #### Response Example ```json ["profileId1", "profileId2"] ``` #### Error Response (404) Returns an empty array. ``` -------------------------------- ### about Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Determines the LRS version by sending a GET request to the 'about' endpoint. Returns an About object or asynchronously calls a callback. ```APIDOC ## about ### Description Determines the LRS version by sending a GET request to the 'about' endpoint. Returns an About object or asynchronously calls a callback. ### Method about ### Parameters - **cfg** (Object) - Configuration object for the about request. - **cfg.callback** (Function) - Optional. Callback to execute upon receiving a response. - **cfg.params** (Object) - This is needed, but can be empty. ### Return Value - **Object** - About which holds the version, or asynchronously calls a specified callback. ``` -------------------------------- ### Build query statements request config Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Builds a request configuration object for querying statements, defining supported parameters and version compatibility. It sets the URL to "statements" with a GET method and initializes parameter lists. ```javascript _queryStatementsRequestCfg: function (cfg) { this.log("_queryStatementsRequestCfg"); var params = {}, returnCfg = { url: "statements", method: "GET", params: params }, jsonProps = [ "agent", "actor", "object", "instructor" ], idProps = [ "verb", "activity" ], valProps = [ "registration", "context", "since", "until", "limit", "authoritative", "sparse", "ascending", "related_activities", "related_agents", "format", "attachments" ], i, prop, // // list of parameters that are supported in all versions (supported by // this library) of the spec // universal = { verb: true, registration: true, since: true, until: true, limit: true, ascending: true }, // // future proofing here, "supported" is an object so that // in the future we can support a "deprecated" list to // throw warnings, hopefully the spec uses deprecation phases // for the removal of these things // compatibility = { "0.9": { supported: { actor: true, instructor: true, target: true, object: true, context: true, authoritative: true, sparse: true } }, "1.0.0": { supported: { agent: true, activity: true, related_activities: true, related_agents: true, format: true, attachments: true } } }; compatibility["0.95"] = compatibility["0.9"]; compatibility["1.0.1"] = compatibility["1.0.0"]; compatibility["1.0.2"] = compatibility["1.0.0"]; ``` -------------------------------- ### retrieveAgentProfile(key, cfg) Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Retrieves an agent profile value using the RESTful interface. Sends a GET request to the agents/profile endpoint (or actors/profile for version 0.9) with profileId and agent parameters. ```APIDOC ## retrieveAgentProfile(key, cfg) ### Description Retrieves an agent profile value, when used from a browser sends to the endpoint using the RESTful interface. ### Method GET ### Endpoint agents/profile (or actors/profile for version 0.9) ### Parameters #### Path Parameters - **profileId** (String) - Required - Key of agent profile to retrieve - **agent** (TinCan.Agent) - Required - Agent in document identifier #### Request Headers - **requestHeaders** (Object) - Optional - Optional object containing additional headers to add to request #### Callback - **callback** (Function) - Optional - Callback to execute on completion ### Request Example ``` { "profileId": "key", "agent": "agent.asVersion(version)" } ``` ### Response #### Success Response Returns an object containing the retrieved value. ``` -------------------------------- ### GET /activities/state Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Retrieves a state value from the LRS using the RESTful interface. The state is identified by a key, activity, and agent, and optionally a registration. The result is a TinCan.State object or null if the state is not found (404). ```APIDOC ## GET /activities/state ### Description Retrieves a state value from the LRS using the RESTful interface. The state is identified by a key, activity, and agent, and optionally a registration. The result is a TinCan.State object or null if the state is not found (404). ### Method GET ### Endpoint /activities/state ### Parameters #### Query Parameters - **stateId** (String) - Required - The key of the state to retrieve. - **activityId** (String) - Required - The ID of the activity in the document identifier. - **agent** (String) - Required - The agent in the document identifier, serialized as JSON (for versions other than 0.9). - **actor** (String) - Required for version 0.9 - The actor in the document identifier, serialized as JSON. - **registrationId** (String) - Optional for version 0.9 - The registration ID. - **registration** (String) - Optional - The registration. #### Request Body None ### Request Example ``` GET /activities/state?stateId=&activityId=&agent= ``` ### Response #### Success Response (200) - **state** (TinCan.State) - The retrieved state object. #### Response Example ```json { "id": "stateId", "activityId": "activityId", "agent": {}, "registration": "registration", "value": "state value" } ``` ``` -------------------------------- ### Parse multipart headers with _parseHeaders Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Parses raw header strings from a multipart/mixed response section into an object map. Splits each line on ':' and trims whitespace from the value; handles continuation lines starting with a tab. ```javascript _parseHeaders: function (rawHeaders) { var headers = {}, headerList, key, h, i; headerList = rawHeaders.split("\n"); for (i = 0; i < headerList.length; i += 1) { h = headerList[i].split(":", 2); if (h[1] !== null) { headers[h[0]] = h[1].replace(/^\s+|\s+$/g, ""); key = h[0]; } else { if (h[0].substring(0, 1) === "\t") { headers[h[0]] = h[1].replace(/^\s+|\s+$/g, ""); } } } return headers; } ``` -------------------------------- ### GET /statements/more Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Retrieves a paginated set of statements using a more URL returned from a previous statements query. The more URL is resolved relative to the LRS endpoint or server root, and the result is returned as a TinCan.StatementsResult object. ```APIDOC ## GET /statements/more ### Description Retrieves a paginated set of statements using a more URL returned from a previous statements query. The more URL is resolved relative to the LRS endpoint or server root, and the result is returned as a TinCan.StatementsResult object. ### Method GET ### Endpoint /statements/more ### Parameters #### Query Parameters - **more** (String) - Required - The more URL from a previous statements result. #### Request Body None ### Request Example ``` GET /statements/more?more= ``` ### Response #### Success Response (200) - **statementsResult** (TinCan.StatementsResult) - The retrieved statements result. #### Response Example ```json { "statements": [], "more": "" } ``` ``` -------------------------------- ### Process more URL and send GET request Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Handles the 'more' URL from a StatementsResult, converting it to an absolute URL relative to the server root or endpoint. Supports both callback and synchronous modes, parsing the response into a TinCan.StatementsResult when no error occurs. ```javascript var requestCfg, requestResult, callbackWrapper, parsedURL, serverRoot; cfg = cfg || {}; // to support our interface (to support IE) we need to break apart // the more URL query params so that the request can be made properly later parsedURL = TinCan.Utils.parseURL(cfg.url, { allowRelative: true }); // Respect a more URL that is relative to either the server root // or endpoint (though only the former is allowed in the spec) serverRoot = TinCan.Utils.getServerRoot(this.endpoint); if (parsedURL.path.indexOf("/statements") === 0){ parsedURL.path = this.endpoint.replace(serverRoot, "") + parsedURL.path; this.log("converting non-standard more URL to " + parsedURL.path); } // The more relative URL might not start with a slash, add it if not if (parsedURL.path.indexOf("/") !== 0) { parsedURL.path = "/" + parsedURL.path; } requestCfg = { method: "GET", // For arbitrary more URLs to work, we need to make the URL absolute here url: serverRoot + parsedURL.path, params: parsedURL.params }; if (typeof cfg.callback !== "undefined") { callbackWrapper = function (err, xhr) { var result = xhr; if (err === null) { result = TinCan.StatementsResult.fromJSON(xhr.responseText); } cfg.callback(err, result); }; requestCfg.callback = callbackWrapper; } requestResult = this.sendRequest(requestCfg); requestResult.config = requestCfg; if (! callbackWrapper) { requestResult.statementsResult = null; if (requestResult.err === null) { requestResult.statementsResult = TinCan.StatementsResult.fromJSON(requestResult.xhr.responseText); } } return requestResult; ``` -------------------------------- ### retrieveStateIds method implementation Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Defines the retrieveStateIds function that constructs a GET request to the 'activities/state' endpoint. It handles version-specific parameter names (actor for 0.9, agent otherwise) and optional registration. The callback parses the response, returning an empty array on 404 and handling JSON parse errors. ```javascript retrieveStateIds: function (cfg) { this.log("retrieveStateIds"); var requestParams = {}, requestCfg, requestHeaders, requestResult, callbackWrapper; cfg = cfg || {}; requestHeaders = cfg.requestHeaders || {}; requestParams.activityId = cfg.activity.id; if (this.version === "0.9") { requestParams.actor = JSON.stringify(cfg.agent.asVersion(this.version)); } else { requestParams.agent = JSON.stringify(cfg.agent.asVersion(this.version)); } if ((typeof cfg.registration !== "undefined") && (cfg.registration !== null)) { if (this.version === "0.9") { requestParams.registrationId = cfg.registration; } else { requestParams.registration = cfg.registration; } } requestCfg = { url: "activities/state", method: "GET", params: requestParams, headers: requestHeaders, ignore404: true }; if (typeof cfg.callback !== "undefined") { callbackWrapper = function (err, xhr) { var result = xhr; if (err !== null) { cfg.callback(err, result); return; } if (xhr.status === 404) { result = []; } else { try { result = JSON.parse(xhr.responseText); } catch (ex) { err = "Response JSON parse error: " + ex; } } cfg.callback(err, result); }; requestCfg.callback = callbackWrapper; } requestResult = TinCan.Request.send(requestCfg); return requestResult; } ``` -------------------------------- ### LRS statement serialization and retrieval logic Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_LRS.js.html Handles statement serialization failures and multipart attachment requests in the LRS sendStatement method. The first block logs warnings or errors and returns appropriate callback or result objects. The second block builds multipart/mixed or JSON request data, sets PUT or POST method based on statement ID, and sends the request. The third block initializes a GET request to retrieve a statement by ID. ```javascript if (this.allowFail) { this.log("[warning] statement could not be serialized in version (" + this.version + "): " + ex); if (typeof cfg.callback !== "undefined") { cfg.callback(null, null); return; } return { err: null, xhr: null }; } this.log("[error] statement could not be serialized in version (" + this.version + "): " + ex); if (typeof cfg.callback !== "undefined") { cfg.callback(ex, null); return; } return { err: ex, xhr: null }; ``` ```javascript if (versionedStatement.hasOwnProperty("attachments") && stmt.hasAttachmentWithContent()) { boundary = this._getBoundary(); requestCfg.headers["Content-Type"] = "multipart/mixed; boundary=" + boundary; for (i = 0; i < stmt.attachments.length; i += 1) { if (stmt.attachments[i].content !== null) { requestAttachments.push(stmt.attachments[i]); } } try { requestCfg.data = this._getMultipartRequestData(boundary, versionedStatement, requestAttachments); } catch (ex) { if (this.allowFail) { this.log("[warning] multipart request data could not be created (attachments probably not supported): " + ex); if (typeof cfg.callback !== "undefined") { cfg.callback(null, null); return; } return { err: null, xhr: null }; } this.log("[error] multipart request data could not be created (attachments probably not supported): " + ex); if (typeof cfg.callback !== "undefined") { cfg.callback(ex, null); return; } return { err: ex, xhr: null }; } } else { requestCfg.headers["Content-Type"] = "application/json"; requestCfg.data = JSON.stringify(versionedStatement); } if (stmt.id !== null) { requestCfg.method = "PUT"; requestCfg.params = { statementId: stmt.id }; } else { requestCfg.method = "POST"; } if (typeof cfg.callback !== "undefined") { requestCfg.callback = cfg.callback; } return this.sendRequest(requestCfg); ``` ```javascript retrieveStatement: function (stmtId, cfg) { this.log("retrieveStatement"); var requestCfg, requestResult, callbackWrapper, lrs = this; cfg = cfg || {}; cfg.params = cfg.params || {}; requestCfg = { url: "statements", method: "GET", params: { statementId: stmtId } }; ``` -------------------------------- ### Asynchronous getStatements query with TinCan object Source: https://rusticisoftware.github.io/TinCanJS Legacy asynchronous query to get latest statements using the deprecated TinCan object. Requires a configured tincan object as shown in the basic usage example. The params object is passed through to TinCan.LRS.queryStatements; the callback receives err (null on success) and result (a TinCan.StatementsResult object). ```javascript tincan.getStatements( { // 'params' is passed through to TinCan.LRS.queryStatements params: { since: "2013-08-29 07:42:10CDT" }, callback: function (err, result) { // 'err' will be null on success if (err !== null) { // handle error return; } // handle success, 'result' is a TinCan.StatementsResult object console.log(result); } } ); ``` -------------------------------- ### init Method Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.Context.html Initializes the context with configuration options. ```APIDOC ## init Method ### Description Initializes the context with configuration options. ### Method `init(options)` ### Parameters - **options** (Object) - Optional. Configuration used to initialize the context. ### Returns None ``` -------------------------------- ### init(options) Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.Group.html Initializes the Group with provided options. ```APIDOC ## TinCan.Group.init ### Description Initializes the Group instance with configuration options. ### Method `init(options)` ### Parameters - `options` (Object) - Optional - Configuration used to initialize ### Returns - None ``` -------------------------------- ### init Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.Statement.html Initializes the statement with optional properties and configuration. ```APIDOC ## init ### Description Initializes the statement with given properties and configuration. ### Method `init([properties], [cfg])` ### Parameters - **properties** (Object, optional) - Configuration used to set properties (see constructor) - **cfg** (Object, optional) - Configuration used to initialize (see constructor) ``` -------------------------------- ### Force no-cache synchronous XHR request Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_Environment_Browser.js.html Forces a cache-busting synchronous GET request to the current URL. The comment notes that removing this made the while loop too tight to allow asynchronous events through to get handled so that the response was correctly handled. ```javascript var xhr = new XMLHttpRequest (), url = window.location + "?forcenocache=" + TinCan.Utils.getUUID() ; xhr.open("GET", url, false); xhr.send(null); ``` -------------------------------- ### init Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.Attachment.html Initializes the attachment with the provided options. ```APIDOC ## init([options]) ### Description Initializes the attachment with the provided options. ### Method `init([options])` ### Parameters - `[options]` (Object) - Optional - Configuration used to initialize. ### Defined in `src/Attachment.js:94` ``` -------------------------------- ### About.init(cfg) Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_About.js.html Initializes the About object by setting the version property if provided in the configuration. ```APIDOC ## About.init(cfg) ### Description Initializes the About instance with configuration options. ### Method `init(cfg)` ### Parameters - **cfg** (Object) - Optional - Configuration used to initialize. Supported properties: `version` (String[]). ### Behavior If the `cfg` object has own property `version` and its value is not null, the instance's `version` property is set to that value. ``` -------------------------------- ### TinCan.Activity.init(options) Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.Activity.html Initializes the activity with the provided configuration options. ```APIDOC ## init(options) ### Description Initializes the activity with the provided configuration options. ### Method `init(options)` ### Parameters - `options` (Object) - Optional - Configuration used to initialize ### Returns None. ``` -------------------------------- ### init (method) Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_State.js.html Initializes the State instance with the provided configuration, copying direct properties (id, contents, etag, contentType) from the config object and sets `updated` to false. ```APIDOC ## init (method) ### Description Initializes the State instance with the provided configuration, copying direct properties (id, contents, etag, contentType) from the config object and sets `updated` to false. ### Syntax state.init(cfg) ### Parameters - **cfg** (Object) - Optional - Configuration object used to initialize the state. ### Properties Set - **id** (String) - Set if provided in cfg. - **contents** (String) - Set if provided in cfg. - **etag** (String) - Set if provided in cfg. - **contentType** (String) - Set if provided in cfg. - **updated** (Boolean) - Set to false. ### Example ```javascript state.init({ id: "new-id", contents: "data" }); ``` ``` -------------------------------- ### init Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.AgentAccount.html Initializes the AgentAccount with a configuration options object. ```APIDOC ## init(options) ### Description Initializes the AgentAccount using the provided configuration options. ### Parameters - `[options]` (Object, optional) - Configuration used to initialize ``` -------------------------------- ### init Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.html Initializes the TinCan instance. ```APIDOC ## init ### Description Initializes the TinCan instance. ### Method init ### Request Example ```javascript tincan.init(); ``` ### Response No return value. ``` -------------------------------- ### init Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.SubStatement.html Initializes the SubStatement instance with the provided options. This method is used internally to set up the object's properties. ```APIDOC ## init ### Description Initializes the SubStatement instance with the provided options. This method is used internally to set up the object's properties. ### Method `init(options)` ### Parameters - **options** (Object) - Optional - Configuration used to initialize (see constructor) ``` -------------------------------- ### Context.init(cfg) Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_Context.js.html Initializes the context with the provided configuration. It sets direct properties (registration, revision, platform, language, extensions) and processes agent/group properties (instructor, team) by converting plain objects to TinCan.Agent or TinCan.Group instances as needed. ```APIDOC ## Context.init(cfg) ### Description Initializes the context instance with the given configuration object. Direct properties are copied directly, while instructor and team properties are converted to TinCan.Agent or TinCan.Group instances if they are not already instances. ### Method init ### Parameters - **cfg** (Object) - Optional - Configuration used to initialize the context. ### Behavior - Direct properties: registration, revision, platform, language, extensions are set if present and not null. - Agent/Group properties: instructor and team are set if present and not null. If the objectType is undefined or "Person", it is set to "Agent". If the objectType is "Agent" and the value is not a TinCan.Agent instance, it is converted to one. If the objectType is "Group" and the value is not a TinCan.Group instance, it is converted to one. - contextActivities: If provided and not null, it is used as is if it is a TinCan.ContextActivities instance; otherwise, it is converted to a TinCan.ContextActivities instance. ### Example ```javascript var context = new TinCan.Context(); context.init({ registration: "uuid", instructor: { objectType: "Agent", name: "John Doe" }, team: { objectType: "Group", name: "Team A" }, contextActivities: { parent: [{ id: "activityId" }] }, revision: "1.0", platform: "web", language: "en-US", statement: { objectType: "StatementRef", id: "statementId" }, extensions: { "http://example.com/extension": "value" } }); ``` ``` -------------------------------- ### init(options) Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.StatementRef.html Initializes the StatementRef instance with configuration options. This is used internally by the constructor but can be called directly to reinitialize. ```APIDOC ## init(options) ### Description Initializes or reinitializes the StatementRef with given options. Options include an optional ID. ### Method Instance method ### Endpoint `statementRef.init(options)` ### Parameters - **options** (Object) - Optional - Configuration object with same properties as constructor: - **id** (String) - Optional - ID of the statement to reference ### Usage Example ```javascript const ref = new TinCan.StatementRef(); ref.init({ id: 'new-id' }); ``` ``` -------------------------------- ### asVersion Method Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.Context.html Returns the context data in a specified version format. ```APIDOC ## asVersion Method ### Description Returns the context data in a specified version format. ### Method `asVersion(version)` ### Parameters - **version** (String) - Optional. The version to return. Defaults to the newest supported version. ### Returns A representation of the context in the specified version. ``` -------------------------------- ### Create a TinCan.LRS object with endpoint and credentials Source: https://rusticisoftware.github.io/TinCanJS Creates a TinCan.LRS object with endpoint, username, password, and allowFail set to false to prevent silent failures. Optionally specify the xAPI version; the default is the latest supported. Wrap in try/catch to handle setup errors. ```javascript var lrs; try { lrs = new TinCan.LRS( { endpoint: "https://cloud.scorm.com/tc/public/", username: "", password: "", allowFail: false } ); } catch (ex) { console.log("Failed to setup LRS object: ", ex); // TODO: do something with error, can't communicate with LRS } ``` -------------------------------- ### init Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.InteractionComponent.html Initializes the InteractionComponent with the provided options. ```APIDOC ## init ### Description Initializes the InteractionComponent with the provided options. ### Method `init([options])` ### Parameters - `[options]` (Object) - Optional - Configuration used to initialize. ### Defined in `src/InteractionComponent.js:58` ``` -------------------------------- ### init method: configure TinCan with options Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_TinCan.js.html Initializes a TinCan instance from a configuration object, handling URL parameters, record stores, activity, actor, context, and registration. Accepts either instances or plain objects for activity, actor, and context, converting as needed. If a URL is provided, it processes query-string parameters via _initFromQueryString. ```javascript init: function (cfg) { this.log("init"); var i; cfg = cfg || {}; if (cfg.hasOwnProperty("url") && cfg.url !== "") { this._initFromQueryString(cfg.url); } if (cfg.hasOwnProperty("recordStores") && cfg.recordStores !== undefined) { for (i = 0; i < cfg.recordStores.length; i += 1) { this.addRecordStore(cfg.recordStores[i]); } } if (cfg.hasOwnProperty("activity")) { if (cfg.activity instanceof TinCan.Activity) { this.activity = cfg.activity; } else { this.activity = new TinCan.Activity (cfg.activity); } } if (cfg.hasOwnProperty("actor")) { if (cfg.actor instanceof TinCan.Agent) { this.actor = cfg.actor; } else { this.actor = new TinCan.Agent (cfg.actor); } } if (cfg.hasOwnProperty("context")) { if (cfg.context instanceof TinCan.Context) { this.context = cfg.context; } else { this.context = new TinCan.Context (cfg.context); } } if (cfg.hasOwnProperty("registration")) { this.registration = cfg.registration; } }, ``` -------------------------------- ### ActivityDefinition.prototype.init Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_ActivityDefinition.js.html Initializes the ActivityDefinition instance with the provided configuration. This method is called by the constructor and can be used to set up the object's properties. ```APIDOC ## ActivityDefinition.prototype.init ### Description Initializes the ActivityDefinition instance with the provided configuration. This method is called by the constructor and can be used to set up the object's properties. ### Method init ### Signature `init: function (cfg)` ### Parameters - **cfg** (Object) - Optional - Configuration object used to initialize the instance. ### Returns - (undefined) - This method does not return a value. ### Example ```javascript var activityDefinition = new TinCan.ActivityDefinition(); activityDefinition.init({ name: {"en-US": "Example Activity"}, type: "http://adlnet.gov/expapi/activities/course" }); ``` ``` -------------------------------- ### _initFromQueryString: parse URL parameters for TinCan Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_TinCan.js.html Parses URL query-string parameters to populate actor, activity, and context properties. Handles 'actor' via JSON deserialization, 'activity_id' for activity, and 'activity_platform', 'registration', and 'grouping' for context. Note that 'registration' is stored both in the context and on the instance for statement queries. ```javascript _initFromQueryString: function (url) { this.log("_initFromQueryString"); var i, prop, qsParams = TinCan.Utils.parseURL(url).params, lrsProps = ["endpoint", "auth"], lrsCfg = {}, contextCfg, extended = null ; if (qsParams.hasOwnProperty("actor")) { this.log("_initFromQueryString - found actor: " + qsParams.actor); try { this.actor = TinCan.Agent.fromJSON(qsParams.actor); delete qsParams.actor; } catch (ex) { this.log("_initFromQueryString - failed to set actor: " + ex); } } if (qsParams.hasOwnProperty("activity_id")) { this.activity = new TinCan.Activity ( { id: qsParams.activity_id } ); delete qsParams.activity_id; } if ( qsParams.hasOwnProperty("activity_platform") || qsParams.hasOwnProperty("registration") || qsParams.hasOwnProperty("grouping") ) { contextCfg = {}; if (qsParams.hasOwnProperty("activity_platform")) { contextCfg.platform = qsParams.activity_platform; delete qsParams.activity_platform; } if (qsParams.hasOwnProperty("registration")) { // // stored in two locations cause we always want it in the default // context, but we also want to be able to get to it for Statement // queries // contextCfg.registration = this.registration = qsParams.registration; delete qsParams.registration; } if (qsParams.hasOwnProperty("grouping")) { contextCfg.contextActivities = {}; contextCfg.contextActivities.grouping = qsParams.grouping; delete qsParams.grouping; } this.context = new TinCan.Context (contextCfg); } // // order matters here, process the URL provided LRS last because it gets ``` -------------------------------- ### TinCan.Activity constructor Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.Activity.html Creates a new TinCan.Activity instance. ```APIDOC ## TinCan.Activity() ### Description Creates a new TinCan.Activity instance. ### Constructor `TinCan.Activity()` ### Parameters No parameters. ### Returns A new TinCan.Activity object. ``` -------------------------------- ### versions() static Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.html Returns the supported versions. ```APIDOC ## versions() static ### Description Returns the supported versions. ### Method versions ### Request Example ```javascript TinCan.versions(); ``` ### Response No return value. ``` -------------------------------- ### new TinCan.About(cfg) Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_About.js.html Creates a new About object. The constructor initializes the version property and calls init. ```APIDOC ## new TinCan.About(cfg) ### Description Creates a new instance of the TinCan.About class. ### Constructor `TinCan.About(cfg)` ### Parameters - **cfg** (Object) - Optional - Configuration object. Possible properties include `version`. - `version` (String[]) - Optional - The version information. ### Description of Behavior Initializes the object, setting the `version` property if provided. ``` -------------------------------- ### asVersion Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.InteractionComponent.html Returns the component as a versioned object. Optionally specify a version string. ```APIDOC ## asVersion ### Description Returns the component as a versioned object. Optionally specify a version string. ### Method `asVersion([version])` ### Parameters - `[version]` (String) - Optional - Version to return (defaults to newest supported). ### Defined in `src/InteractionComponent.js:80` ``` -------------------------------- ### TinCan.Agent.init Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_Agent.js.html Initializes the agent instance with the provided configuration. Handles backward compatibility for split name fields. ```APIDOC ## TinCan.Agent.init ### Description Initializes the agent instance with the provided configuration. Handles backward compatibility for split name fields. ### Method init ### Endpoint init(cfg) ### Parameters #### Configuration Object - **cfg** (Object) - Optional - Configuration used to initialize the agent. - **name** (String) - Optional - The full name of the agent. - **mbox** (String) - Optional - The email address (mailto: URI) of the agent. - **mbox_sha1sum** (String) - Optional - The SHA1 hash of the mailto: URI. - **openid** (String) - Optional - An openID for the agent. - **account** (TinCan.AgentAccount) - Optional - An account object for the agent. - **firstName** (Array) - Optional - First name(s) for backward compatibility; first element used as name. - **lastName** (Array) - Optional - Last name(s) for backward compatibility; first element used as name. - **givenName** (Array) - Optional - Given name(s) for backward compatibility; first element used as name. - **familyName** (Array) - Optional - Family name(s) for backward compatibility; first element used as name. ### Response #### Success Response No return value; initializes the agent's properties. #### Response Example ```javascript agent.init({ name: "John Doe", mbox: "mailto:john@example.com" }); ``` ``` -------------------------------- ### TinCan.Activity class definition (src/Activity.js) Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/files/src_Activity.js.html Full source of the TinCan.Activity class. Defines the constructor, prototype methods (log, init, toString, asVersion), and the static fromJSON method. The constructor initializes objectType to 'Activity', id to null, and definition to null, then calls init(cfg). The init method accepts a configuration object with 'id' and 'definition' properties, creating a TinCan.ActivityDefinition if needed. toString returns the definition string, the id, or 'Activity: unidentified'. asVersion returns an object with id, objectType, and optionally definition. fromJSON parses a JSON string and returns a new Activity instance. ```JavaScript /* Copyright 2012 Rustici Software Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /** TinCan client library @module TinCan @submodule TinCan.Activity **/ (function () { "use strict"; /** @class TinCan.Activity @constructor */ var Activity = TinCan.Activity = function (cfg) { this.log("constructor"); /** @property objectType @type String @default Activity */ this.objectType = "Activity"; /** @property id @type String */ this.id = null; /** @property definition @type TinCan.ActivityDefinition */ this.definition = null; this.init(cfg); }; Activity.prototype = { /** @property LOG_SRC */ LOG_SRC: "Activity", /** @method log */ log: TinCan.prototype.log, /** @method init @param {Object} [options] Configuration used to initialize */ init: function (cfg) { this.log("init"); var i, directProps = [ "id" ] ; cfg = cfg || {}; if (cfg.hasOwnProperty("definition")) { if (cfg.definition instanceof TinCan.ActivityDefinition) { this.definition = cfg.definition; } else { this.definition = new TinCan.ActivityDefinition (cfg.definition); } } for (i = 0; i < directProps.length; i += 1) { if (cfg.hasOwnProperty(directProps[i]) && cfg[directProps[i]] !== null) { this[directProps[i]] = cfg[directProps[i]]; } } }, /** @method toString @return {String} String representation of the activity */ toString: function (lang) { this.log("toString"); var defString = ""; if (this.definition !== null) { defString = this.definition.toString(lang); if (defString !== "") { return defString; } } if (this.id !== null) { return this.id; } return "Activity: unidentified"; }, /** @method asVersion @param {String} [version] Version to return (defaults to newest supported) */ asVersion: function (version) { this.log("asVersion"); var result = { id: this.id, objectType: this.objectType }; version = version || TinCan.versions()[0]; if (this.definition !== null) { result.definition = this.definition.asVersion(version); } return result; } }; /** @method fromJSON @return {Object} Activity @static */ Activity.fromJSON = function (activityJSON) { Activity.prototype.log("fromJSON"); var _activity = JSON.parse(activityJSON); return new Activity(_activity); }; }()); ``` -------------------------------- ### TinCan.Verb.init(options) Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.Verb.html Initializes the verb with the provided options. This method is called by the constructor. ```APIDOC ## init(options) ### Description Initializes the verb with the provided options. This method is called by the constructor. ### Method init ### Parameters - `[options]` (Object) - Optional - Configuration used to initialize ### Returns None ### Example ```javascript var verb = new TinCan.Verb(); verb.init({ id: "http://example.com/verb" }); ``` ``` -------------------------------- ### asVersion Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.Statement.html Returns the statement in a specified version format. ```APIDOC ## asVersion ### Description Returns the statement as a versioned JSON representation. ### Method `asVersion([version])` ### Parameters - **version** (String, optional) - Version to return (defaults to newest supported) ``` -------------------------------- ### asVersion(version) Source: https://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.StatementRef.html Returns the statement reference as a version-specific string. If no version is provided, the newest supported version is used. ```APIDOC ## asVersion(version) ### Description Converts the StatementRef to a string for a specified version. If no version is supplied, the default (newest) is used. ### Method Instance method ### Endpoint `statementRef.asVersion(version)` ### Parameters - **version** (String) - Optional - Version to return (defaults to newest supported) ### Returns - **String** - The statement reference in the specified version string format. ### Usage Example ```javascript const ref = new TinCan.StatementRef({ id: 'some-id' }); ref.asVersion(); // returns version string ``` ```