JSPM

  • Created
  • Published
  • Downloads 652
  • Score
    100M100P100Q114211F
  • License MIT

JavaScript client library for Rokka.io

Package Exports

  • rokka

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rokka) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Rokka.js NPM version Dependency Status

JavaScript client library for Rokka.

Install

$ npm install rokka --save

Usage

var rokka = require('rokka')({
  apiKey: 'apikey'
});

rokka.sourceimages.list('myorg')
  .then(function(result) {
    console.log(result);
  })
  .catch(function(err) {
    console.error(err);
  });

Documentation

Initializing the Rokka client.

var rokka = require('rokka')({
  apiKey: 'apikey',       // required for certain operations
  apiHost: '<url>',       // default: https://api.rokka.io
  apiVersion: <number>,   // default: 1
  renderHost: '<url>',    // default: https://{organization}.rokka.io
  debug: true,            // default: false
  transport: {
    requestTimeout: <number>,  // milliseconds to wait for rokka server response (default: 30000)
    retries: <number>,         // number of retries when API response is 429 (default: 10)
    minTimeout: <number>,      // minimum milliseconds between retries (default: 1000)
    maxTimeout: <number>,      // maximum milliseconds between retries (default: 10000)
    randomize: <boolean>       // randomize time between retries (default: true)
  }
});

All properties are optional since certain calls don't require credentials.


Users

rokka.users.create(email) → Promise

Register a new user for the Rokka service.

rokka.users.create('user@example.org')
     .then(function(result) {})
     .catch(function(err) {});

Organizations

rokka.organizations.get(name) → Promise

Get a list of organizations.

rokka.organizations.get('myorg')
     .then(function(result) {})
     .catch(function(err) {});

rokka.organizations.create(name, billingEmail, displayName) → Promise

Create an organization.

rokka.organizations.create('myorg', 'billing@example.org', 'Organization Inc.')
     .then(function(result) {})
     .catch(function(err) {});

Memberships

Roles

  • rokka.memberships.ROLES.READ - read-only access
  • rokka.memberships.ROLES.WRITE - read-write access
  • rokka.memberships.ROLES.ADMIN - administrative access

rokka.memberships.create(organization, email, role) → Promise

Add a member to an organization.

rokka.memberships.create('myorg', 'user@example.org', rokka.memberships.ROLES.WRITE)
     .then(function(result) {})
     .catch(function(err) {});

Source Images

rokka.sourceimages.list(organization, params) → Promise

Get a list of source images.

By default, listing sourceimages sorts them by created date descending.

rokka.sourceimages.list('myorg')
     .then(function(result) {})
     .catch(function(err) {});

Searching for images can be achieved using the search parameter. Supported are predefined fields like height, name etc. but also user metadata. If you search for user metadata, the field name has to be prefixed with user:TYPE. All fields are combined with an AND. OR/NOT is not possible.

Example:

const search = {
  'user:int:id': '42',
  'height': '64'
}
rokka.sourceimages.list('myorg', { search: search })
  .then(function(result) {})
  .catch(function(err) {});

The search also supports range and wildcard queries. Check out the rokka documentation for more.

Sorting works with user metadata as well and can be passed as either an array or as a comma separated string.

rokka.sourceimages.get(organization, hash) → Promise

Get information of a source image by hash.

rokka.sourceimages.get('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a')
     .then(function(result) {})
     .catch(function(err) {});

rokka.sourceimages.getWithBinaryHash(organization, binaryHash) → Promise

Get information of a source image by its binary hash.

rokka.sourceimages.getWithBinaryHash('myorg', 'b23e17047329b417d3902dc1a5a7e158a3ee822a')
     .then(function(result) {})
     .catch(function(err) {});

rokka.sourceimages.download(organization, hash) → Promise

Download image by hash.

rokka.sourceimages.download('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a')
     .then(function(result) {})
     .catch(function(err) {});

rokka.sourceimages.create(organization, fileName, binaryData) → Promise

Upload an image.

const file = require('fs').createReadStream('picture.png');
rokka.sourceimages.create('myorg', 'picture.png', file)
     .then(function(result) {})
     .catch(function(err) {});

rokka.sourceimages.delete(organization, hash) → Promise

Delete image by hash.

rokka.sourceimages.delete('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a')
     .then(function(result) {})
     .catch(function(err) {});

User metadata

rokka.sourceimages.meta.add(organization, hash, data) → Promise

Add user metadata to a source image.

See the user metadata documentation for an explanation.

rokka.sourceimages.meta.add('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a', {
  somefield: 'somevalue',
  'int:some_number': 0,
  'delete_this': null
}).then(function(result) {})
  .catch(function(err) {});

rokka.sourceimages.meta.replace(organization, hash, data) → Promise

Replace user metadata of a source image with the passed data.

See the user metadata documentation for an explanation.

rokka.sourceimages.meta.replace('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a', {
  somefield: 'somevalue',
  'int:some_number': 0
}).then(function(result) {})
  .catch(function(err) {});

rokka.sourceimages.meta.delete(organization, hash, [field=null]) → Promise

Replace user metadata of a source image with the passed data.

See the user metadata documentation for an explanation.

rokka.sourceimages.meta.delete('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a')
  .then(function(result) {})
  .catch(function(err) {});

If the third parameter (field) is specified, it will just delete this field.


Operations

Available operations

  • rokka.operations.resize(width, height, options={})
  • rokka.operations.rotate(angle, options={})
  • rokka.operations.dropshadow(options={})
  • rokka.operations.trim(options={})
  • rokka.operations.crop(options={})
  • rokka.operations.noop()

Please refer to the Rokka API documentation

rokka.operations.list() → Promise

Get a list of available stack operations.

rokka.operations.list()
     .then(function(result) {})
     .catch(function(err) {});

Stacks

rokka.stacks.list(organization, [limit=null], [offset=null]) → Promise

Get a list of available stacks.

rokka.stacks.list('myorg')
     .then(function(result) {})
     .catch(function(err) {});

rokka.stacks.get(organization, name) → Promise

Get details about a stack.

rokka.stacks.get('myorg', 'mystack')
  .then(function(result) {})
  .catch(function(result) {});

rokka.stacks.create(organization, name, operations) → Promise

Create a new stack.

var operations = [
  rokka.operations.rotate(45),
  rokka.operations.resize(100, 100)
];

rokka.stacks.create('myorg', 'mystack', operations)
     .then(function(result) {})
     .catch(function(err) {});

rokka.stacks.delete(organization, name) → Promise

Delete a stack.

rokka.stacks.delete('myorg', 'mystack')
     .then(function(result) {})
     .catch(function(err) {});

Render

rokka.render.getUrl(organization, hash, format, [mixed]) → string

Get URL for rendering an image.

rokka.render.getUrl('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a', 'png', 'mystack')