0.2.1 • Published 3 years ago

@slyceit/slyce v0.2.1

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

SlyceJS

This is a client library for consuming the Slyce API.

Requirements

  • Slyce credentials JSON file.

  • One or more Slyce Workflow IDs .

Basic Usage

The client can be initialized with two parameters:

  • credentials - The are the JSON Credentials provided by Slyce.
  • fingerprint - An optional string useful for differentiating access across different instances .

Browser

When running in the browser, axios is required. A version is available on the Slyce CDN.

Initializing

<script type="text/javascript" src="http://cdn.slyce.it/libs/axios/0.21.1/axios.js"></script>
<script type="text/javascript" src="http://cdn.slyce.it/libs/slyce/0.2.1/slyce.js"></script>

<script>
	const credentials = {
		api_key: 'api_key',
		account_id: 'account_id',
		space_id: 'space_id',
	};
	const fingerprint = 'uniqueidentifier';

	const slyce = new slycejs.SlyceClient(credentials, fingerprint);
</script>

Uploading an image

Using this code in browser requires the image to be a Blob (including subclasses such as File) .

Examples
  • File upload:

    	```
    	<script>
    		var imagefile = document.querySelector('#file');
    
    		slyce
    			.uploadImage(imagefile)
    			.then(imageId => console.log(imageId))
    			.catch(console.error);
    	</script>
    	```
  • Using fetch with a URL:

    	```
    	<script>
    		var url = "https://test.com/test.jpg"
    
    		fetch(url)
    			.then(response => response.blob())
    			.then(blob => slyce.uploadImage(blob))
    			.then(imageId => console.log(imageId))
    			.catch(console.error);
    	</script>
    	```

Executing a Workflow

Examples
<script>
	const workflowId = 'workflow_id' // Provided by Slyce.
	const imageId = '123' // Returned ID from `uploadImage` method.

	slyce
		.executeWorkflow(workflowId, { imageId: imageId })
		.then(res => {
			console.log(res.data.type);
        	console.log(res.data.operation);
        	console.log(JSON.stringify(res.data.resultsList, null, 4));
		});
</script>

Server

Installation

$ npm install @slyceit/slyce

Initializing

const { SlyceClient } =  require('@slyceit/slyce');

const credentials = JSON.parse(fs.readFileSync("/path/to/creds.json")) 
const fingerprint = 'uniqueidentifier'

var slyce = new SlyceClient(credentials, fingerprint)

Uploading an image

Using this code in Node requires the image to be a ReadableStream.

Examples
  • File upload:
    	```
    	var stream = fs.createReadStream('/path/to/image.jpg')
    
    	slyce
    		.uploadImage(stream)
    		.then(imageId => console.log(imageId))
    		.catch(console.error);
    	```
  • Using https with a URL:

    	```
    	const https = require('https')
    
    	const url = "https://test.com/test.jpg"
    	
    	new Promise(resolve => https.get(url, res => resolve))
    		.then(stream => slyce.uploadImage(stream))
    		.then(imageId => console.log(imageId))
    		.catch(console.error);
    	```

Executing a Workflow

Examples
const workflowId = 'workflow_id' // Provided by Slyce.
const imageId = '123' // Returned ID from `uploadImage` method.

slyce
	.executeWorkflow(workflowId, { imageId: imageId })
	.then(res => {
		console.log(res.data.type);
        console.log(res.data.operation);
        console.log(JSON.stringify(res.data.resultsList, null, 4));
	});
0.2.1

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.0

3 years ago