-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from irisEd/callback_errors
Added support error-first callbacks through strictCallbacks option
- Loading branch information
Showing
4 changed files
with
183 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,9 @@ var Config = function() | |
// conf["registration"] = ruuid(); | ||
// conf["grouping"] = {"id":"ctxact:default/grouping"}; | ||
// conf["activity_platform"] = "default platform"; | ||
|
||
// Behavior defaults | ||
// conf["strictCallbacks"] = false; // Strict error-first callbacks | ||
return conf | ||
}(); | ||
``` | ||
|
@@ -407,6 +410,25 @@ ADL.XAPIWrapper.sendStatement(stmt, function(resp, obj){ | |
>> [4edfe763-8b84-41f1-a355-78b7601a6fe8]: 200 - OK | ||
``` | ||
|
||
###### Send Statement with strict error-first callback | ||
|
||
Requires the config option `strictCallbacks` to be `true`. | ||
|
||
```JavaScript | ||
var stmt = {"actor" : {"mbox" : "mailto:[email protected]"}, | ||
"verb" : {"id" : "http://adlnet.gov/expapi/verbs/answered", | ||
"display" : {"en-US" : "answered"}}, | ||
"object" : {"id" : "http://adlnet.gov/expapi/activities/question"}}; | ||
ADL.XAPIWrapper.sendStatement(stmt, function(err, res, body) { | ||
if (err) { | ||
// Handle error case | ||
return; | ||
} | ||
|
||
ADL.XAPIWrapper.log("[" + body.id + "]: " + res.status + " - " + res.statusText);}); | ||
>> [4edfe763-8b84-41f1-a355-78b7601a6fe8]: 200 - OK | ||
``` | ||
|
||
###### Send Statement with Attachments | ||
The wrapper can construct a `multipart/mixed` POST for a single statement that includes attachments. Attachments should be | ||
supplied as an array in the 3rd parameter to `sendStatement`. Attachments are optional. The attachments array should consist of | ||
|
@@ -538,6 +560,29 @@ ADL.XAPIWrapper.sendStatements(stmts, function(r){ADL.XAPIWrapper.log(JSON.parse | |
>> ["2d819ea4-1a1e-11e3-a888-08002787eb49", "409c27de-1a1e-11e3-a888-08002787eb49"] | ||
``` | ||
|
||
###### Send Statements with strict error-first callback | ||
|
||
Requires the config option `strictCallbacks` to be `true`. | ||
|
||
```JavaScript | ||
var stmt = {"actor" : {"mbox" : "mailto:[email protected]"}, | ||
"verb" : ADL.verbs.answered, | ||
"object" : {"id" : "http://adlnet.gov/expapi/activities/question/1"}}; | ||
var stmt2 = {"actor" : {"mbox" : "mailto:[email protected]"}, | ||
"verb" : ADL.verbs.answered, | ||
"object" : {"id" : "http://adlnet.gov/expapi/activities/question/2"}}; | ||
var stmts = [stmt, stmt2]; | ||
ADL.XAPIWrapper.sendStatements(stmts, function(err, res, body) { | ||
if (err) { | ||
// Handle error case | ||
return; | ||
} | ||
|
||
ADL.XAPIWrapper.log(body); | ||
}); | ||
>> ["2d819ea4-1a1e-11e3-a888-08002787eb49", "409c27de-1a1e-11e3-a888-08002787eb49"] | ||
``` | ||
|
||
##### Get Statements | ||
`function getStatements(searchParams, more, callback)` | ||
Get a single or collection of Statements based on | ||
|
@@ -557,7 +602,6 @@ if (ret) | |
``` | ||
|
||
###### Get all Statements with callback | ||
|
||
```JavaScript | ||
ADL.XAPIWrapper.getStatements(null, null, | ||
function(r){ADL.XAPIWrapper.log(JSON.parse(r.response).statements);}); | ||
|
@@ -594,6 +638,22 @@ ADL.XAPIWrapper.getStatements(null, null, | |
... | ||
``` | ||
|
||
###### Get all Statements with with strict error-first callback | ||
|
||
Requires the config option `strictCallbacks` to be `true`. | ||
|
||
```JavaScript | ||
ADL.XAPIWrapper.getStatements(null, null, function(err, res, body) { | ||
if (err) { | ||
// Handle error case | ||
return; | ||
} | ||
|
||
ADL.XAPIWrapper.log(body.statements); | ||
}); | ||
>> <Array of statements> | ||
``` | ||
|
||
###### Get Statements based on search parameters | ||
The Experience API provides search parameters to narrow down | ||
the result of a Statement request. See the [Experience API Spec](https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#723-getstatements) | ||
|
@@ -638,6 +698,23 @@ ADL.XAPIWrapper.getActivities("http://adlnet.gov/expapi/activities/question", | |
>> <Activity object> | ||
``` | ||
|
||
###### Get Activity with strict error-first callback | ||
|
||
Requires the config option `strictCallbacks` to be `true`. | ||
|
||
```JavaScript | ||
ADL.XAPIWrapper.getActivities("http://adlnet.gov/expapi/activities/question", function(err, res, body) { | ||
if (err) { | ||
// Handle error case | ||
return; | ||
} | ||
|
||
ADL.XAPIWrapper.log(body); | ||
}); | ||
>> <Activity object> | ||
``` | ||
|
||
|
||
##### Activity State | ||
`function sendState(activityid, agent, stateid, registration, statevalue, matchHash, noneMatchHash, callback)` | ||
`function getState(activityid, agent, stateid, registration, since, callback)` | ||
|
@@ -841,6 +918,22 @@ ADL.XAPIWrapper.getAgents({"mbox":"mailto:[email protected]"}, | |
>> <Person object> | ||
``` | ||
|
||
###### Get Agent with strict error-first callbacks | ||
|
||
Requires the config option `strictCallbacks` to be `true`. | ||
|
||
```JavaScript | ||
ADL.XAPIWrapper.getAgents({"mbox":"mailto:[email protected]"}, function(err, res, body) { | ||
if (err) { | ||
// Handle error case | ||
return; | ||
} | ||
|
||
ADL.XAPIWrapper.log(body); | ||
}); | ||
>> <Person object> | ||
``` | ||
|
||
##### Agent Profile | ||
`function sendAgentProfile(agent, profileid, profilevalue, matchHash, noneMatchHash, callback)` | ||
`function getAgentProfile(agent, profileid, since, callback)` | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.