Skip to content
/ rokka.js Public
forked from rokka-io/rokka.js

The official JavaScript client library for Rokka.io

License

Notifications You must be signed in to change notification settings

dwirz/rokka.js

This branch is 301 commits behind rokka-io/rokka.js:master.

Repository files navigation

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('[email protected]')
	 .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', '[email protected]', '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', '[email protected]', 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')

About

The official JavaScript client library for Rokka.io

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%