1.1.0 • Published 5 years ago

philipssleepcompanionlib v1.1.0

Weekly downloads
4
License
-
Repository
-
Last release
5 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

Version Check

Now use npm to resolve all dependencies by running the following command in the root directory (of the SDK folder):

npm install

Resolve Dependencies

Resolve Dependencies

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.

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.

Open Project

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.

Create new file

Save new file

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

Run file

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 root directory of the SDK folder from command prompt.
  2. Type mocha --recursive to run all the tests.

Method 2 (Run all tests)

  1. Navigate to the ../test/Controllers/ directory from command prompt.
  2. Type mocha * to run all the tests.

Method 3 (Run specific controller's tests)

  1. Navigate to the ../test/Controllers/ directory from command prompt.
  2. 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 in TestBootstrap.js.

Run Tests

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 controller = lib.ScoringController;

Method: getRequiredQuestionSenses

Returns all question senses required to compute the target sense.

function getRequiredQuestionSenses(targetSenseId, locale, callback)

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';

    controller.getRequiredQuestionSenses(targetSenseId, locale, function(error, response, context) {

    
    });

Method: createGetComputableSleepProblemSenses

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

function createGetComputableSleepProblemSenses(senseIds, callback)

Parameters

ParameterTagsDescription
senseIdsOptional CollectionList of ids for all input senses that would be provided.

Example Usage

    var senseIds = ['senseIds'];

    controller.createGetComputableSleepProblemSenses(senseIds, function(error, response, context) {

    
    });

Method: createGetComputableSenses

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

function createGetComputableSenses(senseIds, callback)

Parameters

ParameterTagsDescription
senseIdsOptional CollectionList of ids for all input senses that would be provided.

Example Usage

    var senseIds = ['senseIds'];

    controller.createGetComputableSenses(senseIds, function(error, response, context) {

    
    });

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

    
    });

Method: getSleepProblemSenses

Returns metadata information about all sleep problem senses.

function getSleepProblemSenses(callback)

Example Usage

    controller.getSleepProblemSenses(function(error, response, context) {

    
    });

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

ParameterTagsDescription
localeOptional DefaultValueOptional query param locale used to localize question sense text.

Example Usage

    var locale = 'locale';

    controller.getQuestionSenses(locale, function(error, response, context) {

    
    });

Method: getAllSenses

Returns metadata information about all available senses.

function getAllSenses(locale, callback)

Parameters

ParameterTagsDescription
localeOptional DefaultValueOptional query param locale used to localize question sense text.

Example Usage

    var locale = 'locale';

    controller.getAllSenses(locale, function(error, response, context) {

    
    });

Method: getSense

Returns metadata information about a single sense.

function getSense(senseId, locale, callback)

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';

    controller.getSense(senseId, locale, function(error, response, context) {

    
    });

Method: createComputeIntermediateAndSleepProblemSenses

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

function createComputeIntermediateAndSleepProblemSenses(inputValues, callback)

Parameters

ParameterTagsDescription
inputValuesOptionalMap of sense input values, keyed by sense id.

Example Usage

    var inputValues = {
        id : 21
    };

    controller.createComputeIntermediateAndSleepProblemSenses(inputValues, function(error, response, context) {

    
    });

Method: createComputeSleepProblemSenses

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

function createComputeSleepProblemSenses(inputValues, callback)

Parameters

ParameterTagsDescription
inputValuesOptionalMap of sense input values, keyed by sense id.

Example Usage

    var inputValues = {
        id : 21
    };

    controller.createComputeSleepProblemSenses(inputValues, function(error, response, context) {

    
    });

Method: createComputeSense

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

function createComputeSense(senseId, inputValues, callback)

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
    };

    controller.createComputeSense(senseId, inputValues, function(error, response, context) {

    
    });

Method: createComputeAllSenses

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

function createComputeAllSenses(inputValues, callback)

Parameters

ParameterTagsDescription
inputValuesOptionalMap of sense input values, keyed by sense id.

Example Usage

    var inputValues = {
        id : 21
    };

    controller.createComputeAllSenses(inputValues, function(error, response, context) {

    
    });

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 controller = lib.ResultController;

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

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

Example Usage

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

    controller.createGetTipsByConditionAndInputValues(conditionId, inputValues, function(error, response, context) {

    
    });

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

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

Example Usage

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

    controller.createGetTipIdsByConditionAndInputValues(conditionId, inputValues, function(error, response, context) {

    
    });

Method: createGetTidbitIdsByCondition

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

function createGetTidbitIdsByCondition(conditionId, callback)

Parameters

ParameterTagsDescription
conditionIdRequiredThe id of the condition.

Example Usage

    var conditionId = 'conditionId';

    controller.createGetTidbitIdsByCondition(conditionId, function(error, response, context) {

    
    });

