Segment SDK package

da

No package description available.

Classes

ContextEngine Context engine constructor. This class helps to determine a user's current context. For instance home, work, etc...
Geolocation GeoLocation constructor. This class handles determining a users current location
SpeechSynthesis SpeechSynthesis constructor.
This class is used to execute TTS engine to speak out texts. It should be called after a segment is started, however the speech is muted by the system when the segment is paused or in an onpaused state.
SpeechToText SpeechToText constructor. This class helps to start voice recoginition to return text data.
Storage Storage constructor. Use this API to access local storage on Nigel.
Note: Do not use general JavaScript Window.localStorage and Window.sessionStorage APIs to access Nigel local storage.

Summary

Methods
addTimeline When called from a segment's segment.onpreprocess or segment.onstart process, adds an entry to the time-line database
cancelSegment When called from a segment's segment.onpreprocess process, causes the Personalized Radio function to cancel the pre-launch, without starting the segment.
getApiLevel Gets the current API level
getBatteryLevel Gets the battery level of the user's neckband unit.
getOAuthAccessToken Obtains an OAuth access token from the segment's OAuth procedure and then stores it on the server.
getSegmentConfig Gets segment configuration options from the server.
getString Retrieves a resource string from the segment's string.json file.
getXhr Gets an XHR (XML HTTP Request) object to access an external service.
registerBookmark When called from a segment's segment.onpreprocess or segment.onstart process, adds an entry to the bookmark and time-line database
requestStartSegment This method is called from a worker to request start a segment notification.
setSegmentConfig Updates segment configuration options on the server.
startSegment When called from a segment's segment.onpreprocess process, causes the Personalized Radio function to complete the pre-launch and start the segment.
stopSegment When called from a segment's segment.onstart process, causes the Personalized Radio function to end the segment notification.
stopWorker When called from a worker's segment.onstart process, causes the Personalized Radio function to cancel this iteration of the worker, without triggering the segment.
Type definitions
onerror Callback function when an error occurs.

Methods

addTimeline(entry)

When called from a segment's segment.onpreprocess or segment.onstart process, adds an entry to the time-line database. This API is not available to a worker process.

Parameters
Name Type Description
entry object The object to add to the time-line database in the server.

Properties
Name Type Description
entries Array.<Object> The object entries. Entries are displayed in the same order as they are sorted in the array.

Properties
Name Type Description
title string The title of the entry.
url string The URL for the entry resource.
imageUrl string The icon image URL for the entry.
date string The date when the entry was generated (ISO-8601).
domain string The domain name of the information source.

Returns
Type Description
Object Error
Null if the entry was added successfully; or an error object that describes why the operation failed.
number Error.code : The error code:
  • 900: authentication error
  • 999: unidentified error
string Error.message : A message that describes the error.

cancelSegment()

When called from a segment's segment.onpreprocess process, causes the Personalized Radio function to cancel the pre-launch, without starting the segment.

getApiLevel()

Gets the current API level. This function only exists after the first release so be sure to check to see if this function exists before using it.

Returns
Type Description
number API Level

getBatteryLevel()

Gets the battery level of the user's neckband unit.

Returns
Type Description
number A number between 0.0 (empty) and 1.0 (full).

getOAuthAccessToken(segmentOAuthId, callbackObject, noCache)

Obtains an OAuth access token from the segment's OAuth procedure and then stores it on the server.

The access token is obtained by the OAuth procedure on mobile host application and is stored on the server.
The configuration settings for the OAuth procedure are stored in the segment's oauth.json file.

Parameters
Name Type Description
segmentOAuthId string The segment OAuth ID for the OAuth access token to obtain.
callbackObject Object

Properties
Name Type Description
onsuccess function The callback function to be invoked when the access token is successfully retrieved.

Properties
Name Type Description
jsonObject string A JSON object style string that contains access token information. The object structure differs from provider to provider.

onerror da~onerror Callback function to be invoked when retrieval fails.

noCache boolean True keep the server from caching the token; otherwise, false.
Examples
------ Parsed jsonObject of Twitter ------
{
    "extra": {
        "access_token": {
            "consumer": {
                "key": "****",
                "secret": "****"
            },
            "secret": "****",
            "token": "****"
        }
    }
}

------ Parsed jsonObject of Google ------
{
    "access_token": "****"
}

getSegmentConfig(callbackObject)

Gets segment configuration options from the server.

The default configuration options are generated from the settings in the segment's res/settings/defaultValues.json file. Use the da.setSegmentConfig method to update the segment's configuration options.

Parameters
Name Type Description
callbackObject Object

