API SDKs Downloads
SDKs (Software Development Kits) provide utility functions in different programming languages that make the interactions with the API easier.Authentication
- You do not have to explicitly go to the authentication page and parse the access token provided in the callback URL query string. The SDK authentication functions perform all these operations for you.
- The access token is stored to limit interactions with the authentication page. While a valid access token is found in the store, it is reused. The store implementation depends on the SDK language.
API requests
- You do not have to explicitly build request URLs and add parameters in the query string or in the request body. To send a request to the API, simply call the function with the corresponding request name. Request parameters are provided as objects or data structures, depending on the SDK language.
- The API key and the access token (if any) are automatically added to the request parameters.
Data set traversal
- A DataSet interface allows iterating on data set elements, without explicitly asking for the next page when the end of the current page is reached. Data set pages are automatically requested by the SDK when needed.
- Data set items are ready-to-use objects or data structures, depending on the SDK language (the JSON representation returned by the API is interpreted by the SDK).
JavaScript
The JavaScript SDK provides two utility classes :- JllmAPI, to interact with the API (authentication and requests).
- DataSet, to manipulate (in particular iterate on items of) data sets returned by the API.
JllmAPI methods summary
Method | Description |
---|---|
JllmAPI(apiKey) | Constructor |
Authentication | |
getApiKey() | Returns the API key provided at instantiation. |
storeAccessTokenFromUrl() | Retrieves and parses the access token from the current URL if any. The retrieved access token is stored in the browser local storage and will be available if the user comes back later to the page. |
authenticate(redirectUrl) | Redirects to the authentication page to get a new access token. The authentication page generates an access token from the user login info and redirects to the callback page specified in redirectUrl . The access token is added in the callback page query string as a parameter accessToken . redirectUrl is optional. If not specified, the current URL is used by default. |
setAccessToken(accessToken) | Replaces the current access token with accessToken . accessToken must be an object {token: string, expiresIn: unsigned int} returned by the authentication page. expiresIn is the number of seconds until this access token expires. setAccessToken() has no effect if the provided access token is invalid or expired. |
getAccessToken() | Returns the current access token. Returns undefined if no valid access token is found or if the access token is expired. |
wipeAccessToken() | Erases the current access token. After wipeAccessToken() , getAccessToken() will return undefined . Can be used to force the user to authenticate again. |
API requests | |
computeDataSet(parameters, callback) | All these methods have two arguments : parameters and callback . parameters is an object containing the parameters described in the request documentation page. Each parameter is a field of the object parameters . The field name is the name of parameter. callback is a JavaScript function. It is optional. If provided, the API request is asynchronously sent to the API (the JavaScript code continues its execution, without waiting the response). The API response is provided later, as an object in argument of callback . Otherwise, the API request is synchronously sent to the API (the method execution is blocked until the API response is received). The API response an object returned by the request method. |
getDataSetPage(parameters, callback) | |
addQuiz(parameters, callback) | |
getQuiz(parameters, callback) | |
getQuizAttribute(parameters, callback) | |
getQuizSet(parameters, callback) | |
getResults(parameters, callback) | |
getUser(parameters, callback) | |
getUserAttribute(parameters, callback) | |
getUserGroupSet(parameters, callback) | |
getUserSet(parameters, callback) |
DataSet methods summary
Method | Description |
---|---|
hasNext() | Returns true if this data set has a next item, false otherwise. |
next() | Returns the next item of this data set (the next page of this data set is automatically requested if necessary). Returns undefined if the data set has no more elements. |
get(i) | Returns the ith item of this data set. Throws an OutOfBoundsException if the specified index is out of the data set bounds. |
size() | Returns the total number of items in this data set. |
Example of use
The JavaScript SDK is used to send requests to the API in the "Try it!" section of documentation pages.Code samples
- Authentication : see the code samples provided in the authentication section ("Using the JavaScript SDK" paragraphs).
- Retrieving and displaying identifiers of the quizzes played in the session #71330434 (synchronous version):
var jllmAPI = new JllmAPI(API_KEY); // retrieves the quizzes var quizSet = jllmAPI.getQuizSet({ sessionId : 71330434}); while( quizSet.hasNext() ){ var quiz = quizSet.next(); console.log(quiz.id): }
Download link
Click here to download the JavaScript SDK.Important dependency note: The JavaScript SDK depends on the jQuery framework. You need to load jQuery in your page before the JavaScript SDK. You can get jQuery here.
Plugins
Login button
Description
This plugin adds a widget in your page that calls the JavaScript SDK access token management methods described above. This widget is a button that displays "Logout" if a valid access token is available and "Login" otherwise. Clicking on "Login" and "Logout" calls respectively the methodsauthenticate()
and wipeAccessToken()
of the JavaScript SDK.
The Login button language and appearance are customizable. You can get a preview and the code to include in your page by interacting with the plugin demo below.
Language | Button Size |
Code | Preview | |
Html: |
|
|
JavaScript: |
|