philipssleepcompanionlib v1.1.0
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 PhilipsSleepCompanionLib
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 root directory of the SDK folder from command prompt.
- Type
mocha --recursive
to run all the tests.
Method 2 (Run all tests)
- Navigate to the
../test/Controllers/
directory from command prompt. - Type
mocha *
to run all the tests.
Method 3 (Run specific controller's tests)
- Navigate to the
../test/Controllers/
directory from command prompt. - Type
mocha Philips Sleep CompanionController
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 controller = lib.ScoringController;
getRequiredQuestionSenses
Returns all question senses required to compute the target sense.
function getRequiredQuestionSenses(targetSenseId, locale, callback)
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';
controller.getRequiredQuestionSenses(targetSenseId, locale, function(error, response, context) {
});
createGetComputableSleepProblemSenses
Returns all sleep problem senses which can be computed from the given input sense ids.
function createGetComputableSleepProblemSenses(senseIds, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
senseIds | Optional Collection | List of ids for all input senses that would be provided. |
Example Usage
var senseIds = ['senseIds'];
controller.createGetComputableSleepProblemSenses(senseIds, function(error, response, context) {
});
createGetComputableSenses
Returns all senses which can be computed from the given input sense ids.
function createGetComputableSenses(senseIds, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
senseIds | Optional Collection | List of ids for all input senses that would be provided. |
Example Usage
var senseIds = ['senseIds'];
controller.createGetComputableSenses(senseIds, function(error, response, context) {
});
getComputedSenses
Returns metadata information about all computed senses. Computed senses are derived from other senses and should
not be asked directly to a user.
function getComputedSenses(callback)
Example Usage
controller.getComputedSenses(function(error, response, context) {
});
getSleepProblemSenses
Returns metadata information about all sleep problem senses.
function getSleepProblemSenses(callback)
Example Usage
controller.getSleepProblemSenses(function(error, response, context) {
});
getQuestionSenses
Returns metadata information about all question senses. Question senses are simple value senses which can be asked
to a user in the form of a question.
function getQuestionSenses(locale, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
locale | Optional DefaultValue | Optional query param locale used to localize question sense text. |
Example Usage
var locale = 'locale';
controller.getQuestionSenses(locale, function(error, response, context) {
});
getAllSenses
Returns metadata information about all available senses.
function getAllSenses(locale, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
locale | Optional DefaultValue | Optional query param locale used to localize question sense text. |
Example Usage
var locale = 'locale';
controller.getAllSenses(locale, function(error, response, context) {
});
getSense
Returns metadata information about a single sense.
function getSense(senseId, locale, callback)
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';
controller.getSense(senseId, locale, function(error, response, context) {
});
createComputeIntermediateAndSleepProblemSenses
Computes the values of all possible intermediate and sleep problem senses based on the provided input values.
function createComputeIntermediateAndSleepProblemSenses(inputValues, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
inputValues | Optional | Map of sense input values, keyed by sense id. |
Example Usage
var inputValues = {
id : 21
};
controller.createComputeIntermediateAndSleepProblemSenses(inputValues, function(error, response, context) {
});
createComputeSleepProblemSenses
Computes the values of all possible sleep problem senses based on the provided input values.
function createComputeSleepProblemSenses(inputValues, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
inputValues | Optional | Map of sense input values, keyed by sense id. |
Example Usage
var inputValues = {
id : 21
};
controller.createComputeSleepProblemSenses(inputValues, function(error, response, context) {
});
createComputeSense
Computes the value of a single sense based on the provided input values.
function createComputeSense(senseId, inputValues, callback)
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
};
controller.createComputeSense(senseId, inputValues, function(error, response, context) {
});
createComputeAllSenses
Computes the values of all possible senses based on the provided input values.
function createComputeAllSenses(inputValues, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
inputValues | Optional | Map of sense input values, keyed by sense id. |
Example Usage
var inputValues = {
id : 21
};
controller.createComputeAllSenses(inputValues, function(error, response, context) {
});
ResultController
Get singleton instance
The singleton instance of the ResultController
class can be accessed from the API Client.
var controller = lib.ResultController;
createGetTipsByConditionAndInputValues
Computes and returns all tips that would be associated with the given condition, based on the given input values.
function createGetTipsByConditionAndInputValues(conditionId, inputValues, callback)
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
};
controller.createGetTipsByConditionAndInputValues(conditionId, inputValues, function(error, response, context) {
});
createGetTipIdsByConditionAndInputValues
Computes and returns the ids of all tips that would be associated with the given condition, based on the given
input values.
function createGetTipIdsByConditionAndInputValues(conditionId, inputValues, callback)
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
};
controller.createGetTipIdsByConditionAndInputValues(conditionId, inputValues, function(error, response, context) {
});
createGetTidbitIdsByCondition
Returns the ids of all tidbits that could be associated with the given condition.
function createGetTidbitIdsByCondition(conditionId, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
conditionId | Required | The id of the condition. |
Example Usage
var conditionId = 'conditionId';
controller.createGetTidbitIdsByCondition(conditionId, function(error, response, context) {
});
createGetTipIdsByCondition
Returns the ids of all tips that could be associated with the given condition.
function createGetTipIdsByCondition(conditionId, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
conditionId | Required | The id of the condition. |
Example Usage
var conditionId = 'conditionId';
controller.createGetTipIdsByCondition(conditionId, function(error, response, context) {
});
createGetCondition
Returns metadata information about an single condition.
function createGetCondition(conditionId, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
conditionId | Required | The id of the condition. |
Example Usage
var conditionId = 'conditionId';
controller.createGetCondition(conditionId, function(error, response, context) {
});
createSubmitTipFeedback
Submits feedback for the user on the indicated tip.
function createSubmitTipFeedback(requestDTO, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
requestDTO | Optional | The request object. |
Example Usage
var requestDTO = new UpdateTipFeedbackRequestDTO({"key":"value"});
controller.createSubmitTipFeedback(requestDTO, function(error, response, context) {
});
getAllConditions
Returns metadata information about all available conditions.
function getAllConditions(callback)
Example Usage
controller.getAllConditions(function(error, response, context) {
});
createSubmitConditionFeedback
Submits feedback for the user on the indicated condition.
function createSubmitConditionFeedback(requestDTO, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
requestDTO | Optional | The request object. |
Example Usage
var requestDTO = new UpdateConditionFeedbackRequestDTO({"key":"value"});
controller.createSubmitConditionFeedback(requestDTO, function(error, response, context) {
});
getComputeResult
Computes Results output for the given survey.
function getComputeResult(surveyIdentifier, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
surveyIdentifier | Required | The identifier of the survey. |
Example Usage
var surveyIdentifier = 'surveyIdentifier';
controller.getComputeResult(surveyIdentifier, function(error, response, context) {
});
UserController
Get singleton instance
The singleton instance of the UserController
class can be accessed from the API Client.
var controller = lib.UserController;
createLogin
Logs a user into the system.
function createLogin(userDTO, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
userDTO | Optional | Object containing the user's credentials. |
Example Usage
var userDTO = new UserDTO({"key":"value"});
controller.createLogin(userDTO, function(error, response, context) {
});
retrieve
Retrieves the details of the logged in user.
function retrieve(callback)
Example Usage
controller.retrieve(function(error, response, context) {
});
getLogout
Logs the current user out of the system.
function getLogout(callback)
Example Usage
controller.getLogout(function(error, response, context) {
});
createRegisterUser
Registers a new user with the provided user information.
function createRegisterUser(userDTO, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
userDTO | Optional | The provided user information. |
Example Usage
var userDTO = new UserDTO({"key":"value"});
controller.createRegisterUser(userDTO, function(error, response, context) {
});
SurveyController
Get singleton instance
The singleton instance of the SurveyController
class can be accessed from the API Client.
var controller = lib.SurveyController;
getMatchedRules
DEVELOPMENT ONLY: Returns all rules which were matched in the computation of the user's survey state. This API is
only available in development environment. In all other environments it will result in a 404 (not found).
function getMatchedRules(identifier, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required | The identifier of the survey. |
Example Usage
var identifier = 'identifier';
controller.getMatchedRules(identifier, function(error, response, context) {
});
postSurveyAnswers
DEVELOPMENT ONLY: Updates all answers stored for a user for a survey to the given set of answers. This API is only
available in
development environment. In all other environments it will result in a 404 (not found). Returns all updated
answers.
function postSurveyAnswers(identifier, answers, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required | The identifier of the survey. |
answers | Optional | The answer values to apply. Answers are keyed by question identifier. |
Example Usage
var identifier = 'identifier';
var answers = {
id : 21
};
controller.postSurveyAnswers(identifier, answers, function(error, response, context) {
});
getSenseInputValues
DEVELOPMENT ONLY: Similar to the GET /answers API, but instead returns answers mapped to their corresponding sense
values. This API is only available in development environment. In all other environments it will result in a 404
(not found).
function getSenseInputValues(identifier, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required | The identifier of the survey. |
Example Usage
var identifier = 'identifier';
controller.getSenseInputValues(identifier, function(error, response, context) {
});
createResetSurveyState
Resets the state of the survey for the current user. In other words, all the user's answers are removed and the
survey should start back at the beginning.
function createResetSurveyState(identifier, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required | The identifier of the survey. |
Example Usage
var identifier = 'identifier';
controller.createResetSurveyState(identifier, function(error, response, context) {
});
getSurveyAnswers
DEVELOPMENT ONLY: Gets all answers stored for a user for a given survey. This API is only available in development
environment. In
all other environments it will result in a 404 (not found).
function getSurveyAnswers(identifier, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required | The identifier of the survey. |
Example Usage
var identifier = 'identifier';
controller.getSurveyAnswers(identifier, function(error, response, context) {
});
getSurveyState
Retrieves the state of a survey for the current user.
function getSurveyState(identifier, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required | The identifier of the survey. |
Example Usage
var identifier = 'identifier';
controller.getSurveyState(identifier, function(error, response, context) {
});
updateSurveyState
Updates the state of a survey for the current user, and returns the portion of the survey state necessary for the
client to render the survey based on the update.
function updateSurveyState(identifier, requestDTO, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
identifier | Required | The identifier of the survey. |
requestDTO | Optional | The update request object. |
Example Usage
var identifier = 'identifier';
var requestDTO = new UpdateSurveyStateRequestDTO({"key":"value"});
controller.updateSurveyState(identifier, requestDTO, function(error, response, context) {
});