uil namespace
This page documents the functions that are available in the uil namespace, as such, all functions/classes on this page should be used as follows:
- setAccessKey(access_key)
Saves an access key to be used with all API related functions as an default.
Saves an access key to be used with all API related functions as an default. If a default has been saved, one does not need to supply the access key anymore to any function with it as a parameter. This acces key will be used for all subsequent communications with the dataserver. If you would like to change it, you would have to call this function again, otherwise the cached variable is used instead of the ones passed to the server.
- Arguments:
access_key, (string) – the key obtain from the datastore server.
- useAcceptationServer()
Instructs all API methods to use the acceptation datastore server.
Instructs all API methods to use the acceptation datastore server. This can be overriden on a per-call method using the
acc_serverparameter;
- useCustomServer(endpoint)
Instructs all API methods to use the server specified here
By default, the uil-utils forward the user to the production datastore. Using the function useAcceptationServer(), one can use the acceptation server. Using this function you can choose a server at a specific url.
- Arguments:
endpoint (string) – a url for the endpoint must end with /api/.
- static stopIfExperimentClosed(access_key, acc_server, A)
This function will redirect the user away if the experiment is closed.
This function will redirect the user to a ‘experiment closed’ page if the experiment is closed according to the datastore.
- Arguments:
access_key, (string) – the key obtain from the datastore server. Optional if key is set using setAccessKey
acc_server, (bool) – true if the data should be stored at the “acceptation server” for testing purposes. This parameter is only useful when running the experiment online
A (string) – page to land when the experiment is closed
A – page to land when the communication with the datastore fails.
- static saveData(access_key, acc_server)
Note
Deprecated: use saveJson() instead.
Saves data to the uilots data server or displays the data.
Saves data to the uilots data server or displays the data in the browser window. When the experiment is hosted via an http(s):// server the data will be send to the data server, otherwise this function assumes that you are testing your experiment on your own pc via the file protocol.
- Arguments:
access_key, (string) – the key obtain from the datastore server. Optional if key is set using setAccessKey
acc_server, (bool) – true if the data should be stored at the “acceptation server” for testing purposes. This parameter is only usefull when running the experiment online
- Returns:
Promise|Promise.<Object> – a promise that resolves when then upload is transferred. In case the saveOnDataServer path is chosen, it might also be “resolved” when the “retry” screen is displayed. When testing offline a resolved Promise is returned
- static saveJson(json, access_key, acc_server)
Saves a json formatted string the uilots data server or displays the data.
Saves data to the uilots data server or displays the data in the browser window. When the experiment is hosted via an http(s):// server the data will be send to the data server, otherwise this function assumes that you are testing your experiment on your own pc via the file protocol and will just display the json.
- Arguments:
json (string) – a json formatted string.
access_key, (string) – the key obtain from the datastore server. Optional if key is set using setAccessKey
acc_server, (bool) – true if the data should be stored at the “acceptation server” for testing purposes. This parameter is only useful when running the experiment online
- Returns:
Promise|Promise.<Object> – a promise that resolves when then upload is transferred. In case the saveOnDataServer (no active session) path is chosen, it might also be “resolved” when the “retry” screen is displayed. When testing offline a resolved Promise is returned.
- resolveServer(acc_server)
Figures out which server we should be talking to
Namespaces
Additionally to the functions above, a number of modules are exported as namespaces
from uil namespace, these namespaces contain functions to some specific functionality,
these namespaces such as random functions and browser information.
You can use these namespaces by using uil.random.randomise(array) or
uil.browser.isMobile(). The following namespaces are exported from uil.
browser namespace to retrieve info about the browser and device the client is workin on.
uil.error for some error handeling
uil.randomization to randomize arrays (with constrains).
uil.session for the dataservers session API
uil.focus to check whether the participant is focusing on the experiment