Class: WirelessTagPlatform

WirelessTagPlatform

new WirelessTagPlatform(optionsopt)

Instantiates WirelessTagPlatform.

Parameters:
Name Type Attributes Description
options Object <optional>
Properties
Name Type Attributes Description
log String <optional>

a custom log function.

errorHandler String <optional>

a function returning a custom error handler, will be passed a callback function.

apiBaseURI String <optional>

the base URI of the API server if hosted on a different server than the default (API_BASE_URI)

Source:

Methods

(static) callAPI(uri, reqBody, callbackopt) → {Promise}

Performs a call to the cloud JSON API. Users should not normally need to call this method directly.

Note that the method tries to infer necessary pre-steps based on the value of 'this'. It is thus meant to be called as an instance method, with this set to the instance in the library's class hierarchy from where the call would be coming. For example, tag-specific calls should have 'this' bound to a WirelessTag instance.

Parameters:
Name Type Attributes Description
uri string

the uri for the API endpoint to be called; will be prefixed with the base URI if not an absolute URI.

reqBody object

the request body as an object

callback module:wirelesstags~apiCallback <optional>

note that this method will only call this in the event of error, and it is the caller's responsibility to call it with the appropriately processed return value in case of success.

Source:
Returns:

Resolves to the value of the 'd' property of the response body from the API endpoint (or the body itself if there is no 'd' property). Invokes error handler function on error. The default handler will rethrow the error, resulting in rejecting the promise.

Type
Promise

(static) create(optionsopt) → {WirelessTagPlatform}

Creates a WirelessTagPlatform instance, using the given options for initializing. In contrast to the constructor, this method will first attempt to load default configuration using WirelessTagPlatform.loadConfig.

Parameters:
Name Type Attributes Description
options Object <optional>

overrides options found in the default configuration loaded using WirelessTagPlatform.loadConfig.

Properties
Name Type Attributes Description
log String <optional>

a custom log function.

errorHandler String <optional>

a function returning a custom error handler, will be passed a callback function.

apiBaseURI String <optional>

the base URI of the API server if hosted on a different server than the default

Source:
Returns:
Type
WirelessTagPlatform

(static) loadConfig() → {Object}

Loads config information, which presently consists primarily of connection options.

The algorithm will attempt to read the file CONFIG_NAME (in JSON format) in the executing user's home directory if the file exists. It will then take username and password from the environment (ENV_USERNAME and ENV_PASSWORD), which allows to use the environment to override settings in the configuration file.

Source:
Returns:
Type
Object

connect(opts, callbackopt) → {Promise}

Connects to the cloud API if not connected already. Note that the WirelessTagPlatform#event:connect event will not fire if already connected.

Parameters:
Name Type Attributes Description
opts Object

connection parameters

Properties
Name Type Description
username String

the username (email) for connecting

password String

the password for connecting

callback module:wirelesstags~apiCallback <optional>
Source:
Fires:
Returns:

resolves to 'this' upon success

Type
Promise

discoverTagManagers(queryopt, callbackopt) → {Promise}

Retrieves the tag managers available to the connected account. The list is optionally filtered depending on the supplied query parameter.

Note that using the 'query' parameter as opposed to filtering the returned tag manager objects will really only be useful to prevent 'discover' events from being fired for undesired tag manager objects. The filtering does not happen at the API endpoint, and so has almost no performance benefits, unless there are many tag managers under the account and the 'discover' event listener were somehow expensive to execute.

Parameters:
Name Type Attributes Description
query Object <optional>

an object with keys and values that a tag manager data object returned by the API has to meet. The most useful ones are likely 'name' and 'mac'. Consult the GetTagManagers JSON API for possible keys.

callback module:wirelesstags~apiCallback <optional>
Source:
Fires:
Returns:

resolves to an array of (optionally filtered) WirelessTagManager instances

Type
Promise

isConnected(callbackopt) → {Promise}

Tests whether this instance is connected to the cloud API.

Parameters:
Name Type Attributes Description
callback module:wirelesstags~apiCallback <optional>
Source:
Returns:

resolves to true if connected, and false otherwise

Type
Promise

retryOnError(enableopt) → {boolean}

Queries and/or sets whether failed API calls should be retried. By default this is off.

Note that failed calls are only retried under certain conditions, and only for a certain number of times. At present, the condition is that failure be due to the tag not responding, and the call is retried only once, after waiting WAIT_BEFORE_RETRY milliseconds.

Parameters:
Name Type Attributes Description
enable boolean <optional>

on set, whether or not to enable retrying

Source:
Returns:

whether or not retrying is currently enabled

Type
boolean

selectTagManager(tagManager, callbackopt) → {Promise}

Selects the given tag manager for subsequent API calls that expect it, if the tag manager is not already selected. Note that the library will call this automatically, and so a user will not normally need to do so.

Parameters:
Name Type Attributes Description
tagManager WirelessTagManager

the tag manager instance to select

callback module:wirelesstags~apiCallback <optional>
Source:
Returns:

resolves to the tag manager instance

Type
Promise

Events

connect

Connect event. Emitted after the platform object successfully connects to the cloud.

Type:
Source:

discover

Discover event. Emitted for every WirelessTagManager instance discovered.

Type:
Source: