Class: MojioSDK

Defined in: MojioSDK.coffee
Inherits: Module

Overview

The Mojio SDK. The Mojio SDK provides a means to easily use Mojio's Authentication Server, REST API, and Push API.

The SDK works with four code segments: MojioModel, MojioAuth, MojioRest, and MojioPush that work together to provide methods for constructing fluent method calls.

MojioModel provides mechanisms for specifying resources and data for resources.

MojioAuth provides a security layer through OAuth2.

MojioRest provides ways to make rest calls to the API and preform CRUD operations as well as update associates with secondary resources like permissions, images or tags.

MojioPush methods provide a way to subscribe to changes that occur on primary resources. The Push SDK allows data to be sent to the application without it requesting it through transports like SignalR, Http Post, MQTT or others.

Four programming styles are supported, synchronous, asynchronous with callbacks (node js style), asynchronous with promises, and asynchronous with reactive streams. Choose one style and or multiple, but each fluent call must operate in one of these modes at the end of the fluent chain.

Examples:

initate a fluent chain to retrieve a the vehicle given using a synchronous call. (don't do this very often).

sdk = new MojioSDK()
result = sdk.get().vehicle(vehicleId).sync()
...

initate a fluent chain to retrieve a the vehicle given using an asynchronous initiation with a callback.

sdk = new MojioSDK()
sdk.get().vehicle(vehicleId).callback((error, result) ->
  ...
)

initate a fluent chain to retrieve a the vehicle given using an asynchronous initiation with a promise.

sdk = new MojioSDK()
promise = sdk.get().vehicle(vehicleId).callback()
...

initate a fluent chain to retrieve a the vehicle given using an asynchronous initiation with a reative stream.

sdk = new MojioSDK()
stream = sdk.get().vehicle(vehicleId).callback()
...

Instance Method Summary

Instance Method Details

# (void) sync()

Sync initiates the fluent chain in a synchronous call, blocking until results are returned. Sync is one of four ways to initiate fluent requests, one of which must be called for requests to be made. This is the least desireable way to initiate a call because it will block until an answer is returned or a timeout occurs. @public

# (void) callback(callback)

The 'callback' method initiates the fluent chain asynchronously by providing a callback(error, result) that will be called once the request has returned. It is one of four ways to initiate fluent requests, one of which must be called for requests to be made. In the case of a redirect (in the auth sdk) control will be returned to a url given and you must call authorize again with the results until 'true' is given in the callback results. @public

Parameters:

  • callback ( function ) A function to call when the fluent chain is complete.

# (void) redirect(redirectClass = null)

The 'redirect' method initiates the fluent chain by performing a redirect given the passed in redirecting technology. The class or object passed in must follow the iRedirect interface and must have a function called "redirect". For browser environments, pass in "{ redirect: (url) -> window.location = url }". For NodeJS express, pass in ServerResponse ('res' passed into the route expression in the examples). For other technologies, this class will depend on the framework used to reply to server requests. Note that even in server environments, the redirect call may need to be wrapped as it is in the browser. @public @ return {object} this

Parameters:

  • redirectClass ( object ) An object with a 'redirect' function implement.

# (string) url()

return the url formed by the fluent chain instead of actually making the rest call.

Returns:

  • ( string ) — Fully formed REST url

# (object) show()

return the internal state object. Used for debugging this sdk.

Returns:

  • ( object ) — Internal state object built up by the fluent chain.

# (void) me()

    Quickly fuzzy find classes, mixins, methods, file:

    Control the navigation frame:

    You can focus and blur the search input: