JSPM

  • Created
  • Published
  • Downloads 851
  • Score
    100M100P100Q113975F
  • 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: {
    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, [limit=null], [offset=null]) → Promise

Get a list of source images.

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

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.

rokka.sourceimages.create('myorg', require('fs').createReadStream('picture.png'))
     .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) {});

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.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')