AngularJS Service for managing generic API calls.
Also stores default settings for API calls such as game_id
.
Requires
- module:debugService
- module:domainService
- module:instructorService
- module:URLParamsService
- module:utilityService
Members
(private, inner, nullable) game_id :number
Stored game_id
to use as default when API calls do not specify one.
- Source:
Type:
-
number
Methods
(static) setGameId(idnullable)
Set stored default game ID module:APIService~game_id
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
id |
number
|
<nullable> |
(static) getGameId() → (nullable) {number}
Get stored default game ID module:APIService~game_id
- Source:
Returns:
- Type:
-
number
The default game_id
currently stored in the module instance.
(static) call(params) → {Promise}
Generic wrapper function for API calls using angular $http service. Used by most public methods in the module.
If debugService.get('noAPI')
is true, this will not perform any API request, and will immediately resolve
as if the request responded successfully with the data { noAPI: true }
.
- Source:
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object
|
|
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the result of the
onSuccess
callback or the HTTP response data. - Rejected with the result of the
onError
callback, the full HTTP response object, or an error.
(static) getGame(params, onSuccessopt) → {Promise}
Get game information.
- Source:
- See:
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object
|
|
|||||||||||||||||||||
onSuccess |
$httpDataCallback
|
<optional> |
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the result of the
onSuccess
callback or the HTTP response data. - Rejected with the full HTTP response object or an error.
(static) getGameFile(url, onSuccessopt) → {Promise}
Get Game Data from a file
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
url |
string
|
||
onSuccess |
$httpDataCallback
|
<optional> |
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the result of the
onSuccess
callback or the HTTP response data. - Rejected with the full HTTP response object or an error.
(static) getScore(params, onSuccessopt) → {Promise}
Get player's high score for a game.
- Source:
- See:
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object
|
|
||||||||||||||||
onSuccess |
$httpDataCallback
|
<optional> |
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the result of the
onSuccess
callback or the HTTP response data. - Rejected with the full HTTP response object or an error.
(static) reportScore(data, onSuccessopt, noSVopt) → {Promise}
Add player's score for a game. Only the player's high score for each game is reported in Score and Leaderboard calls.
- Source:
- See:
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object
|
Request message data (may include entries besides those listed below).
|
|||||||||||||||||||||||||||
onSuccess |
$httpDataCallback
|
<optional> |
|||||||||||||||||||||||||||
noSV |
boolean
|
<optional> |
false |
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the result of the
onSuccess
callback or the HTTP response data. - Rejected with the full HTTP response object or an error.
(static) reportAnswer(data, onSuccessopt) → {Promise}
Add an answer attempt.
- Source:
- See:
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object
|
Request message data (may include entries besides those listed below).
|
|||||||||||||||||||||||||||||||||||||||||
onSuccess |
$httpDataCallback
|
<optional> |
|
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the result of the
onSuccess
callback or the HTTP response data. - Rejected with the full HTTP response object or an error.
(static) getQuestionLeaderboard(question_id, params, onSuccess) → {Promise}
Get leaderboard for a game for a specific question
- Source:
- See:
Parameters:
Name | Type | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
question_id |
number
|
|||||||||||
params |
Object
|
Query parameters (may include entries besides those listed below).
|
||||||||||
onSuccess |
$httpDataCallback
|
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the result of the
onSuccess
callback or the HTTP response data. - Rejected with the full HTTP response object or an error.
(static) getLeaderboard(params, onSuccess) → {Promise}
Get leaderboard for a game
- Source:
- See:
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object
|
Query parameters (may include entries besides those listed below).
|
||||||||||||||||||||||||||||||
onSuccess |
$httpDataCallback
|
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the result of the
onSuccess
callback or the HTTP response data. - Rejected with the full HTTP response object or an error.
(static) getInstructorLeaderboard(params, onSuccess) → {Promise}
Get instructor leaderboard
- Source:
Parameters:
Name | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
params |
Object
|
Query parameters (may include entries besides those listed below).
|
||||||||
onSuccess |
$httpDataCallback
|
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the HTTP response object
- Rejected with the full HTTP response object or an error.
(static) getInstructorState(slug) → {Promise}
Get instructor state
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
slug |
string
|
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the result of
module:instructorService.getStates
- Rejected with the full HTTP response object or an error.
(static) getInstructorPlayers(data) → {Promise}
Get instructor players
- Source:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
data |
object
|
|
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the number of players.
- Rejected with the full HTTP response object or an error.
(static) getQuestionResults(data) → {Promise}
Get results of question
- Source:
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
data |
object
|
|
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the HTTP response object.
- Rejected with the full HTTP response object or an error.
(static) getQuestionAudio(question_id) → {Promise}
Get audio data for a question ID.
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
question_id |
number
|
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the HTTP response data.
- Rejected with the full HTTP response object or an error.