1.1.4 • Published 4 years ago

smartsleep-analyzer v1.1.4

Weekly downloads
25
License
SEE LICENSE IN ./...
Repository
github
Last release
4 years ago

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)

  1. Navigate to the <repo-root>/SSA-NodeJS/test/ directory from command prompt.
  2. Type mocha --<YourClientId> --<YourClientSecret> * to run all the tests.

Method 2 (Run specific controller's tests)

  1. Navigate to the <repo-root>/SSA-NodeJS/test/ directory from command prompt.
  2. Edit the clientid and secretKey properties in the Configuration.js file with your Client Id and Secret.
  3. 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 in TestBootstrap.js.

Initialization

API client can be initialized as following:

const lib = require('lib');

Class Reference

List of Controllers

Class: 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);

Method: getRequiredQuestionSenses

Returns all question senses required to compute the target sense.

function getRequiredQuestionSenses(targetSenseId, locale)

Parameters

ParameterTagsDescription
targetSenseIdRequiredId of sense for which required inputs are returned.
localeOptional DefaultValueOptional 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
});

Method: getComputableSleepProblemSenses

Returns all sleep problem senses which can be computed from the given input sense ids.

function getComputableSleepProblemSenses(senseIds)

Parameters

ParameterTagsDescription
senseIdsOptional CollectionList 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
});

Method: getComputableSenses

Returns all senses which can be computed from the given input sense ids.

function getComputableSenses(senseIds)

Parameters

ParameterTagsDescription
senseIdsOptional CollectionList 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
});

Method: 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
});

Method: getSleepProblemSenses

Returns metadata information about all sleep problem senses.

function getSleepProblemSenses()

Example Usage

SSA_ClientLib.ScoringController.getSleepProblemSenses().then(function(result) {
    //TODO Business Logic
});

Method: 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

ParameterTagsDescription
localeOptional DefaultValueOptional 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
});

Method: getAllSenses

Returns metadata information about all available senses.

function getAllSenses(locale)

Parameters

ParameterTagsDescription
localeOptional DefaultValueOptional 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
});

Method: getSense

Returns metadata information about a single sense.

function getSense(senseId, locale)

Parameters

ParameterTagsDescription
senseIdRequiredThe id of the sense.
localeOptional DefaultValueOptional 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
});

Method: computeIntermediateAndSleepProblemSenses

Computes the values of all possible intermediate and sleep problem senses based on the provided input values.

function computeIntermediateAndSleepProblemSenses(inputValues)

Parameters

ParameterTagsDescription
inputValuesOptionalMap 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
});

Method: computeSleepProblemSenses

Computes the values of all possible sleep problem senses based on the provided input values.

function computeSleepProblemSenses(inputValues)

Parameters

ParameterTagsDescription
inputValuesOptionalMap 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
});

Method: computeSense

Computes the value of a single sense based on the provided input values.

function computeSense(senseId, inputValues)

Parameters

ParameterTagsDescription
senseIdRequiredId of the sense to compute.
inputValuesOptionalMap 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
});

Method: computeAllSenses

Computes the values of all possible senses based on the provided input values.

function computeAllSenses(inputValues)

Parameters

ParameterTagsDescription
inputValuesOptionalMap 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
});

Back to List of Controllers

Class: 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);

Method: 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

ParameterTagsDescription
conditionIdOptionalThe id of the sleep problem.
inputValuesOptionalThe sense input values.

Example Usage

var conditionId = 'conditionId';
var inputValues = {
    id : 21
};

SSA_ClientLib.ResultController.getTipsByConditionAndInputValues(conditionId, inputValues).then(function(result) {
    //TODO Business Logic
});

Method: 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

ParameterTagsDescription
conditionIdRequiredThe id of the sleep problem.
inputValuesOptionalThe sense input values.

Example Usage

var conditionId = 'conditionId';
var inputValues = {
    id : 21
};

SSA_ClientLib.ResultController.getTipIdsByConditionAndInputValues(conditionId, inputValues).then(function(result) {
    //TODO Business Logic
});

Method: getTidbitIdsByCondition

Returns the ids of all tidbits that could be associated with the given condition.

function getTidbitIdsByCondition(conditionId)

Parameters

ParameterTagsDescription
conditionIdRequiredThe id of the condition.

Example Usage

var conditionId = 'conditionId';

SSA_ClientLib.ResultController.getTidbitIdsByCondition(conditionId).then(function(result) {
    //TODO Business Logic
});

Method: getTipIdsByCondition

Returns the ids of all tips that could be associated with the given condition.

function getTipIdsByCondition(conditionId)

Parameters

ParameterTagsDescription
conditionIdRequiredThe id of the condition.

Example Usage

var conditionId = 'conditionId';

SSA_ClientLib.ResultController.getTipIdsByCondition(conditionId).then(function(result) {
    //TODO Business Logic
});

Method: getCondition

Returns metadata information about an single condition.

function getCondition(conditionId)

Parameters

ParameterTagsDescription
conditionIdRequiredThe id of the condition.

Example Usage

var conditionId = 'conditionId';