Method: createGetTipIdsByCondition

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

function createGetTipIdsByCondition(conditionId, callback)

Parameters

ParameterTagsDescription
conditionIdRequiredThe id of the condition.

Example Usage

    var conditionId = 'conditionId';

    controller.createGetTipIdsByCondition(conditionId, function(error, response, context) {

    
    });

Method: createGetCondition

Returns metadata information about an single condition.

function createGetCondition(conditionId, callback)

Parameters

ParameterTagsDescription
conditionIdRequiredThe id of the condition.

Example Usage

    var conditionId = 'conditionId';

    controller.createGetCondition(conditionId, function(error, response, context) {

    
    });

Method: createSubmitTipFeedback

Submits feedback for the user on the indicated tip.

function createSubmitTipFeedback(requestDTO, callback)

Parameters

ParameterTagsDescription
requestDTOOptionalThe request object.

Example Usage

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

    controller.createSubmitTipFeedback(requestDTO, function(error, response, context) {

    
    });

Method: getAllConditions

Returns metadata information about all available conditions.

function getAllConditions(callback)

Example Usage

    controller.getAllConditions(function(error, response, context) {

    
    });

Method: createSubmitConditionFeedback

Submits feedback for the user on the indicated condition.

function createSubmitConditionFeedback(requestDTO, callback)

Parameters

ParameterTagsDescription
requestDTOOptionalThe request object.

Example Usage

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

    controller.createSubmitConditionFeedback(requestDTO, function(error, response, context) {

    
    });

Method: getComputeResult

Computes Results output for the given survey.

function getComputeResult(surveyIdentifier, callback)

Parameters

ParameterTagsDescription
surveyIdentifierRequiredThe identifier of the survey.

Example Usage

    var surveyIdentifier = 'surveyIdentifier';

    controller.getComputeResult(surveyIdentifier, function(error, response, context) {

    
    });

Back to List of Controllers

Class: UserController

Get singleton instance

The singleton instance of the UserController class can be accessed from the API Client.

var controller = lib.UserController;

Method: createLogin

Logs a user into the system.

function createLogin(userDTO, callback)

Parameters

ParameterTagsDescription
userDTOOptionalObject containing the user's credentials.

Example Usage

    var userDTO = new UserDTO({"key":"value"});

    controller.createLogin(userDTO, function(error, response, context) {

    
    });

Method: retrieve

Retrieves the details of the logged in user.

function retrieve(callback)

Example Usage

    controller.retrieve(function(error, response, context) {

    
    });

Method: getLogout

Logs the current user out of the system.

function getLogout(callback)

Example Usage

    controller.getLogout(function(error, response, context) {

    
    });

Method: createRegisterUser

Registers a new user with the provided user information.

function createRegisterUser(userDTO, callback)

Parameters

ParameterTagsDescription
userDTOOptionalThe provided user information.

Example Usage

    var userDTO = new UserDTO({"key":"value"});

    controller.createRegisterUser(userDTO, function(error, response, context) {

    
    });

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 controller = lib.SurveyController;

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

ParameterTagsDescription
identifierRequiredThe identifier of the survey.

Example Usage

    var identifier = 'identifier';

    controller.getMatchedRules(identifier, function(error, response, context) {

    
    });

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

ParameterTagsDescription
identifierRequiredThe identifier of the survey.
answersOptionalThe 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) {

    
    });

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

ParameterTagsDescription
identifierRequiredThe identifier of the survey.

Example Usage

    var identifier = 'identifier';

    controller.getSenseInputValues(identifier, function(error, response, context) {

    
    });

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

ParameterTagsDescription
identifierRequiredThe identifier of the survey.

Example Usage

    var identifier = 'identifier';

    controller.createResetSurveyState(identifier, function(error, response, context) {

    
    });

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

ParameterTagsDescription
identifierRequiredThe identifier of the survey.

Example Usage

    var identifier = 'identifier';

    controller.getSurveyAnswers(identifier, function(error, response, context) {

    
    });

Method: getSurveyState

Retrieves the state of a survey for the current user.

function getSurveyState(identifier, callback)

Parameters

ParameterTagsDescription
identifierRequiredThe identifier of the survey.

Example Usage

    var identifier = 'identifier';

    controller.getSurveyState(identifier, function(error, response, context) {

    
    });

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

ParameterTagsDescription
identifierRequiredThe identifier of the survey.
requestDTOOptionalThe update request object.

Example Usage

    var identifier = 'identifier';
    var requestDTO = new UpdateSurveyStateRequestDTO({"key":"value"});

    controller.updateSurveyState(identifier, requestDTO, function(error, response, context) {

    
    });

Back to List of Controllers