Properties
Name Type Description
onsuccess function The callback function to be invoked when the configuration is successfully retrieved.

Properties
Name Type Description
jsonObject Object A JSON object that contains the configuration options that are stored on the server.

onerror da~onerror The callback function to be invoked when retrieval fails.

getString(key, objectString)

Retrieves a resource string from the segment's string.json file.

The meta expressions (${meta-name}) in the retrieved string are replaced with the value of the corresponding field in the objectString parameter.

Parameters
Name Type Description
key String The key of the string to retrieve from the file.
objectString Object An object that contains the values for the meta expressions (${meta-name}) in the retrieved resource string.
Examples
================================
[string.json]
{
 "rt": [
   "RT @${name}\:*"
 ]
}
================================
[How to use]
var text = da.getString("rt", { name: 'RENA' });
-> "RT @${name}\:*" is retrieved from string.json.
   Then ${name} is replaced with 'RENA', "RT @RENA\:*" is returned.
================================

getXhr()

Gets an XHR (XML HTTP Request) object to access an external service.

Returns
Type Description
XMLHttpRequest XHR object

registerBookmark(entry)

When called from a segment's segment.onpreprocess or segment.onstart process, adds an entry to the bookmark and time-line database. Once segment calls registerBookmark API, the item is added not only to the bookmark database, but also to the time-line database. This API is not available to a worker process.

Parameters
Name Type Description
entry object The object to add to the bookmark database in the server.

Properties
Name Type Description
entries Array.<Object> The object entries. Entries are displayed in the same order as they are sorted in the array.

Properties
Name Type Description
title string The title of the entry.
url string The URL for the entry resource.
imageUrl string The icon image URL for the entry.
date string The date when the entry was generated (ISO-8601).
domain string The domain name of the information source.

Returns
Type Description
Object Error
Null if the entry was added successfully; or an error object that describes why the operation failed.
number Error.code : The error code:
  • 900: authentication error
  • 999: unidentified error
string Error.message : A message that describes the error.

requestStartSegment(launchType, argumentObject)

This method is called from a worker to request start a segment notification.

When called from a worker's segment.onstart process, causes the Personalized Radio function to complete this iteration of the worker and trigger the segment. The Personalized Radio function triggers the segment by calling its segment.onpreprocess method. In that call, the trigger parameter is "Worker", and the Personalized Radio function uses the arguments provided here as default values when the segment calls the da.startSegment method.

Parameters
Name Type Description
launchType string The default launch type for the segment to trigger: [simple, full].
argumentObject Object

Properties
Name Type Description
cueVoice string The default segment start sub-key, as defined in the segment's scripts.json file, to use for the segment start cue voice.
cueVoiceArgs Array.<string> The strings for the arguments ${ARG0}, ${ARG1}... in the cue voice.
args object The launch arguments to pass to the segment's segment.onpreprocess method and the default value when the segment calls da.startSegment method.

setSegmentConfig(callbackObject, jsonObject)

Updates segment configuration options on the server.

The data format for settings object is described in res/settings/schema.json to server.

Parameters
Name Type Description
callbackObject Object

Properties
Name Type Description
onsuccess function The callback function to be invoked when the configuration options are successfully updated.

Properties
Name Type Description
jsonObject Object A JSON object that contains the configuration options that are stored on the server.

onerror da~onerror The callback function to be invoked when the update fails

jsonObject Object A JSON object that contains the configuration options to set on the server.

startSegment(launchType, argumentObject)

When called from a segment's segment.onpreprocess process, causes the Personalized Radio function to complete the pre-launch and start the segment.

Parameters
Name Type Description
launchType string The launch type for the segment to start: [simple, full]; or null to use the default value. Available if the segment trigger was launchRule or worker.
argumentObject object The cue voice and launch arguments for the segment, or null to use the default values.

Properties
Name Type Description
cueVoice string The segment start sub-key, as defined in the segment's scripts.json file, to use for the segment start cue voice; or null to use the default value.
cueVoiceArgs Array.<string> Strings for the arguments ${ARG0}, ${ARG1}... in the cue voice; or null to use the default value.
args object The launch arguments to pass to the segment's segment.onstart method, or null to use the default value.

stopSegment()

When called from a segment's segment.onstart process, causes the Personalized Radio function to end the segment notification.

stopWorker()

When called from a worker's segment.onstart process, causes the Personalized Radio function to cancel this iteration of the worker, without triggering the segment.

Type definitions

onerror(error)

Type
function

Callback function when an error occurs.

Parameters
Name Type Description
error Object Error object

Properties
Name Type Description
code number Error code
  • 999: unidentified error
message string Detail message of this error