mojio-js-sdk
Version:
Mojio javascript REST client.
713 lines (710 loc) • 22.6 kB
HTML
<html>
<head>
<meta charset='UTF-8'>
<title>CoffeeScript API Documentation</title>
<script src='../javascript/application.js'></script>
<script src='../javascript/search.js'></script>
<link rel='stylesheet' href='../stylesheets/application.css' type='text/css'>
</head>
<body>
<div id='base' data-path='../'></div>
<div id='header'>
<div id='menu'>
<a href='../alphabetical_index.html' title='Index'>
Index
</a>
»
<span class='title'>MojioPushSDK</span>
</div>
</div>
<div id='content'>
<h1>
Class:
MojioPushSDK
</h1>
<table class='box'>
<tr>
<td>Defined in:</td>
<td>MojioPushSDK.coffee</td>
</tr>
<tr>
<td>Inherits:</td>
<td>
<a href='../class/MojioRestSDK.html'>MojioRestSDK</a>
</td>
</tr>
</table>
<h2>Overview</h2>
<div class='docstring'>
<p>The Push segment of the Mojio SDK. The Push segement of the SDK provides a mechanism for applications to subscribe
to changes occurring on primary API resources of Vehicles, Users, Mojios, Trips, Groups, and Apps.</p><p>Mojio maintains a separate "Push" style API where applications can subscribe to changes on resources and receive those
changes across multiple transports. Current transports include: SIGNALR, HTTPS POST, and MQTT.</p><p>Subscriptions are instantiated by posting "Observers" to the Push API's REST interface. Observers define what, when
and how data is channeled to the application from the server.</p><p>What is defined by specification of the resource type and id.
The "What" delivered can be narrowed down to a specific set of fields through a filter specification (basically a list of the names of the fields).</p><p>The "When" is defined by optional conditions, debounce, throttle, and timings.</p><p>The "How" is defined by a transport specification
that has the connection details to a method, server or hub, depending on the transport type. For SignalR, Mojio provides
the hub of communication, for other protocols like MQTT or Http Post, the application writer is responsible for the
communication infrastructure.</p><p>The inheritance path is:
MojioPushSDK->MojioRestSDK->MojioAuthSDK->MojioModelSDK</p>
<div class='examples'>
<h3>Examples:</h3>
<h4>
</h4>
<pre><code class='coffeescript'>mojioSdk = new MojioSDK({sdk: MojioPushSDK}) # instantiate the mojioSDK to all available API calls.</code></pre>
</div>
</div>
<div class='tags'>
</div>
<h2>Instance Method Summary</h2>
<ul class='summary'>
<li>
<span class='signature'>
<a href='#observe-dynamic'>
#
(object)
<b>observe</b><span>(key)</span>
</a>
</span>
<span class='desc'>
Observe a Vehicle, Mojio, or User object in the Mojio API.
</span>
</li>
<li>
<span class='signature'>
<a href='#fields-dynamic'>
#
(object)
<b>fields</b><span>(fields)</span>
</a>
</span>
<span class='desc'>
Limit the fields returned to a specific set of properties.
</span>
</li>
<li>
<span class='signature'>
<a href='#where-dynamic'>
#
(object)
<b>where</b><span>(clause)</span>
</a>
</span>
<span class='desc'>
The condition that must be satisfied for the observer to fire.
</span>
</li>
<li>
<span class='signature'>
<a href='#transport-dynamic'>
#
(object)
<b>transport</b><span>(transport)</span>
</a>
</span>
<span class='desc'>
Specify how data is sent.
</span>
</li>
<li>
<span class='signature'>
<a href='#throttle-dynamic'>
#
(object)
<b>throttle</b><span>(throttle)</span>
</a>
</span>
<span class='desc'>
Limit how much data is sent.
</span>
</li>
<li>
<span class='signature'>
<a href='#debounce-dynamic'>
#
(object)
<b>debounce</b><span>(debounce)</span>
</a>
</span>
<span class='desc'>
Debounce the condtion for the obserer.
</span>
</li>
<li>
<span class='signature'>
<a href='#timing-dynamic'>
#
(object)
<b>timing</b><span>(state)</span>
</a>
</span>
<span class='desc'>
Set the timing of the observer.
</span>
</li>
</ul>
<h2>
<small>Inherited Method Summary</small>
<h3 class='inherited'>
Methods inherited from
<a href='../class/MojioRestSDK.html'>MojioRestSDK</a>
</h3>
<p class='inherited'>
<a href='../class/MojioRestSDK.html#put-dynamic'>#put</a>
<a href='../class/MojioRestSDK.html#post-dynamic'>#post</a>
<a href='../class/MojioRestSDK.html#delete-dynamic'>#delete</a>
<a href='../class/MojioRestSDK.html#get-dynamic'>#get</a>
<a href='../class/MojioRestSDK.html#query-dynamic'>#query</a>
<a href='../class/MojioRestSDK.html#select-dynamic'>#select</a>
<a href='../class/MojioRestSDK.html#filter-dynamic'>#filter</a>
<a href='../class/MojioRestSDK.html#top-dynamic'>#top</a>
<a href='../class/MojioRestSDK.html#skip-dynamic'>#skip</a>
<a href='../class/MojioRestSDK.html#orderby-dynamic'>#orderby</a>
<a href='../class/MojioRestSDK.html#field-dynamic'>#field</a>
<a href='../class/MojioRestSDK.html#add-dynamic'>#add</a>
<a href='../class/MojioRestSDK.html#set-dynamic'>#set</a>
<a href='../class/MojioRestSDK.html#remove-dynamic'>#remove</a>
<a href='../class/MojioAuthSDK.html#authorize-dynamic'>#authorize</a>
<a href='../class/MojioAuthSDK.html#unauthorize-dynamic'>#unauthorize</a>
<a href='../class/MojioAuthSDK.html#token-dynamic'>#token</a>
<a href='../class/MojioAuthSDK.html#parse-dynamic'>#parse</a>
<a href='../class/MojioAuthSDK.html#refresh-dynamic'>#refresh</a>
<a href='../class/MojioAuthSDK.html#login-dynamic'>#login</a>
<a href='../class/MojioAuthSDK.html#consent-dynamic'>#consent</a>
<a href='../class/MojioAuthSDK.html#loginAndConsent-dynamic'>#loginAndConsent</a>
<a href='../class/MojioAuthSDK.html#prompt-dynamic'>#prompt</a>
<a href='../class/MojioAuthSDK.html#scope-dynamic'>#scope</a>
<a href='../class/MojioAuthSDK.html#username-dynamic'>#username</a>
<a href='../class/MojioAuthSDK.html#email-dynamic'>#email</a>
<a href='../class/MojioAuthSDK.html#password-dynamic'>#password</a>
<a href='../class/MojioAuthSDK.html#credentials-dynamic'>#credentials</a>
<a href='../class/MojioAuthSDK.html#with-dynamic'>#with</a>
<a href='../class/MojioAuthSDK.html#getToken-dynamic'>#getToken</a>
<a href='../class/MojioModelSDK.html#setup-dynamic'>#setup</a>
<a href='../class/MojioModelSDK.html#setCriteria-dynamic'>#setCriteria</a>
<a href='../class/MojioModelSDK.html#users-dynamic'>#users</a>
<a href='../class/MojioModelSDK.html#vehicles-dynamic'>#vehicles</a>
<a href='../class/MojioModelSDK.html#mojios-dynamic'>#mojios</a>
<a href='../class/MojioModelSDK.html#trips-dynamic'>#trips</a>
<a href='../class/MojioModelSDK.html#apps-dynamic'>#apps</a>
<a href='../class/MojioModelSDK.html#groups-dynamic'>#groups</a>
<a href='../class/MojioModelSDK.html#permissions-dynamic'>#permissions</a>
<a href='../class/MojioModelSDK.html#images-dynamic'>#images</a>
<a href='../class/MojioModelSDK.html#tags-dynamic'>#tags</a>
<a href='../class/MojioModelSDK.html#details-dynamic'>#details</a>
<a href='../class/MojioModelSDK.html#histories-dynamic'>#histories</a>
<a href='../class/MojioModelSDK.html#states-dynamic'>#states</a>
<a href='../class/MojioModelSDK.html#locations-dynamic'>#locations</a>
<a href='../class/MojioModelSDK.html#mock-dynamic'>#mock</a>
</p>
</h2>
<h2>Instance Method Details</h2>
<div class='methods'>
<div class='method_details'>
<p class='signature' id='observe-dynamic'>
#
(object)
<b>observe</b><span>(key)</span>
<br>
</p>
<div class='docstring'>
<p>Observe a Vehicle, Mojio, or User object in the Mojio API.</p><p>Observers on particular objects are setup by chaining them with calls to the RestSDK's entity methods: Vehicle, Vehicles, User, Users, Mojio, or Mojios.
The observer will observe the entities specified in those calls.</p>
<div class='examples'>
<h3>Examples:</h3>
<h4>
observe all vehicles for this user, assumes SignalR transport and the callback given is the handler.
</h4>
<pre><code class='coffeescript'>sdk.observe("MyUniqueKeyName")
.vehicles() # observe all vehicles for the account of the authorized token
.callback((error, result) ->
if (typeof result is 'boolean') # this is a callback via nodejs return
console.log("Vehicle Observer created with signalR transport and this callback as the handler")
else if (result instanceof 'object') # we are in a callback via signalR
... # receive the changes to the objects.
)</code></pre>
<h4>
</h4>
<pre><code class='coffeescript'>sdk.observe("MyUniqueKeyName")
.vehicle("[some id]") # observe all vehicles for a specific vehicle
.callback((error, result) ->
console.log("success in creating an observer") if (result?)
)</code></pre>
</div>
</div>
<div class='tags'>
<h3>Parameters:</h3>
<ul class='param'>
<li>
<span class='name'>key</span>
<span class='type'>
(
<tt>string</tt>
)
</span>
—
<span class='desc'>This parameter is a name that can be used to find the observer later, or to modify it. </span>
</li>
<li>
<span class='name'>callback</span>
<span class='type'>
(
<tt>function</tt>
)
</span>
—
<span class='desc'>Optional parameter to initiate the fluent chain if needed. </span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'></span>
(
<tt>object</tt>
)
—
<span class='desc'>this </span>
</li>
</ul>
</div>
</div>
<div class='method_details'>
<p class='signature' id='fields-dynamic'>
#
(object)
<b>fields</b><span>(fields)</span>
<br>
</p>
<div class='docstring'>
<p>Limit the fields returned to a specific set of properties.</p><p>Fields are given as an array of strings that are the names of the properties of the entity returned.</p>
<div class='examples'>
<h3>Examples:</h3>
<h4>
</h4>
<pre><code class='coffeescript'>sdk.observe({key: "MyUniqueKeyName"})
.vehicles()
.fields(
"VIN",
"AccidentState",
"Battery",
"Location",
"Heading",
"Altitude",
"Speed",
"Accelerometer",
"LastContactTime",
"GatewayTimeStamp",
"FuelLevel"
])</code></pre>
</div>
</div>
<div class='tags'>
<h3>Parameters:</h3>
<ul class='param'>
<li>
<span class='name'>fields</span>
<span class='type'>
(
<tt>array of strings</tt>
)
</span>
—
<span class='desc'>The fields of an object to deliver in the results of a query. </span>
</li>
<li>
<span class='name'>callback</span>
<span class='type'>
(
<tt>function</tt>
)
</span>
—
<span class='desc'>Optional parameter to initiate the fluent chain if needed. </span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'></span>
(
<tt>object</tt>
)
—
<span class='desc'>this </span>
</li>
</ul>
</div>
</div>
<div class='method_details'>
<p class='signature' id='where-dynamic'>
#
(object)
<b>where</b><span>(clause)</span>
<br>
</p>
<div class='docstring'>
<p>The condition that must be satisfied for the observer to fire.</p><p>When the condition fires, the observer sends data. For instance, if the observer is setup
with the condition send data when MilStatus is true, it will fire when the MilStatus field on the vehicle
changes from false to true. See "timing" below to change the time when the data is sent.</p>
<div class='examples'>
<h3>Examples:</h3>
<h4>
Send only when the battery level transitions is in this condition
</h4>
<pre><code class='coffeescript'>sdk.observe({key: "MyUniqueKeyName"})
.vehicles()
.where("Battery > min or Battery < max")</code></pre>
</div>
</div>
<div class='tags'>
<h3>Parameters:</h3>
<ul class='param'>
<li>
<span class='name'>clause</span>
<span class='type'>
(
<tt>string</tt>
)
</span>
—
<span class='desc'>A where clause for queries. </span>
</li>
<li>
<span class='name'>callback</span>
<span class='type'>
(
<tt>function</tt>
)
</span>
—
<span class='desc'>Optional parameter to initiate the fluent chain if needed. </span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'></span>
(
<tt>object</tt>
)
—
<span class='desc'>this </span>
</li>
</ul>
</div>
</div>
<div class='method_details'>
<p class='signature' id='transport-dynamic'>
#
(object)
<b>transport</b><span>(transport)</span>
<br>
</p>
<div class='docstring'>
<p>Specify how data is sent.</p><p>Specify the transport used to send data. Possible transports are numerous and include: SignalR, Http Post, MQTT, etc.</p>
<div class='examples'>
<h3>Examples:</h3>
<h4>
Use SignalR as a transport with the given callback:
</h4>
<pre><code class='coffeescript'># coffeescript
sdk.observe({key: "MyUniqueKeyName"})
.vehicles()
.transport({
Type: "SignalR",
Callback: (error, result) -> # function to call when the condition fires.
console.log("Error:"+ JSON.stringify(error)) if error
console.log(JSON.stringify(result)) if result
})</code></pre>
</div>
</div>
<div class='tags'>
<h3>Parameters:</h3>
<ul class='param'>
<li>
<span class='name'>transport</span>
<span class='type'>
(
<tt>object</tt>
)
</span>
—
<span class='desc'>An object that contains the information about how the entity will be delivered, eg http post, signalr etc. </span>
</li>
<li>
<span class='name'>callback</span>
<span class='type'>
(
<tt>function</tt>
)
</span>
—
<span class='desc'>Optional parameter to initiate the fluent chain if needed. </span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'></span>
(
<tt>object</tt>
)
—
<span class='desc'>this </span>
</li>
</ul>
</div>
</div>
<div class='method_details'>
<p class='signature' id='throttle-dynamic'>
#
(object)
<b>throttle</b><span>(throttle)</span>
<br>
</p>
<div class='docstring'>
<p>Limit how much data is sent.</p><p>Throttle back the data sent by telling the push API to send data at a limited rate. The rate is limited by
specifying a window of time to refrain from sending data after the observer has fired.</p>
<div class='examples'>
<h3>Examples:</h3>
<h4>
Don't send data faster than 10 seconds, in other words, once data is sent, don't send anything again until 10 seconds have past.
</h4>
<pre><code class='coffeescript'>throttle("10 seconds")</code></pre>
</div>
</div>
<div class='tags'>
<h3>Parameters:</h3>
<ul class='param'>
<li>
<span class='name'>throttle</span>
<span class='type'>
(
<tt>object</tt>
)
</span>
—
<span class='desc'>An object that defines how often to send data. </span>
</li>
<li>
<span class='name'>callback</span>
<span class='type'>
(
<tt>function</tt>
)
</span>
—
<span class='desc'>Optional parameter to initiate the fluent chain if needed. </span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'></span>
(
<tt>object</tt>
)
—
<span class='desc'>this </span>
</li>
</ul>
</div>
</div>
<div class='method_details'>
<p class='signature' id='debounce-dynamic'>
#
(object)
<b>debounce</b><span>(debounce)</span>
<br>
</p>
<div class='docstring'>
<p>Debounce the condtion for the obserer.</p><p>Prevent false positives by making sure that the condition has fired by specifying either the number of
readings required for a condition to be considered true, or specifying the amount of time the condition must
be true in order to be sure of the change.</p>
<div class='examples'>
<h3>Examples:</h3>
<h4>
Set the observer so that it detects a transition if 6 true data points show the change.
</h4>
<pre><code class='coffeescript'>debounce({ DataPoints: 6 })</code></pre>
<h4>
Set the observer so that it detects a transition if the change has been active for 15 seconds.
</h4>
<pre><code class='coffeescript'>debounce({ TimeWindow: "00:00:15" }) # time window is given in a csharp timespan format</code></pre>
<h4>
Set the observer so that it detects a transition there are 6 true datapoints within 15 seconds.
</h4>
<pre><code class='coffeescript'>debounce({ DataPoints: 6, TimeWindow: "00:00:15" }) # time window is given in a csharp timespan format</code></pre>
</div>
</div>
<div class='tags'>
<h3>Parameters:</h3>
<ul class='param'>
<li>
<span class='name'>debounce</span>
<span class='type'>
(
<tt>object</tt>
)
</span>
—
<span class='desc'>An object that defines how to smooth out detection of transitions of state. </span>
</li>
<li>
<span class='name'>callback</span>
<span class='type'>
(
<tt>function</tt>
)
</span>
—
<span class='desc'>Optional parameter to initiate the fluent chain if needed. </span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'></span>
(
<tt>object</tt>
)
—
<span class='desc'>this </span>
</li>
</ul>
</div>
</div>
<div class='method_details'>
<p class='signature' id='timing-dynamic'>
#
(object)
<b>timing</b><span>(state)</span>
<br>
</p>
<div class='docstring'>
<p>Set the timing of the observer. Timing refers to when to send data in relation to the given condition.
Possible timings are: leading, trailing, high, low, edge, and continuous.</p><p>leading- deliver data when the condition transitions from false to true.</p><p>trailing- deliver the data when the condition transitions from true to false</p><p>high- deliver the data when the condition is true and information comes from the vehicle (subject to throttle)</p><p>low- deliver the data when the condition is false and information comes from the vehicle (subject to throttle)</p><p>edge- both leading and trailing edges</p><p>continuous- both high and low</p>
<div class='examples'>
<h3>Examples:</h3>
<h4>
Set the observer so that it detects a transition if 6 data points show the change.
</h4>
<pre><code class='coffeescript'>timing("high")</code></pre>
<h4>
Set the observer so that it detects a transition if the change has been active for 15 seconds.
</h4>
<pre><code class='coffeescript'>timing("leading")</code></pre>
</div>
</div>
<div class='tags'>
<h3>Parameters:</h3>
<ul class='param'>
<li>
<span class='name'>states</span>
<span class='type'>
(
<tt>string</tt>
)
</span>
—
<span class='desc'>An object that defines how to smooth out detection of transitions of state. </span>
</li>
<li>
<span class='name'>callback</span>
<span class='type'>
(
<tt>function</tt>
)
</span>
—
<span class='desc'>Optional parameter to initiate the fluent chain if needed. </span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'></span>
(
<tt>object</tt>
)
—
<span class='desc'>this </span>
</li>
</ul>
</div>
</div>
</div>
</div>
<div id='footer'>
November 17, 15 17:54:44 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>
2.0.11
✲
Press H to see the keyboard shortcuts
✲
<a href='http://twitter.com/netzpirat' target='_parent'>@netzpirat</a>
✲
<a href='http://twitter.com/_inossidabile' target='_parent'>@_inossidabile</a>
</div>
<iframe id='search_frame'></iframe>
<div id='fuzzySearch'>
<input type='text'>
<ol></ol>
</div>
<div id='help'>
<p>
Quickly fuzzy find classes, mixins, methods, file:
</p>
<ul>
<li>
<span>T</span>
Open fuzzy finder dialog
</li>
</ul>
<p>
Control the navigation frame:
</p>
<ul>
<li>
<span>L</span>
Toggle list view
</li>
<li>
<span>C</span>
Show class list
</li>
<li>
<span>I</span>
Show mixin list
</li>
<li>
<span>F</span>
Show file list
</li>
<li>
<span>M</span>
Show method list
</li>
<li>
<span>E</span>
Show extras list
</li>
</ul>
<p>
You can focus and blur the search input:
</p>
<ul>
<li>
<span>S</span>
Focus search input
</li>
<li>
<span>Esc</span>
Blur search input
</li>
</ul>
</div>
</body>
</html>