Permalink
Fetching contributors…
Cannot retrieve contributors at this time
84 lines (64 sloc) 2.03 KB

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) {
  // ...
});