Skip to content

Commit 292c710

Browse files
committed
Build 0.32.0
1 parent 2a204f3 commit 292c710

File tree

6 files changed

+307
-23
lines changed

6 files changed

+307
-23
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tincan",
3-
"version": "0.31.1",
3+
"version": "0.32.0",
44
"homepage": "http://rusticisoftware.github.com/TinCanJS/",
55
"authors": [
66
"Brian J. Miller <brian.miller@scorm.com>"

build/tincan-min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/tincan-min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/tincan-node.js

Lines changed: 150 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"0.31.1";
1+
"0.32.0";
22
/*
33
CryptoJS v3.0.2
44
code.google.com/p/crypto-js
@@ -980,6 +980,7 @@ var TinCan;
980980
defaults to 'registration' property if empty
981981
@param {String} [cfg.lastSHA1] SHA1 of the previously seen existing state
982982
@param {String} [cfg.contentType] Content-Type to specify in headers
983+
@param {Boolean} [cfg.overwriteJSON] If the Content-Type is JSON, should a PUT be used?
983984
@param {Function} [cfg.callback] Function to run with state
984985
*/
985986
setState: function (key, val, cfg) {
@@ -1016,6 +1017,9 @@ var TinCan;
10161017
}
10171018
if (typeof cfg.contentType !== "undefined") {
10181019
queryCfg.contentType = cfg.contentType;
1020+
if ((typeof cfg.overwriteJSON !== "undefined") && (! cfg.overwriteJSON) && (TinCan.Utils.isApplicationJSON(cfg.contentType))) {
1021+
queryCfg.method = "POST";
1022+
}
10191023
}
10201024
if (typeof cfg.callback !== "undefined") {
10211025
queryCfg.callback = cfg.callback;
@@ -1127,6 +1131,7 @@ var TinCan;
11271131
defaults to 'activity' property if empty
11281132
@param {String} [cfg.lastSHA1] SHA1 of the previously seen existing profile
11291133
@param {String} [cfg.contentType] Content-Type to specify in headers
1134+
@param {Boolean} [cfg.overwriteJSON] If the Content-Type is JSON, should a PUT be used?
11301135
@param {Function} [cfg.callback] Function to run with activity profile
11311136
*/
11321137
setActivityProfile: function (key, val, cfg) {
@@ -1159,6 +1164,9 @@ var TinCan;
11591164
}
11601165
if (typeof cfg.contentType !== "undefined") {
11611166
queryCfg.contentType = cfg.contentType;
1167+
if ((typeof cfg.overwriteJSON !== "undefined") && (! cfg.overwriteJSON) && (TinCan.Utils.isApplicationJSON(cfg.contentType))) {
1168+
queryCfg.method = "POST";
1169+
}
11621170
}
11631171

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

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

1490+
/**
1491+
@method convertISO8601DurationToMilliseconds
1492+
@static
1493+
@param {String} ISO8601Duration Duration in ISO8601 format
1494+
@return {Int} Duration in milliseconds
1495+
1496+
Note: does not handle input strings with years, months and days
1497+
*/
1498+
convertISO8601DurationToMilliseconds: function (ISO8601Duration) {
1499+
var isValueNegative = (ISO8601Duration.indexOf("-") >= 0),
1500+
indexOfT = ISO8601Duration.indexOf("T"),
1501+
indexOfH = ISO8601Duration.indexOf("H"),
1502+
indexOfM = ISO8601Duration.indexOf("M"),
1503+
indexOfS = ISO8601Duration.indexOf("S"),
1504+
hours,
1505+
minutes,
1506+
seconds,
1507+
durationInMilliseconds;
1508+
1509+
if ((indexOfT === -1) || ((indexOfM !== -1) && (indexOfM < indexOfT)) || (ISO8601Duration.indexOf("D") !== -1) || (ISO8601Duration.indexOf("Y") !== -1)) {
1510+
throw new Error("ISO 8601 timestamps including years, months and/or days are not currently supported");
1511+
}
1512+
1513+
if (indexOfH === -1) {
1514+
indexOfH = indexOfT;
1515+
hours = 0;
1516+
}
1517+
else {
1518+
hours = parseInt(ISO8601Duration.slice(indexOfT + 1, indexOfH), 10);
1519+
}
1520+
1521+
if (indexOfM === -1) {
1522+
indexOfM = indexOfT;
1523+
minutes = 0;
1524+
}
1525+
else {
1526+
minutes = parseInt(ISO8601Duration.slice(indexOfH + 1, indexOfM), 10);
1527+
}
1528+
1529+
seconds = parseFloat(ISO8601Duration.slice(indexOfM + 1, indexOfS));
1530+
1531+
durationInMilliseconds = parseInt((((((hours * 60) + minutes) * 60) + seconds) * 1000), 10);
1532+
if (isNaN(durationInMilliseconds)){
1533+
durationInMilliseconds = 0;
1534+
}
1535+
if (isValueNegative) {
1536+
durationInMilliseconds = durationInMilliseconds * -1;
1537+
}
1538+
1539+
return durationInMilliseconds;
1540+
},
1541+
1542+
/**
1543+
@method convertMillisecondsToISO8601Duration
1544+
@static
1545+
@param {Int} inputMilliseconds Duration in milliseconds
1546+
@return {String} Duration in ISO8601 format
1547+
*/
1548+
convertMillisecondsToISO8601Duration: function (inputMilliseconds) {
1549+
var hours,
1550+
minutes,
1551+
seconds,
1552+
i_inputMilliseconds = parseInt(inputMilliseconds, 10),
1553+
inputIsNegative = "",
1554+
rtnStr = "";
1555+
1556+
if (i_inputMilliseconds < 0) {
1557+
inputIsNegative = "-";
1558+
i_inputMilliseconds = i_inputMilliseconds * -1;
1559+
}
1560+
1561+
hours = parseInt(((i_inputMilliseconds) / 3600000), 10);
1562+
minutes = parseInt((((i_inputMilliseconds) % 3600000) / 60000), 10);
1563+
seconds = (((i_inputMilliseconds) % 3600000) % 60000) / 1000;
1564+
1565+
rtnStr = inputIsNegative + "PT";
1566+
if (hours > 0) {
1567+
rtnStr += hours + "H";
1568+
}
1569+
1570+
if (minutes > 0) {
1571+
rtnStr += minutes + "M";
1572+
}
1573+
1574+
rtnStr += seconds + "S";
1575+
1576+
return rtnStr;
1577+
},
1578+
14781579
/**
14791580
@method getSHA1String
14801581
@static
@@ -2459,7 +2560,7 @@ TinCan client library
24592560
else {
24602561
requestParams.agent = JSON.stringify(cfg.agent.asVersion(this.version));
24612562
}
2462-
if (typeof cfg.registration !== "undefined") {
2563+
if ((typeof cfg.registration !== "undefined") && (cfg.registration !== null)) {
24632564
if (this.version === "0.9") {
24642565
requestParams.registrationId = cfg.registration;
24652566
}
@@ -2575,6 +2676,7 @@ TinCan client library
25752676
@param {String} [cfg.registration] Registration
25762677
@param {String} [cfg.lastSHA1] SHA1 of the previously seen existing state
25772678
@param {String} [cfg.contentType] Content-Type to specify in headers (defaults to 'application/octet-stream')
2679+
@param {String} [cfg.method] Method to use. Default: PUT
25782680
@param {Function} [cfg.callback] Callback to execute on completion
25792681
*/
25802682
saveState: function (key, val, cfg) {
@@ -2590,6 +2692,10 @@ TinCan client library
25902692
val = JSON.stringify(val);
25912693
}
25922694

2695+
if (typeof cfg.method === "undefined" || cfg.method !== "POST") {
2696+
cfg.method = "PUT";
2697+
}
2698+
25932699
requestParams = {
25942700
stateId: key,
25952701
activityId: cfg.activity.id
@@ -2600,7 +2706,7 @@ TinCan client library
26002706
else {
26012707
requestParams.agent = JSON.stringify(cfg.agent.asVersion(this.version));
26022708
}
2603-
if (typeof cfg.registration !== "undefined") {
2709+
if ((typeof cfg.registration !== "undefined") && (cfg.registration !== null)) {
26042710
if (this.version === "0.9") {
26052711
requestParams.registrationId = cfg.registration;
26062712
}
@@ -2611,7 +2717,7 @@ TinCan client library
26112717

26122718
requestCfg = {
26132719
url: "activities/state",
2614-
method: "PUT",
2720+
method: cfg.method,
26152721
params: requestParams,
26162722
data: val,
26172723
headers: {
@@ -2657,7 +2763,7 @@ TinCan client library
26572763
if (key !== null) {
26582764
requestParams.stateId = key;
26592765
}
2660-
if (typeof cfg.registration !== "undefined") {
2766+
if ((typeof cfg.registration !== "undefined") && (cfg.registration !== null)) {
26612767
if (this.version === "0.9") {
26622768
requestParams.registrationId = cfg.registration;
26632769
}
@@ -2803,6 +2909,7 @@ TinCan client library
28032909
@param {Object} cfg.activity TinCan.Activity
28042910
@param {String} [cfg.lastSHA1] SHA1 of the previously seen existing profile
28052911
@param {String} [cfg.contentType] Content-Type to specify in headers (defaults to 'application/octet-stream')
2912+
@param {String} [cfg.method] Method to use. Default: PUT
28062913
@param {Function} [cfg.callback] Callback to execute on completion
28072914
*/
28082915
saveActivityProfile: function (key, val, cfg) {
@@ -2813,13 +2920,17 @@ TinCan client library
28132920
cfg.contentType = "application/octet-stream";
28142921
}
28152922

2923+
if (typeof cfg.method === "undefined" || cfg.method !== "POST") {
2924+
cfg.method = "PUT";
2925+
}
2926+
28162927
if (typeof val === "object" && TinCan.Utils.isApplicationJSON(cfg.contentType)) {
28172928
val = JSON.stringify(val);
28182929
}
28192930

28202931
requestCfg = {
28212932
url: "activities/profile",
2822-
method: "PUT",
2933+
method: cfg.method,
28232934
params: {
28242935
profileId: key,
28252936
activityId: cfg.activity.id
@@ -3005,6 +3116,7 @@ TinCan client library
30053116
@param {Object} cfg.agent TinCan.Agent
30063117
@param {String} [cfg.lastSHA1] SHA1 of the previously seen existing profile
30073118
@param {String} [cfg.contentType] Content-Type to specify in headers (defaults to 'application/octet-stream')
3119+
@param {String} [cfg.method] Method to use. Default: PUT
30083120
@param {Function} [cfg.callback] Callback to execute on completion
30093121
*/
30103122
saveAgentProfile: function (key, val, cfg) {
@@ -3015,12 +3127,16 @@ TinCan client library
30153127
cfg.contentType = "application/octet-stream";
30163128
}
30173129

3130+
if (typeof cfg.method === "undefined" || cfg.method !== "POST") {
3131+
cfg.method = "PUT";
3132+
}
3133+
30183134
if (typeof val === "object" && TinCan.Utils.isApplicationJSON(cfg.contentType)) {
30193135
val = JSON.stringify(val);
30203136
}
30213137

30223138
requestCfg = {
3023-
method: "PUT",
3139+
method: cfg.method,
30243140
params: {
30253141
profileId: key
30263142
},
@@ -5101,7 +5217,6 @@ TinCan client library
51015217
"revision",
51025218
"platform",
51035219
"language",
5104-
"statement",
51055220
"extensions"
51065221
],
51075222
agentGroupProps = [
@@ -5147,6 +5262,24 @@ TinCan client library
51475262
this.contextActivities = new TinCan.ContextActivities(cfg.contextActivities);
51485263
}
51495264
}
5265+
5266+
if (cfg.hasOwnProperty("statement") && cfg.statement !== null) {
5267+
if (cfg.statement instanceof TinCan.StatementRef) {
5268+
this.statement = cfg.statement;
5269+
}
5270+
else if (cfg.statement instanceof TinCan.SubStatement) {
5271+
this.statement = cfg.statement;
5272+
}
5273+
else if (cfg.statement.objectType === "StatementRef") {
5274+
this.statement = new TinCan.StatementRef(cfg.statement);
5275+
}
5276+
else if (cfg.statement.objectType === "SubStatement") {
5277+
this.statement = new TinCan.SubStatement(cfg.statement);
5278+
}
5279+
else {
5280+
this.log("Unable to parse statement.context.statement property.");
5281+
}
5282+
}
51505283
},
51515284

51525285
/**
@@ -5173,6 +5306,11 @@ TinCan client library
51735306

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

5309+
if (this.statement instanceof TinCan.SubStatement && version !== "0.9" && version !== "0.95") {
5310+
this.log("[error] version does not support SubStatements in the 'statement' property: " + version);
5311+
throw new Error(version + " does not support SubStatements in the 'statement' property");
5312+
}
5313+
51765314
for (i = 0; i < optionalDirectProps.length; i += 1) {
51775315
if (this[optionalDirectProps[i]] !== null) {
51785316
result[optionalDirectProps[i]] = this[optionalDirectProps[i]];
@@ -5562,6 +5700,10 @@ TinCan client library
55625700
result.object = this.target.asVersion(version);
55635701
}
55645702

5703+
if (version === "0.9") {
5704+
result.objectType = "Statement";
5705+
}
5706+
55655707
return result;
55665708
}
55675709
};

0 commit comments

Comments
 (0)