# SAIA Javascript SDK

[![Build Status](https://travis-ci.org/3dlook-me/saia-sdk.svg?branch=master)](https://travis-ci.org/3dlook-me/saia-sdk)
[![Version](https://img.shields.io/npm/v/@3dlook/saia-sdk.svg?color=f&logo=%403dlook%2Fsaia-sdk)](https://npmjs.com/package/@3dlook/saia-sdk)
[![Dependencies](https://img.shields.io/david/3dlook-me/saia-sdk.svg)](https://www.npmjs.com/package/@3dlook/saia-sdk?activeTab=dependencies)

## Installing

To install SAIA SDK as npm package into your project, use the following command using npm:

```sh
npm install --save @3dlook/saia-sdk
```

# Building

To build SAIA SDK, clone repository to your local machine

with https:

```sh
git clone https://github.com/3dlook-me/saia-sdk.git
```

or with ssh:

```sh
git clone git@github.com:3dlook-me/saia-sdk.git
```

and then enter into the cloned project directory in the terminal:

```sh
cd saia-sdk
```

and build it:

```sh
npm run build:prod
```

## Usage

SAIA Javascript SDK works as an API wrapper. To use it, you only need to create a new instance of the SAIA class and then call methods that you need.

Example:

```js
const frontImage, sideImage;

const saia = new SAIA({
  key: '<your api key>',
});

saia.api.person.create({
  gender: 'female',
  height: 180,
  frontImage: frontImage,
  sideImage: sideImage,
})
  .then((taskSetId) => saia.api.queue.getResults(taskSetId))
  .then(results => console.log(results))
  .catch(err => console.error(err));
```

`frontImage`/`sideImage` can also be passed as a `File`/`Blob` instead of a Base64 string - the SDK will then send the request as `multipart/form-data` instead of JSON:

```js
const saia = new SAIA({
  key: '<your api key>',
});

saia.api.person.create({
  gender: 'female',
  height: 180,
  frontImage: fileInput.files[0],
  sideImage: fileInput2.files[0],
})
  .then((taskSetId) => saia.api.queue.getResults(taskSetId))
  .then(results => console.log(results))
  .catch(err => console.error(err));
```

## API

{{>main}}

## Testing

The test suite is a set of self-contained client-side unit tests (input
validation, error handling) — it does not make real HTTP requests, so no
live API credentials are required:

    $ npm test
