build/tincan.js
function (cfg) {
            this.log("queryStatements");
            var requestCfg,
                requestResult,
                callbackWrapper,
                lrs = this;

            cfg = cfg || {};
            cfg.params = cfg.params || {};

            //
            // if they misconfigured (possibly due to version mismatches) the
            // query then don't try to send a request at all, rather than give
            // them invalid results
            //
            try {
                requestCfg = this._queryStatementsRequestCfg(cfg);

                if (cfg.params.attachments) {
                    requestCfg.expectMultipart = true;
                }
            }
            catch (ex) {
                this.log("[error] Query statements failed - " + ex);
                if (typeof cfg.callback !== "undefined") {
                    cfg.callback(ex, {});
                }

                return {
                    err: ex,
                    statementsResult: null
                };
            }

            if (typeof cfg.callback !== "undefined") {
                callbackWrapper = function (err, xhr) {
                    var result = xhr,
                        parsedResponse,
                        boundary,
                        statements,
                        attachmentMap = {},
                        i;

                    if (err === null) {
                        if (! cfg.params.attachments) {
                            result = TinCan.StatementsResult.fromJSON(xhr.responseText);
                        }
                        else {
                            boundary = xhr.getResponseHeader("Content-Type").split("boundary=")[1];

                            parsedResponse = lrs._parseMultipart(boundary, xhr.response);
                            statements = JSON.parse(parsedResponse[0].body);
                            for (i = 1; i < parsedResponse.length; i += 1) {
                                attachmentMap[parsedResponse[i].headers["X-Experience-API-Hash"]] = parsedResponse[i].body;
                            }

                            lrs._assignAttachmentContent(statements.statements, attachmentMap);
                            result = new TinCan.StatementsResult({ statements: statements.statements });

                            for (i = 0; i < result.statements.length; i += 1) {
                                if (! (result.statements[i] instanceof TinCan.Statement)) {
                                    result.statements[i] = new TinCan.Statement(result.statements[i]);
                                }
                            }
                        }
                    }

                    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;
        }
function (cfg) {
            this.log("queryStatements");
            var requestCfg,
                requestResult,
                callbackWrapper,
                lrs = this;

            cfg = cfg || {};
            cfg.params = cfg.params || {};

            //
            // if they misconfigured (possibly due to version mismatches) the
            // query then don't try to send a request at all, rather than give
            // them invalid results
            //
            try {
                requestCfg = this._queryStatementsRequestCfg(cfg);

                if (cfg.params.attachments) {
                    requestCfg.expectMultipart = true;
                }
            }
            catch (ex) {
                this.log("[error] Query statements failed - " + ex);
                if (typeof cfg.callback !== "undefined") {
                    cfg.callback(ex, {});
                }

                return {
                    err: ex,
                    statementsResult: null
                };
            }

            if (typeof cfg.callback !== "undefined") {
                callbackWrapper = function (err, xhr) {
                    var result = xhr,
                        parsedResponse,
                        boundary,
                        statements,
                        attachmentMap = {},
                        i;

                    if (err === null) {
                        if (! cfg.params.attachments) {
                            result = TinCan.StatementsResult.fromJSON(xhr.responseText);
                        }
                        else {
                            boundary = xhr.getResponseHeader("Content-Type").split("boundary=")[1];

                            parsedResponse = lrs._parseMultipart(boundary, xhr.response);
                            statements = JSON.parse(parsedResponse[0].body);
                            for (i = 1; i < parsedResponse.length; i += 1) {
                                attachmentMap[parsedResponse[i].headers["X-Experience-API-Hash"]] = parsedResponse[i].body;
                            }

                            lrs._assignAttachmentContent(statements.statements, attachmentMap);
                            result = new TinCan.StatementsResult({ statements: statements.statements });

                            for (i = 0; i < result.statements.length; i += 1) {
                                if (! (result.statements[i] instanceof TinCan.Statement)) {
                                    result.statements[i] = new TinCan.Statement(result.statements[i]);
                                }
                            }
                        }
                    }

                    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;
        }
function ( cfg ) { this . log ( "queryStatements" ) ; var requestCfg , requestResult , callbackWrapper , lrs = this ; cfg = cfg || { } ; cfg . params = cfg . params || { } ; // // if they misconfigured (possibly due to version mismatches) the // query then don't try to send a request at all, rather than give // them invalid results // try { requestCfg = this . _queryStatementsRequestCfg ( cfg ) ; if ( cfg . params . attachments ) { requestCfg . expectMultipart = true ; } } catch ( ex ) { this . log ( "[error] Query statements failed - " + ex ) ; if ( typeof cfg . callback !== "undefined" ) { cfg . callback ( ex , { } ) ; } return { err : ex , statementsResult : null } ; } if ( typeof cfg . callback !== "undefined" ) { callbackWrapper = function ( err , xhr ) { var result = xhr , parsedResponse , boundary , statements , attachmentMap = { } , i ; if ( err === null ) { if ( ! cfg . params . attachments ) { result = TinCan . StatementsResult . fromJSON ( xhr . responseText ) ; } else { boundary = xhr . getResponseHeader ( "Content-Type" ) . split ( "boundary=" ) [ 1 ] ; parsedResponse = lrs . _parseMultipart ( boundary , xhr . response ) ; statements = JSON . parse ( parsedResponse [ 0 ] . body ) ; for ( i = 1 ; i < parsedResponse . length ; i += 1 ) { attachmentMap [ parsedResponse [ i ] . headers [ "X-Experience-API-Hash" ] ] = parsedResponse [ i ] . body ; } lrs . _assignAttachmentContent ( statements . statements , attachmentMap ) ; result = new TinCan . StatementsResult ( { statements : statements . statements } ) ; for ( i = 0 ; i < result . statements . length ; i += 1 ) { if ( ! ( result . statements [ i ] instanceof TinCan . Statement ) ) { result . statements [ i ] = new TinCan . Statement ( result . statements [ i ] ) ; } } } } 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 ; }
Fetch a set of statements, when used from a browser sends to the endpoint using the
RESTful interface.  Use a callback to make the call asynchronous.

@method queryStatements
@param {Object} [cfg] Configuration used to query
@param {Object} [cfg.params] Query parameters
@param {TinCan.Agent|TinCan.Group} [cfg.params.agent] Agent matches 'actor' or 'object'
@param {TinCan.Verb|String} [cfg.params.verb] Verb (or verb ID) to query on
@param {TinCan.Activity|String} [cfg.params.activity] Activity (or activity ID) to query on
@param {String} [cfg.params.registration] Registration UUID
@param {Boolean} [cfg.params.related_activities] Match related activities
@param {Boolean} [cfg.params.related_agents] Match related agents
@param {String} [cfg.params.since] Match statements stored since specified timestamp
@param {String} [cfg.params.until] Match statements stored at or before specified timestamp
@param {Integer} [cfg.params.limit] Number of results to retrieve
@param {String} [cfg.params.format] One of "ids", "exact", "canonical" (default: "exact")
@param {Boolean} [cfg.params.ascending] Return results in ascending order of stored time

@param {TinCan.Agent} [cfg.params.actor] (Removed in 1.0.0, use 'agent' instead) Agent matches 'actor'
@param {TinCan.Activity|TinCan.Agent|TinCan.Statement} [cfg.params.target] (Removed in 1.0.0, use 'activity' or 'agent' instead) Activity, Agent, or Statement matches 'object'
@param {TinCan.Agent} [cfg.params.instructor] (Removed in 1.0.0, use 'agent' + 'related_agents' instead) Agent matches 'context:instructor'
@param {Boolean} [cfg.params.context] (Removed in 1.0.0, use 'activity' instead) When filtering on target, include statements with matching context
@param {Boolean} [cfg.params.authoritative] (Removed in 1.0.0) Get authoritative results
@param {Boolean} [cfg.params.sparse] (Removed in 1.0.0, use 'format' instead) Get sparse results

@param {Function} [cfg.callback] Callback to execute on completion
@param {String|null} cfg.callback.err Error status or null if succcess
@param {TinCan.StatementsResult|XHR} cfg.callback.response Receives a StatementsResult argument
@return {Object} Request result
Fetch a set of statements when used from a browser sends to the endpoint using the RESTful interface . Use a callback to make the call asynchronous .