SSA_ClientLib.ResultController.getCondition(conditionId).then(function(result) {
    //TODO Business Logic
});

Method: submitTipFeedback

Submits feedback for the session on the indicated tip.

function submitTipFeedback(requestDTO)

Parameters

ParameterTagsDescription
requestDTOOptionalThe request object.

Example Usage

var requestDTO = new UpdateTipFeedbackRequestDTO({"key":"value"});

SSA_ClientLib.ResultController.submitTipFeedback(requestDTO).then(function(result) {
    //TODO Business Logic
});

Method: getAllConditions

Returns metadata information about all available conditions.

function getAllConditions()

Example Usage

SSA_ClientLib.ResultController.getAllConditions().then(function(result) {
    //TODO Business Logic
});

Method: submitConditionFeedback

Submits feedback for the session on the indicated condition.

function submitConditionFeedback(requestDTO)

Parameters

ParameterTagsDescription
requestDTOOptionalThe request object.

Example Usage

var requestDTO = new UpdateConditionFeedbackRequestDTO({"key":"value"});

SSA_ClientLib.ResultController.submitConditionFeedback(requestDTO).then(function(result) {
    //TODO Business Logic
});

Method: computeResult

Computes Results output for the given survey.

function computeResult(surveyIdentifier, sessionId)

Parameters

ParameterTagsDescription
surveyIdentifierRequiredThe identifier of the survey.
sessionIdOptionalAn 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
});

Back to List of Controllers

Class: 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);

Method: activateSession

Activates a session.

function activateSession(sessionDTO)

Parameters

ParameterTagsDescription
sessionDTOOptionalObject containing the session's credentials.

Example Usage

var sessionDTO = new SessionDTO({"key":"value"});

SSA_ClientLib.SessionController.activateSession(sessionDTO).then(function(result) {
    //TODO Business Logic
});

Method: retrieveActivatedSession

Retrieves the details of the activated session.

function retrieveActivatedSession()

Example Usage

SSA_ClientLib.SessionController.retrieveActivatedSession().then(function(result) {
    //TODO Business Logic
});

Method: deactivateSession

Deactivates the current session.

function deactivateSession()

Example Usage

SSA_ClientLib.SessionController.deactivateSession().then(function(result) {
    //TODO Business Logic
});

Method: createSession

Creates a new session with the provided information.

function createSession(sessionDTO)

Parameters

ParameterTagsDescription
sessionDTOOptionalThe provided session information.

Example Usage

var sessionDTO = new SessionDTO({"key":"value"});

SSA_ClientLib.SessionController.createSession(sessionDTO).then(function(result) {
    //TODO Business Logic
});

Back to List of Controllers

Class: 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);

Method: 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

ParameterTagsDescription
identifierRequiredThe identifier of the survey.

Example Usage

var identifier = 'identifier';

SSA_ClientLib.SurveyController.resetSurveyState(identifier).then(function(result) {
    //TODO Business Logic
});

Method: getSurveyState

Retrieves the state of a survey for the current session.

function getSurveyState(identifier, sessionId)

Parameters

ParameterTagsDescription
identifierRequiredThe identifier of the survey.
sessionIdOptionalAn 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
});

Method: 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

ParameterTagsDescription
identifierRequiredThe identifier of the survey.
requestDTOOptionalThe update request object.
sessionIdOptionalAn 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
});

Method: getSenseQuestion

Get the QuestionDTO for a given sense, and for the given survey.

function getSenseQuestion(identifier, senseId)

Parameters

ParameterTagsDescription
identifierRequiredThe identifier of the survey.
senseIdRequiredThe 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
});

Method: getSenseRequiredQuestions

Get a list of required QuestionDTO items for a given sense, and for the given survey.

function getSenseRequiredQuestions(identifier, senseId)

Parameters

ParameterTagsDescription
identifierRequiredThe identifier of the survey.
senseIdRequiredThe 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
});

Method: 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

ParameterTagsDescription
identifierRequiredThe identifier of the survey.
stepRefOptionalOptional Step Id we wish to query QuestionDTOs for. Defaults to the latest step, if unspecified.
sessionIdOptionalAn 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
});

Method: 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

ParameterTagsDescription
identifierRequiredThe identifier of the survey.
answersOptionalThe answers for the most recent, unanswered questions available in the survey.
sessionIdOptionalAn 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
});

Method: 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

ParameterTagsDescription
identifierRequiredThe identifier of the survey.
updateSurveyStateRequestDTORequiredA DTO with the step ref, and answers to re-submit.
sessionIdOptionalAn 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
});

Method: getSurveyStateSummary

Retrieves the state of a survey for the current session.

function getSurveyStateSummary(identifier, sessionId)

Parameters

ParameterTagsDescription
identifierRequiredThe identifier of the survey.
sessionIdOptionalAn 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
});

Back to List of Controllers

1.1.4

4 years ago

1.1.0

4 years ago

1.0.7-beta

4 years ago

1.0.6-beta

5 years ago

1.0.5-beta

5 years ago

1.0.2-beta

5 years ago