2.1.1 • Published 3 years ago

universe-js v2.1.1

Weekly downloads
59
License
MIT
Repository
github
Last release
3 years ago

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

3 years ago

2.1.0

3 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

8 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago