build/tincan.js
function (key, cfg) {
            this.log("retrieveAgentProfile");
            var requestCfg = {},
                requestResult,
                callbackWrapper,
                requestHeaders,
                self = this;

            requestHeaders = cfg.requestHeaders || {};

            requestCfg = {
                method: "GET",
                params: {
                    profileId: key
                },
                ignore404: true,
                headers: requestHeaders
            };

            if (this.version === "0.9") {
                requestCfg.url = "actors/profile";
                requestCfg.params.actor = JSON.stringify(cfg.agent.asVersion(this.version));
            }
            else {
                requestCfg.url = "agents/profile";
                requestCfg.params.agent = JSON.stringify(cfg.agent.asVersion(this.version));
            }
            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.AgentProfile(
                                {
                                    id: key,
                                    agent: cfg.agent,
                                    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("retrieveAgentProfile - failed to deserialize JSON: " + ex);
                                }
                            }
                        }
                    }

                    cfg.callback(err, result);
                };
                requestCfg.callback = callbackWrapper;
            }

            requestResult = this.sendRequest(requestCfg);
            if (! callbackWrapper) {
                requestResult.profile = null;
                if (requestResult.err === null && requestResult.xhr.status !== 404) {
                    requestResult.profile = new TinCan.AgentProfile(
                        {
                            id: key,
                            agent: cfg.agent,
                            contents: requestResult.xhr.responseText
                        }
                    );
                    if (typeof requestResult.xhr.getResponseHeader !== "undefined" && requestResult.xhr.getResponseHeader("ETag") !== null && requestResult.xhr.getResponseHeader("ETag") !== "") {
                        requestResult.profile.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.profile.etag = "\"" + TinCan.Utils.getSHA1String(requestResult.xhr.responseText) + "\"";
                    }
                    if (typeof requestResult.xhr.contentType !== "undefined") {
                        // most likely an XDomainRequest which has .contentType
                        // for the ones that it supports
                        requestResult.profile.contentType = requestResult.xhr.contentType;
                    }
                    else if (typeof requestResult.xhr.getResponseHeader !== "undefined" && requestResult.xhr.getResponseHeader("Content-Type") !== null && requestResult.xhr.getResponseHeader("Content-Type") !== "") {
                        requestResult.profile.contentType = requestResult.xhr.getResponseHeader("Content-Type");
                    }
                    if (TinCan.Utils.isApplicationJSON(requestResult.profile.contentType)) {
                        try {
                            requestResult.profile.contents = JSON.parse(requestResult.profile.contents);
                        } catch (ex) {
                            this.log("retrieveAgentProfile - failed to deserialize JSON: " + ex);
                        }
                    }
                }
            }

            return requestResult;
        }
function (key, cfg) {
            this.log("retrieveAgentProfile");
            var requestCfg = {},
                requestResult,
                callbackWrapper,
                requestHeaders,
                self = this;

            requestHeaders = cfg.requestHeaders || {};

            requestCfg = {
                method: "GET",
                params: {
                    profileId: key
                },
                ignore404: true,
                headers: requestHeaders
            };

            if (this.version === "0.9") {
                requestCfg.url = "actors/profile";
                requestCfg.params.actor = JSON.stringify(cfg.agent.asVersion(this.version));
            }
            else {
                requestCfg.url = "agents/profile";
                requestCfg.params.agent = JSON.stringify(cfg.agent.asVersion(this.version));
            }
            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.AgentProfile(
                                {
                                    id: key,
                                    agent: cfg.agent,
                                    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("retrieveAgentProfile - failed to deserialize JSON: " + ex);
                                }
                            }
                        }
                    }

                    cfg.callback(err, result);
                };
                requestCfg.callback = callbackWrapper;
            }

            requestResult = this.sendRequest(requestCfg);
            if (! callbackWrapper) {
                requestResult.profile = null;
                if (requestResult.err === null && requestResult.xhr.status !== 404) {
                    requestResult.profile = new TinCan.AgentProfile(
                        {
                            id: key,
                            agent: cfg.agent,
                            contents: requestResult.xhr.responseText
                        }
                    );
                    if (typeof requestResult.xhr.getResponseHeader !== "undefined" && requestResult.xhr.getResponseHeader("ETag") !== null && requestResult.xhr.getResponseHeader("ETag") !== "") {
                        requestResult.profile.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.profile.etag = "\"" + TinCan.Utils.getSHA1String(requestResult.xhr.responseText) + "\"";
                    }
                    if (typeof requestResult.xhr.contentType !== "undefined") {
                        // most likely an XDomainRequest which has .contentType
                        // for the ones that it supports
                        requestResult.profile.contentType = requestResult.xhr.contentType;
                    }
                    else if (typeof requestResult.xhr.getResponseHeader !== "undefined" && requestResult.xhr.getResponseHeader("Content-Type") !== null && requestResult.xhr.getResponseHeader("Content-Type") !== "") {
                        requestResult.profile.contentType = requestResult.xhr.getResponseHeader("Content-Type");
                    }
                    if (TinCan.Utils.isApplicationJSON(requestResult.profile.contentType)) {
                        try {
                            requestResult.profile.contents = JSON.parse(requestResult.profile.contents);
                        } catch (ex) {
                            this.log("retrieveAgentProfile - failed to deserialize JSON: " + ex);
                        }
                    }
                }
            }

            return requestResult;
        }
function ( key , cfg ) { this . log ( "retrieveAgentProfile" ) ; var requestCfg = { } , requestResult , callbackWrapper , requestHeaders , self = this ; requestHeaders = cfg . requestHeaders || { } ; requestCfg = { method : "GET" , params : { profileId : key } , ignore404 : true , headers : requestHeaders } ; if ( this . version === "0.9" ) { requestCfg . url = "actors/profile" ; requestCfg . params . actor = JSON . stringify ( cfg . agent . asVersion ( this . version ) ) ; } else { requestCfg . url = "agents/profile" ; requestCfg . params . agent = JSON . stringify ( cfg . agent . asVersion ( this . version ) ) ; } 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 . AgentProfile ( { id : key , agent : cfg . agent , 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 ( "retrieveAgentProfile - failed to deserialize JSON: " + ex ) ; } } } } cfg . callback ( err , result ) ; } ; requestCfg . callback = callbackWrapper ; } requestResult = this . sendRequest ( requestCfg ) ; if ( ! callbackWrapper ) { requestResult . profile = null ; if ( requestResult . err === null && requestResult . xhr . status !== 404 ) { requestResult . profile = new TinCan . AgentProfile ( { id : key , agent : cfg . agent , contents : requestResult . xhr . responseText } ) ; if ( typeof requestResult . xhr . getResponseHeader !== "undefined" && requestResult . xhr . getResponseHeader ( "ETag" ) !== null && requestResult . xhr . getResponseHeader ( "ETag" ) !== "" ) { requestResult . profile . 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 . profile . etag = "\"" + TinCan . Utils . getSHA1String ( requestResult . xhr . responseText ) + "\"" ; } if ( typeof requestResult . xhr . contentType !== "undefined" ) { // most likely an XDomainRequest which has .contentType // for the ones that it supports requestResult . profile . contentType = requestResult . xhr . contentType ; } else if ( typeof requestResult . xhr . getResponseHeader !== "undefined" && requestResult . xhr . getResponseHeader ( "Content-Type" ) !== null && requestResult . xhr . getResponseHeader ( "Content-Type" ) !== "" ) { requestResult . profile . contentType = requestResult . xhr . getResponseHeader ( "Content-Type" ) ; } if ( TinCan . Utils . isApplicationJSON ( requestResult . profile . contentType ) ) { try { requestResult . profile . contents = JSON . parse ( requestResult . profile . contents ) ; } catch ( ex ) { this . log ( "retrieveAgentProfile - failed to deserialize JSON: " + ex ) ; } } } } return requestResult ; }
Retrieve an agent profile value, when used from a browser sends to the endpoint using the RESTful interface.

@method retrieveAgentProfile
@param {String} key Key of agent profile to retrieve
@param {Object} cfg Configuration options
@param {TinCan.Agent} cfg.agent Agent in document identifier
@param {Function} [cfg.callback] Callback to execute on completion
@param {Object} [cfg.requestHeaders] Optional object containing additional headers to add to request
@return {Object} Value retrieved
Retrieve an agent profile value when used from a browser sends to the endpoint using the RESTful interface .