README
Getting started
Provides an effective solution for sleep problems.
How to Build
The generated SDK relies on Node Package Manager (NPM) being available to resolve dependencies. If you don't already have NPM installed, please go ahead and follow instructions to install NPM from here. The SDK also requires Node to be installed. If Node isn't already installed, please install it from here
NPM is installed by default when Node is installed
To check if node and npm have been successfully installed, write the following commands in command prompt:
node --version
npm -version
Now use npm to resolve all dependencies by running the following command in the root directory (of the SDK folder):
npm install
This will install all dependencies in the node_modules
folder.
Once dependencies are resolved, you will need to move the folder SmartSleepAnalyzer
in to your node_modules
folder.
How to Use
The following section explains how to use the library in a new project.
1. Open Project Folder
Open an IDE/Text Editor for JavaScript like Sublime Text. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
Click on File
and select Open Folder
.
Select the folder of your SDK and click on Select Folder
to open it up in Sublime Text. The folder will become visible in the bar on the left.
2. Creating a Test File
Now right click on the folder name and select the New File
option to create a new test file. Save it as index.js
Now import the generated NodeJS library using the following lines of code:
var lib = require('lib');
Save changes.
3. Running The Test File
To run the index.js
file, open up the command prompt and navigate to the Path where the SDK folder resides. Type the following command to run the file:
node index.js
How to Test
These tests use Mocha framework for testing, coupled with Chai for assertions. These dependencies need to be installed for tests to run. Tests can be run in a number of ways:
Method 1 (Run all tests)
- Navigate to the
<repo-root>/SSA-NodeJS/test/
directory from command prompt. - Type
mocha --<YourClientId> --<YourClientSecret> *
to run all the tests.
Method 2 (Run specific controller's tests)
- Navigate to the
<repo-root>/SSA-NodeJS/test/
directory from command prompt. - Edit the
clientid
andsecretKey
properties in theConfiguration.js
file with your Client Id and Secret. - Type
mocha <ControllerFileName>
to run all the tests in that controller file.
To increase mocha's default timeout, you can change the
TEST_TIMEOUT
parameter's value inTestBootstrap.js
.
Initialization
API client can be initialized as following:
const lib = require('lib');
Class Reference
List of Controllers
ScoringController
Get singleton instance
The singleton instance of the ScoringController
class can be accessed from the API Client.
var SSA_ClientLib = lib(_config.clientid,_config.secretKey);
getRequiredQuestionSenses
Returns all question senses required to compute the target sense.
function getRequiredQuestionSenses(targetSenseId, locale)
Parameters
Parameter | Tags | Description |
---|---|---|
targetSenseId | Required |
Id of sense for which required inputs are returned. |
locale | Optional DefaultValue |
Optional query param locale used to localize question sense text. |
Example Usage
var targetSenseId = 'targetSenseId';
var locale = 'locale';
SSA_ClientLib.ScoringController.getRequiredQuestionSenses(targetSenseId, locale).then(function(result) {
//TODO Business Logic
});
getComputableSleepProblemSenses
Returns all sleep problem senses which can be computed from the given input sense ids.
function getComputableSleepProblemSenses(senseIds)
Parameters
Parameter | Tags | Description |
---|---|---|
senseIds | Optional Collection |
List of ids for all input senses that would be provided. |
Example Usage
var senseIds = ['senseIds'];
SSA_ClientLib.ScoringController.getComputableSleepProblemSenses(senseIds).then(function(result) {
//TODO Business Logic
});
getComputableSenses
Returns all senses which can be computed from the given input sense ids.
function getComputableSenses(senseIds)
Parameters
Parameter | Tags | Description |
---|---|---|
senseIds | Optional Collection |
List of ids for all input senses that would be provided. |
Example Usage
var senseIds = ['senseIds'];
SSA_ClientLib.ScoringController.getComputableSenses(senseIds).then(function(result) {
//TODO Business Logic
});
getComputedSenses
Returns metadata information about all computed senses. Computed senses are derived from other senses and should
not be asked directly to an end-user.
function getComputedSenses()
Example Usage
SSA_ClientLib.ScoringController.getComputedSenses().then(function(result) {
//TODO Business Logic
});
getSleepProblemSenses
Returns metadata information about all sleep problem senses.
function getSleepProblemSenses()
Example Usage
SSA_ClientLib.ScoringController.getSleepProblemSenses().then(function(result) {
//TODO Business Logic
});
getQuestionSenses
Returns metadata information about all question senses. Question senses are simple value senses which can be asked
to an end-user in the form of a question.
function getQuestionSenses(locale)
Parameters
Parameter | Tags | Description |
---|---|---|
locale | Optional DefaultValue |
Optional query param locale used to localize question sense text. |
Example Usage
var locale = 'locale';
SSA_ClientLib.ScoringController.getQuestionSenses(locale).then(function(result) {
//TODO Business Logic
});
getAllSenses
Returns metadata information about all available senses.
function getAllSenses(locale)
Parameters
Parameter | Tags | Description |
---|---|---|
locale | Optional DefaultValue |
Optional query param locale used to localize question sense text. |
Example Usage
var locale = 'locale';
SSA_ClientLib.ScoringController.getAllSenses(locale).then(function(result) {
//TODO Business Logic
});
getSense
Returns metadata information about a single sense.
function getSense(senseId, locale)
Parameters
Parameter | Tags | Description |
---|---|---|
senseId | Required |
The id of the sense. |
locale | Optional DefaultValue |
Optional query param locale used to localize question sense text. |
Example Usage
var senseId = 'senseId';
var locale = 'locale';
SSA_ClientLib.ScoringController.getSense(senseId, locale).then(function(result) {
//TODO Business Logic
});
computeIntermediateAndSleepProblemSenses
Computes the values of all possible intermediate and sleep problem senses based on the provided input values.
function computeIntermediateAndSleepProblemSenses(inputValues)
Parameters
Parameter | Tags | Description |
---|---|---|
inputValues | Optional |
Map of sense input values, keyed by sense id. |
Example Usage
var inputValues = {
id : 21
};
SSA_ClientLib.ScoringController.computeIntermediateAndSleepProblemSenses(inputValues).then(function(result) {
//TODO Business Logic
});
computeSleepProblemSenses
Computes the values of all possible sleep problem senses based on the provided input values.
function computeSleepProblemSenses(inputValues)
Parameters
Parameter | Tags | Description |
---|---|---|
inputValues | Optional |
Map of sense input values, keyed by sense id. |
Example Usage
var inputValues = {
id : 21
};
SSA_ClientLib.ScoringController.computeSleepProblemSenses(inputValues).then(function(result) {
//TODO Business Logic
});
computeSense
Computes the value of a single sense based on the provided input values.
function computeSense(senseId, inputValues)
Parameters
Parameter | Tags | Description |
---|---|---|
senseId | Required |
Id of the sense to compute. |
inputValues | Optional |
Map of sense input values, keyed by sense id. |
Example Usage
var senseId = 'senseId';
var inputValues = {
id : 21
};
SSA_ClientLib.ScoringController.computeSense(senseId, inputValues).then(function(result) {
//TODO Business Logic
});
computeAllSenses
Computes the values of all possible senses based on the provided input values.
function computeAllSenses(inputValues)
Parameters
Parameter | Tags | Description |
---|---|---|
inputValues | Optional |
Map of sense input values, keyed by sense id. |
Example Usage
var inputValues = {
id : 21
};
SSA_ClientLib.ScoringController.computeSense(inputValues).then(function(result) {
//TODO Business Logic
});
ResultController
Get singleton instance
The singleton instance of the ResultController
class can be accessed from the API Client.
var SSA_ClientLib = lib(_config.clientid,_config.secretKey);
getTipsByConditionAndInputValues
Computes and returns all tips that would be associated with the given condition, based on the given input values.
function getTipsByConditionAndInputValues(conditionId, inputValues)
Parameters
Parameter | Tags | Description |
---|---|---|
conditionId | Optional |
The id of the sleep problem. |
inputValues | Optional |
The sense input values. |
Example Usage
var conditionId = 'conditionId';
var inputValues = {
id : 21
};
SSA_ClientLib.ResultController.getTipsByConditionAndInputValues(conditionId, inputValues).then(function(result) {
//TODO Business Logic
});
getTipIdsByConditionAndInputValues
Computes and returns the ids of all tips that would be associated with the given condition, based on the given input values.
function getTipIdsByConditionAndInputValues(conditionId, inputValues)
Parameters
Parameter | Tags | Description |
---|---|---|
conditionId | Required |
The id of the sleep problem. |
inputValues | Optional |
The sense input values. |
Example Usage
var conditionId = 'conditionId';
var inputValues = {
id : 21
};
SSA_ClientLib.ResultController.getTipIdsByConditionAndInputValues(conditionId, inputValues).then(function(result) {
//TODO Business Logic
});
getTidbitIdsByCondition
Returns the ids of all tidbits that could be associated with the given condition.
function getTidbitIdsByCondition(conditionId)
Parameters
Parameter | Tags | Description |
---|---|---|
conditionId | Required |
The id of the condition. |
Example Usage
var conditionId = 'conditionId';
SSA_ClientLib.ResultController.getTidbitIdsByCondition(conditionId).then(function(result) {
//TODO Business Logic
});
getTipIdsByCondition
Returns the ids of all tips that could be associated with the given condition.
function getTipIdsByCondition(conditionId)
Parameters
Parameter | Tags | Description |
---|---|---|
conditionId | Required |
The id of the condition. |
Example Usage
var conditionId = 'conditionId';
SSA_ClientLib.ResultController.getTipIdsByCondition(conditionId).then(function(result) {
//TODO Business Logic
});
getCondition
Returns metadata information about an single condition.
function getCondition(conditionId)
Parameters
Parameter | Tags | Description |
---|---|---|
conditionId | Required |
The id of the condition. |
Example Usage
var conditionId = 'conditionId';
SSA_ClientLib.ResultController.getCondition(conditionId).then(function(result) {
//TODO Business Logic
});
submitTipFeedback
Submits feedback for the session on the indicated tip.
function submitTipFeedback(requestDTO)
Parameters
Parameter | Tags | Description |
---|---|---|
requestDTO | Optional |
The request object. |
Example Usage
var requestDTO = new UpdateTipFeedbackRequestDTO({"key":"value"});
SSA_ClientLib.ResultController.submitTipFeedback(requestDTO).then(function(result) {
//TODO Business Logic
});
getAllConditions
Returns metadata information about all available conditions.
function getAllConditions()
Example Usage
SSA_ClientLib.ResultController.getAllConditions().then(function(result) {
//TODO Business Logic
});
submitConditionFeedback
Submits feedback for the session on the indicated condition.
function submitConditionFeedback(requestDTO)
Parameters
Parameter | Tags | Description |
---|---|---|
requestDTO | Optional |
The request object. |
Example Usage
var requestDTO = new UpdateConditionFeedbackRequestDTO({"key":"value"});
SSA_ClientLib.ResultController.submitConditionFeedback(requestDTO).then(function(result) {
//TODO Business Logic
});
computeResult
Computes Results output for the given survey.
function computeResult(surveyIdentifier, sessionId)
Parameters
Parameter | Tags | Description |
---|---|---|
surveyIdentifier | Required |
The identifier of the survey. |
sessionId | Optional |
An auth token provided by the backend, for persisting state between calls. |
Example Usage
var surveyIdentifier = 'surveyIdentifier';
var sessionId = null;
SSA_ClientLib.ResultController.submitConditionFeedback(surveyIdentifier, sessionId).then(function(result) {
//TODO Business Logic
});
SessionController
Get singleton instance
The singleton instance of the SessionController
class can be accessed from the API Client.
var SSA_ClientLib = lib(_config.clientid,_config.secretKey);
activateSession
Activates a session.
function activateSession(sessionDTO)
Parameters
Parameter | Tags | Description |
---|---|---|
sessionDTO | Optional |
Object containing the session's credentials. |
Example Usage
var sessionDTO = new SessionDTO({"key":"value"});
SSA_ClientLib.SessionController.activateSession(sessionDTO).then(function(result) {
//TODO Business Logic
});
retrieveActivatedSession
Retrieves the details of the activated session.
function retrieveActivatedSession()
Example Usage
SSA_ClientLib.SessionController.retrieveActivatedSession().then(function(result) {
//TODO Business Logic
});
deactivateSession
Deactivates the current session.
function deactivateSession()
Example Usage
SSA_ClientLib.SessionController.deactivateSession().then(function(result) {
//TODO Business Logic
});
createSession
Creates a new session with the provided information.
function createSession(sessionDTO)
Parameters
Parameter | Tags | Description |
---|---|---|
sessionDTO | Optional |
The provided session information. |
Example Usage
var sessionDTO = new SessionDTO({"key":"value"});
SSA_ClientLib.SessionController.createSession(sessionDTO).then(function(result) {
//TODO Business Logic
});
SurveyController
Get singleton instance
The singleton instance of the SurveyController
class can be accessed from the API Client.
var SSA_ClientLib = lib(_config.clientid,_config.secretKey);
resetSurveyState
Resets the state of the survey for the current session. In other words, all the session's answers are removed and the survey should start back at the beginning.
function resetSurveyState(identifier)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required |
The identifier of the survey. |
Example Usage
var identifier = 'identifier';
SSA_ClientLib.SurveyController.resetSurveyState(identifier).then(function(result) {
//TODO Business Logic
});
getSurveyState
Retrieves the state of a survey for the current session.
function getSurveyState(identifier, sessionId)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required |
The identifier of the survey. |
sessionId | Optional |
An auth token provided by the backend, for persisting state between calls. |
Example Usage
var identifier = 'identifier';
var sessionId = null;
SSA_ClientLib.SurveyController.getSurveyState(identifier, sessionId).then(function(result) {
//TODO Business Logic
});
updateSurveyState
Updates the state of a survey for the current session, and returns the portion of the survey state necessary for the client to render the survey based on the update.
function updateSurveyState(identifier, requestDTO, sessionId)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required |
The identifier of the survey. |
requestDTO | Optional |
The update request object. |
sessionId | Optional |
An auth token provided by the backend, for persisting state between calls. |
Example Usage
var identifier = 'identifier';
var requestDTO = new UpdateSurveyStateRequestDTO({"key":"value"});
var sessionId = null;
SSA_ClientLib.SurveyController.updateSurveyState(identifier, requestDTO, sessionId).then(function(result) {
//TODO Business Logic
});
getSenseQuestion
Get the QuestionDTO for a given sense, and for the given survey.
function getSenseQuestion(identifier, senseId)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required |
The identifier of the survey. |
senseId | Required |
The id of the sense we want a list of required QuestionDTO for. |
Example Usage
var identifier = 'identifier';
var senseId = 'height';
SSA_ClientLib.SurveyController.getSenseQuestion(identifier, senseId).then(function(result) {
//TODO Business Logic
});
getSenseRequiredQuestions
Get a list of required QuestionDTO items for a given sense, and for the given survey.
function getSenseRequiredQuestions(identifier, senseId)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required |
The identifier of the survey. |
senseId | Required |
The id of the sense we want a list of required QuestionDTO for. |
Example Usage
var identifier = 'identifier';
var senseId = 'height';
SSA_ClientLib.SurveyController.getSenseRequiredQuestions(identifier, senseId).then(function(result) {
//TODO Business Logic
});
getQuestions
Retrieves the current question set, per the current survey state, or per the given Step Id reference. Templates are also provided for immediately submitting via PostAnswers, or later submission via UpdateAnswers.
function getQuestions(identifier, stepRef, sessionId)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required |
The identifier of the survey. |
stepRef | Optional |
Optional Step Id we wish to query QuestionDTOs for. Defaults to the latest step, if unspecified. |
sessionId | Optional |
An auth token provided by the backend, for persisting state between calls. |
Example Usage
var identifier = 'identifier';
var stepRef = null;
var sessionId = null;
SSA_ClientLib.SurveyController.getSenseRequiredQuestions(identifier, stepRef, sessionId).then(function(result) {
//TODO Business Logic
});
postAnswers
Submits answers to the most recent, unanswered questions for the current survey session, and returns the next batch of unanswered survey questions if successful.
function postAnswers(identifier, answers, sessionId)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required |
The identifier of the survey. |
answers | Optional |
The answers for the most recent, unanswered questions available in the survey. |
sessionId | Optional |
An auth token provided by the backend, for persisting state between calls. |
Example Usage
var identifier = 'identifier';
var answers={'demographics1':true};
var sessionId = null;
SSA_ClientLib.SurveyController.postAnswers(identifier, answers, sessionId).then(function(result) {
//TODO Business Logic
});
updateAnswers
Re-submits answers to a potentially existing set of questions, from a previous step, and returns the next batch of unanswered survey questions if successful. This endpoint gracefully handles first-time submissions as well, similar to the simpler PostAnswers endpoint.
function updateAnswers(identifier, updateSurveyStateRequestDTO, sessionId)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required |
The identifier of the survey. |
updateSurveyStateRequestDTO | Required |
A DTO with the step ref, and answers to re-submit. |
sessionId | Optional |
An auth token provided by the backend, for persisting state between calls. |
Example Usage
var identifier = 'identifier';
var updateSurveyStateRequestDTO={
'stepRef': 'demographics1',
'answers': {
'demographics1':true,
}
};
var sessionId = null;
SSA_ClientLib.SurveyController.postAnswers(identifier, updateSurveyStateRequestDTO, sessionId).then(function(result) {
//TODO Business Logic
});
getSurveyStateSummary
Retrieves the state of a survey for the current session.
function getSurveyStateSummary(identifier, sessionId)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required |
The identifier of the survey. |
sessionId | Optional |
An auth token provided by the backend, for persisting state between calls. |
Example Usage
var identifier = 'identifier';
var sessionId = null;
SSA_ClientLib.SurveyController.getSurveyStateSummary(identifier, sessionId).then(function(result) {
//TODO Business Logic
});