Skip to content

Commit

Permalink
Build 0.32.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjmiller committed Jan 6, 2015
1 parent 2a204f3 commit 292c710
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tincan",
"version": "0.31.1",
"version": "0.32.0",
"homepage": "http://rusticisoftware.github.com/TinCanJS/",
"authors": [
"Brian J. Miller <[email protected]>"
Expand Down
6 changes: 3 additions & 3 deletions build/tincan-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/tincan-min.map

Large diffs are not rendered by default.

158 changes: 150 additions & 8 deletions build/tincan-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"0.31.1";
"0.32.0";
/*
CryptoJS v3.0.2
code.google.com/p/crypto-js
Expand Down Expand Up @@ -980,6 +980,7 @@ var TinCan;
defaults to 'registration' property if empty
@param {String} [cfg.lastSHA1] SHA1 of the previously seen existing state
@param {String} [cfg.contentType] Content-Type to specify in headers
@param {Boolean} [cfg.overwriteJSON] If the Content-Type is JSON, should a PUT be used?
@param {Function} [cfg.callback] Function to run with state
*/
setState: function (key, val, cfg) {
Expand Down Expand Up @@ -1016,6 +1017,9 @@ var TinCan;
}
if (typeof cfg.contentType !== "undefined") {
queryCfg.contentType = cfg.contentType;
if ((typeof cfg.overwriteJSON !== "undefined") && (! cfg.overwriteJSON) && (TinCan.Utils.isApplicationJSON(cfg.contentType))) {
queryCfg.method = "POST";
}
}
if (typeof cfg.callback !== "undefined") {
queryCfg.callback = cfg.callback;
Expand Down Expand Up @@ -1127,6 +1131,7 @@ var TinCan;
defaults to 'activity' property if empty
@param {String} [cfg.lastSHA1] SHA1 of the previously seen existing profile
@param {String} [cfg.contentType] Content-Type to specify in headers
@param {Boolean} [cfg.overwriteJSON] If the Content-Type is JSON, should a PUT be used?
@param {Function} [cfg.callback] Function to run with activity profile
*/
setActivityProfile: function (key, val, cfg) {
Expand Down Expand Up @@ -1159,6 +1164,9 @@ var TinCan;
}
if (typeof cfg.contentType !== "undefined") {
queryCfg.contentType = cfg.contentType;
if ((typeof cfg.overwriteJSON !== "undefined") && (! cfg.overwriteJSON) && (TinCan.Utils.isApplicationJSON(cfg.contentType))) {
queryCfg.method = "POST";
}
}

return lrs.saveActivityProfile(key, val, queryCfg);
Expand Down Expand Up @@ -1256,6 +1264,7 @@ var TinCan;
defaults to 'actor' property if empty
@param {String} [cfg.lastSHA1] SHA1 of the previously seen existing profile
@param {String} [cfg.contentType] Content-Type to specify in headers
@param {Boolean} [cfg.overwriteJSON] If the Content-Type is JSON, should a PUT be used?
@param {Function} [cfg.callback] Function to run with agent profile
*/
setAgentProfile: function (key, val, cfg) {
Expand Down Expand Up @@ -1288,6 +1297,9 @@ var TinCan;
}
if (typeof cfg.contentType !== "undefined") {
queryCfg.contentType = cfg.contentType;
if ((typeof cfg.overwriteJSON !== "undefined") && (! cfg.overwriteJSON) && (TinCan.Utils.isApplicationJSON(cfg.contentType))) {
queryCfg.method = "POST";
}
}

return lrs.saveAgentProfile(key, val, queryCfg);
Expand Down Expand Up @@ -1475,6 +1487,95 @@ TinCan client library
pad(d.getUTCMilliseconds(), 3) + "Z";
},

/**
@method convertISO8601DurationToMilliseconds
@static
@param {String} ISO8601Duration Duration in ISO8601 format
@return {Int} Duration in milliseconds
Note: does not handle input strings with years, months and days
*/
convertISO8601DurationToMilliseconds: function (ISO8601Duration) {
var isValueNegative = (ISO8601Duration.indexOf("-") >= 0),
indexOfT = ISO8601Duration.indexOf("T"),
indexOfH = ISO8601Duration.indexOf("H"),
indexOfM = ISO8601Duration.indexOf("M"),
indexOfS = ISO8601Duration.indexOf("S"),
hours,
minutes,
seconds,
durationInMilliseconds;

if ((indexOfT === -1) || ((indexOfM !== -1) && (indexOfM < indexOfT)) || (ISO8601Duration.indexOf("D") !== -1) || (ISO8601Duration.indexOf("Y") !== -1)) {
throw new Error("ISO 8601 timestamps including years, months and/or days are not currently supported");
}

if (indexOfH === -1) {
indexOfH = indexOfT;
hours = 0;
}
else {
hours = parseInt(ISO8601Duration.slice(indexOfT + 1, indexOfH), 10);
}

if (indexOfM === -1) {
indexOfM = indexOfT;
minutes = 0;
}
else {
minutes = parseInt(ISO8601Duration.slice(indexOfH + 1, indexOfM), 10);
}

seconds = parseFloat(ISO8601Duration.slice(indexOfM + 1, indexOfS));

durationInMilliseconds = parseInt((((((hours * 60) + minutes) * 60) + seconds) * 1000), 10);
if (isNaN(durationInMilliseconds)){
durationInMilliseconds = 0;
}
if (isValueNegative) {
durationInMilliseconds = durationInMilliseconds * -1;
}

return durationInMilliseconds;
},

/**
@method convertMillisecondsToISO8601Duration
@static
@param {Int} inputMilliseconds Duration in milliseconds
@return {String} Duration in ISO8601 format
*/
convertMillisecondsToISO8601Duration: function (inputMilliseconds) {
var hours,
minutes,
seconds,
i_inputMilliseconds = parseInt(inputMilliseconds, 10),
inputIsNegative = "",
rtnStr = "";

if (i_inputMilliseconds < 0) {
inputIsNegative = "-";
i_inputMilliseconds = i_inputMilliseconds * -1;
}

hours = parseInt(((i_inputMilliseconds) / 3600000), 10);
minutes = parseInt((((i_inputMilliseconds) % 3600000) / 60000), 10);
seconds = (((i_inputMilliseconds) % 3600000) % 60000) / 1000;

rtnStr = inputIsNegative + "PT";
if (hours > 0) {
rtnStr += hours + "H";
}

if (minutes > 0) {
rtnStr += minutes + "M";
}

rtnStr += seconds + "S";

return rtnStr;
},

/**
@method getSHA1String
@static
Expand Down Expand Up @@ -2459,7 +2560,7 @@ TinCan client library
else {
requestParams.agent = JSON.stringify(cfg.agent.asVersion(this.version));
}
if (typeof cfg.registration !== "undefined") {
if ((typeof cfg.registration !== "undefined") && (cfg.registration !== null)) {
if (this.version === "0.9") {
requestParams.registrationId = cfg.registration;
}
Expand Down Expand Up @@ -2575,6 +2676,7 @@ TinCan client library
@param {String} [cfg.registration] Registration
@param {String} [cfg.lastSHA1] SHA1 of the previously seen existing state
@param {String} [cfg.contentType] Content-Type to specify in headers (defaults to 'application/octet-stream')
@param {String} [cfg.method] Method to use. Default: PUT
@param {Function} [cfg.callback] Callback to execute on completion
*/
saveState: function (key, val, cfg) {
Expand All @@ -2590,6 +2692,10 @@ TinCan client library
val = JSON.stringify(val);
}

if (typeof cfg.method === "undefined" || cfg.method !== "POST") {
cfg.method = "PUT";
}

requestParams = {
stateId: key,
activityId: cfg.activity.id
Expand All @@ -2600,7 +2706,7 @@ TinCan client library
else {
requestParams.agent = JSON.stringify(cfg.agent.asVersion(this.version));
}
if (typeof cfg.registration !== "undefined") {
if ((typeof cfg.registration !== "undefined") && (cfg.registration !== null)) {
if (this.version === "0.9") {
requestParams.registrationId = cfg.registration;
}
Expand All @@ -2611,7 +2717,7 @@ TinCan client library

requestCfg = {
url: "activities/state",
method: "PUT",
method: cfg.method,
params: requestParams,
data: val,
headers: {
Expand Down Expand Up @@ -2657,7 +2763,7 @@ TinCan client library
if (key !== null) {
requestParams.stateId = key;
}
if (typeof cfg.registration !== "undefined") {
if ((typeof cfg.registration !== "undefined") && (cfg.registration !== null)) {
if (this.version === "0.9") {
requestParams.registrationId = cfg.registration;
}
Expand Down Expand Up @@ -2803,6 +2909,7 @@ TinCan client library
@param {Object} cfg.activity TinCan.Activity
@param {String} [cfg.lastSHA1] SHA1 of the previously seen existing profile
@param {String} [cfg.contentType] Content-Type to specify in headers (defaults to 'application/octet-stream')
@param {String} [cfg.method] Method to use. Default: PUT
@param {Function} [cfg.callback] Callback to execute on completion
*/
saveActivityProfile: function (key, val, cfg) {
Expand All @@ -2813,13 +2920,17 @@ TinCan client library
cfg.contentType = "application/octet-stream";
}

if (typeof cfg.method === "undefined" || cfg.method !== "POST") {
cfg.method = "PUT";
}

if (typeof val === "object" && TinCan.Utils.isApplicationJSON(cfg.contentType)) {
val = JSON.stringify(val);
}

requestCfg = {
url: "activities/profile",
method: "PUT",
method: cfg.method,
params: {
profileId: key,
activityId: cfg.activity.id
Expand Down Expand Up @@ -3005,6 +3116,7 @@ TinCan client library
@param {Object} cfg.agent TinCan.Agent
@param {String} [cfg.lastSHA1] SHA1 of the previously seen existing profile
@param {String} [cfg.contentType] Content-Type to specify in headers (defaults to 'application/octet-stream')
@param {String} [cfg.method] Method to use. Default: PUT
@param {Function} [cfg.callback] Callback to execute on completion
*/
saveAgentProfile: function (key, val, cfg) {
Expand All @@ -3015,12 +3127,16 @@ TinCan client library
cfg.contentType = "application/octet-stream";
}

if (typeof cfg.method === "undefined" || cfg.method !== "POST") {
cfg.method = "PUT";
}

if (typeof val === "object" && TinCan.Utils.isApplicationJSON(cfg.contentType)) {
val = JSON.stringify(val);
}

requestCfg = {
method: "PUT",
method: cfg.method,
params: {
profileId: key
},
Expand Down Expand Up @@ -5101,7 +5217,6 @@ TinCan client library
"revision",
"platform",
"language",
"statement",
"extensions"
],
agentGroupProps = [
Expand Down Expand Up @@ -5147,6 +5262,24 @@ TinCan client library
this.contextActivities = new TinCan.ContextActivities(cfg.contextActivities);
}
}

if (cfg.hasOwnProperty("statement") && cfg.statement !== null) {
if (cfg.statement instanceof TinCan.StatementRef) {
this.statement = cfg.statement;
}
else if (cfg.statement instanceof TinCan.SubStatement) {
this.statement = cfg.statement;
}
else if (cfg.statement.objectType === "StatementRef") {
this.statement = new TinCan.StatementRef(cfg.statement);
}
else if (cfg.statement.objectType === "SubStatement") {
this.statement = new TinCan.SubStatement(cfg.statement);
}
else {
this.log("Unable to parse statement.context.statement property.");
}
}
},

/**
Expand All @@ -5173,6 +5306,11 @@ TinCan client library

version = version || TinCan.versions()[0];

if (this.statement instanceof TinCan.SubStatement && version !== "0.9" && version !== "0.95") {
this.log("[error] version does not support SubStatements in the 'statement' property: " + version);
throw new Error(version + " does not support SubStatements in the 'statement' property");
}

for (i = 0; i < optionalDirectProps.length; i += 1) {
if (this[optionalDirectProps[i]] !== null) {
result[optionalDirectProps[i]] = this[optionalDirectProps[i]];
Expand Down Expand Up @@ -5562,6 +5700,10 @@ TinCan client library
result.object = this.target.asVersion(version);
}

if (version === "0.9") {
result.objectType = "Statement";
}

return result;
}
};
Expand Down
Loading

0 comments on commit 292c710

Please sign in to comment.