Javascript modules for interacting with Sparkart's Universe API.
JavaScript CSS HTML
Latest commit 67ef974 Dec 3, 2015 @joanniclaborde joanniclaborde v1.2.0
Permalink
Failed to load latest commit information.
build
lib
login Login prompt Dec 3, 2015
test
.gitignore
CHANGELOG.md
LICENSE
README.md
gulpfile.js
index.js UniverseJS Apr 1, 2015
package.json v1.2.0 Dec 3, 2015

README.md

universe.js

Interacting with Sparkart's Universe API, using SolidusClient! The Universe module inherits from the SolidusClient module.

Usage

Construction

var Universe = require('universe-js');
var universe = new Universe({key: '12345'});
universe.context = {...};

Options:

  • environment - The Universe API to use, choices are production and staging. Defaults to production.
  • key - The Universe API key to use.

.init

Fetches the current fanclub and logged-in customer. If the instance's context already contains a resources.fanclub key, it is used instead of being fetched from the API. The callback argument is optional.

universe.init(function(err, data) {
  if (err) throw err;
  if (data.customer) {
    // The customer is logged in
  }
});
universe.on('error', function(err) {
  throw err;
});
universe.on('ready', function(data) {
  if (data.customer) {
    // The customer is logged in
  }
});

Callback arguments:

  • err - Error that occured while retrieving the resources.
  • data - Object containing the current fanclub and customer. customer is available only if the customer is logged in.

Emitted events:

  • error - Called with the same err argument as the callback.
  • ready - Called with the same data argument as the callback.

.render

Same as solidus_client.render but the resources can be Universe endpoints.

var view = {
  resources: {
    events: '/events',
    other: 'http://www.other.com'
  },
  ...
};
universe.render(view, function(err, html) {
  // ...
});

.get

Fetch a resource. The URL can be a Universe endpoint.

universe.get('/events', function(err, data) {
  // ...
});

.post

Post to a resource. The URL can be a Universe endpoint.

universe.post('/account', {...}, function(err, data) {
  // ...
});