@3dlook/saia-sdk 中文文档教程

发布于 3年前 浏览 18 项目主页 更新于 3年前

SAIA Javascript SDK

构建状态版本Dependencies

Installing

要将 SAIA SDK 作为 npm 包安装到您的项目中,请使用 npm 使用以下命令:

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

Building

使用以下命令将存储库克隆到本地计算机

要构建 SAIA SDK,请使用 https:

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

或 ssh:

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

然后在终端中进入克隆的项目目录:

cd saia-sdk

并构建它:

npm run build:prod

Usage

SAIA Javascript SDK 用作 API 包装器。 要使用它,您只需要创建一个 SAIA 类的新实例,然后调用您需要的方法。

示例:

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));

API

Classes

API

API 包装类

MTMClient

MTMClient 类

Person

Person 类

Product

Product 类

Queue

Queue 类

Sizechart

Product 类

SAIA

Functions

getBase64(file)Promise.<string>

将文件或 Blob 对象转换为 base64 字符串

getFileName(blob)

获取带有 Blob 扩展名的文件名

getTaskError(tasks)string

获取错误描述

API

API 包装类

种类:全局类

new API(options)

类构造

ParamTypeDescription
optionsObjectoptions
options.hoststringAPI url
options.keystringAPI key

Example

const api = new API({
  key: '<your key>',
  host: '<api host url>',
});

MTMClient

MTMClient类

Kind:全局类

new MTMClient(host, axios)

MTMClient的类构造函数

ParamTypeDescription
hoststringhost url
axiosAxiosaxios instance

mtmClient.create(params) ⇒ Promise.&lt;number&gt;

创建mtm客户端

Kind:的实例方法MTMClient
返回Promise.&lt;number&gt; - mtm 客户端的 id

ParamTypeDescription
paramsobjectmtm client's parameters
params.firstNamestringmtm client's first name
[params.lastName]stringmtm client's last name
params.unitstringmtm client's unit - cm or in
[params.phone]stringmtm client's phone number - cm or in
[params.email]stringmtm client's email - cm or in
[params.source]stringthe source of the request - dashboard, widget
[params.notes]stringadditional information about mtm client
[params.widgetId]stringwidget object id

Example

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

// create person only with metadata
// and get its id
saia.api.mtmClient.create({
  firstName: 'Stephen',
  lastName: 'King',
  unit: 'in',
})
  .then(mtmClientId => console.log(mtmClientId))
  .catch(err => console.log(err));

mtmClient.update(params) ⇒ Promise.&lt;number&gt;

更新mtm客户端

KindMTMClient
的实例方法 返回Promise.&lt;number&gt; - mtm 客户端的 id

ParamTypeDescription
paramsobjectmtm client's parameters
params.firstNamestringmtm client's first name
[params.lastName]stringmtm client's last name
params.unitstringmtm client's unit - cm or in
[params.phone]stringmtm client's phone number - cm or in
[params.email]stringmtm client's email - cm or in
[params.source]stringthe source of the request - dashboard, widget
[params.notes]stringadditional information about mtm client
[params.widgetId]stringwidget object id

Example

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

// update person only with metadata
// and get its id
const existingMtmClientId = 1;

saia.api.mtmClient.update(existingMtmClientId, {
  firstName: 'Stephen',
  lastName: 'King',
  unit: 'in',
})
  .then(mtmClientId => console.log(mtmClientId))
  .catch(err => console.log(err));

mtmClient.createPerson(mtmClientId, params) ⇒ Promise.&lt;(string\|number)&gt;

仅使用元数据(性别和身高)为 mtm 客户端创建人员 或照片(性别、身高、正面图像、侧面图像)。

如果您仅使用元数据创建 Person,那么您将 获取人的 ID。 如果您使用元数据和图像创建 Person, 您将获得任务集 ID

KindMTMClient
的实例方法 返回Promise.&lt;(string\|number)&gt; - 人的id或taskset id

ParamTypeDescription
mtmClientIdnumbermtm client id
paramsobjectperson's parameters
params.genderstringperson's gender
params.heightnumberperson's height
[params.measurementsType]stringtype of measurements - all
[params.frontImage]stringperson's Base64 encoded front photo
[params.sideImage]stringperson's Base64 encoded side photo
[params.weight]stringperson's weight in kg
[params.weightTopBorder]stringperson's top weight border in kg
[params.weightBottomBorder]stringperson's bottom weight border in kg

Example

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

// create person only with metadata
// and get its id
saia.api.mtmClient.createPerson(mtmClientId, {
  gender: 'male',
  height: 180,
})
  .then(personId => console.log(personId))
  .catch(err => console.log(err));

// create person only with metadata and images
// and get taskset id. You can use it to track
// calculation process by using saia.api.queue.getResults(taskSetId)
saia.api.mtmClient.createPerson(mtmClientId, {
  gender: 'male',
  height: 180,
  frontImage: <frontImage>,
  sideImage: <sideImage>,
})
  .then(taskSetId => console.log(taskSetId))
  .catch(err => console.log(err));

Person

Person类

Kind:全局类

new Person(host, axios)

Person的类构造函数

ParamTypeDescription
hoststringhost url
axiosAxiosaxios instance

person.create(params) ⇒ Promise.&lt;(string\|number)&gt;

仅使用元数据(性别和身高)创建人物 或照片(性别、身高、正面图像、侧面图像)。

如果您仅使用元数据创建 Person,那么您将 获取人的 ID。 如果您使用元数据和图像创建 Person, 您将获得任务集 ID

KindPerson
的实例方法 返回Promise.&lt;(string\|number)&gt; - 人的id或taskset id

ParamTypeDescription
paramsobjectperson's parameters
params.genderstringperson's gender
params.heightnumberperson's height
[params.measurementsType]stringtype of measurements - all
[params.hasVirtualTryOn]booleanshould apply virtual try on
[params.product]anyproduct sku which would be used for virtual try on
[params.frontImage]stringperson's Base64 encoded front photo
[params.sideImage]stringperson's Base64 encoded side photo
[params.weight]stringperson's weight in kg
[params.weightTopBorder]stringperson's top weight border in kg
[params.weightBottomBorder]stringperson's bottom weight border in kg
[params.deviceCoordinates]Objectuser device x, y, z coordinates during photos
params.deviceCoordinates.frontPhotoObjectuser device x, y, z coordinates during Front photo
params.deviceCoordinates.frontPhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.frontPhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.frontPhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.deviceCoordinates.sidePhotoObjectuser device x, y, z coordinates during Side photo
params.deviceCoordinates.sidePhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.sidePhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.sidePhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.photoFlowTypestringphoto flow type ("friend" or "hand").

Example

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

// create person only with metadata
// and get its id
saia.api.person.create({
  gender: 'male',
  height: 180,
})
  .then(personId => console.log(personId))
  .catch(err => console.log(err));

// create person only with metadata and images
// and get taskset id. You can use it to track
// calculation process by using saia.api.queue.getResults(taskSetId)
saia.api.person.create({
  gender: 'male',
  height: 180,
  frontImage: <frontImage>,
  sideImage: <sideImage>,
})
  .then(taskSetId => console.log(taskSetId))
  .catch(err => console.log(err));

person.get(id) ⇒ Promise.&lt;Object&gt;

通过 ID Kind 获取特定的 Person

Person 的实例方法br> 返回Promise.&lt;Object&gt; - Person

ParamTypeDescription
idnumberPerson's ID

Example

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

saia.api.person.get(40)
  .then(person => console.log(person))
  .catch(err => console.log(err));

person.update(id, params) ⇒ Promise.&lt;Object&gt;

按 ID 完全或部分更新人员。 返回人的对象 与元数据。

KindPerson
的实例方法 返回Promise.&lt;Object&gt; - 更新参数

ParamTypeDescription
idnumberPerson''s ID
paramsObjectPerson's parameters
[params.gender]stringPerson's parameters
[params.height]numberPerson's height
[params.frontImage]stringPerson's Base64 encoded frontImage
[params.sideImage]stringPerson's Base64 encoded sideImage
[params.weight]stringperson's weight in kg
[params.weightTopBorder]stringperson's top weight border in kg
[params.weightBottomBorder]stringperson's bottom weight border in kg
[params.deviceCoordinates]Objectuser device x, y, z coordinates during photo
params.deviceCoordinates.frontPhotoObjectuser device x, y, z coordinates during Front photo
params.deviceCoordinates.frontPhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.frontPhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.frontPhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.deviceCoordinates.sidePhotoObjectuser device x, y, z coordinates during Side photo
params.deviceCoordinates.sidePhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.sidePhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.sidePhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.photoFlowTypestringphoto flow type ("friend" or "hand").

Example

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

saia.api.person.update(personId, {
  frontImage: <frontImage>,
  sideImage: <sideImage>,
})
  .then(updatedFields => console.log(updatedFields))
  .catch(err => console.log(err));

person.updateAndCalculate(id, params) ⇒ Promise.&lt;string&gt;

通过 ID 更新一个新的 Person 并开始计算。 返回人员的任务集 ID。

KindPerson
的实例方法 返回Promise.&lt;string&gt; - 任务集 url

ParamTypeDescription
idnumberPerson''s ID
paramsObjectPerson's parameters
[params.measurementsType]stringtype of measurements - all
[params.hasVirtualTryOn]booleanshould apply virtual try on
[params.product]anyproduct sku which would be used for virtual try on
[params.gender]stringPerson's parameters
[params.height]numberPerson's height
[params.frontImage]stringPerson's Base64 encoded frontImage
[params.sideImage]stringPerson's Base64 encoded sideImage
[params.weight]stringperson's weight in kg
[params.weightTopBorder]stringperson's top weight border in kg
[params.weightBottomBorder]stringperson's bottom weight border in kg
[params.deviceCoordinates]Objectuser device x, y, z coordinates during photo
params.deviceCoordinates.frontPhotoObjectuser device x, y, z coordinates during Front photo
params.deviceCoordinates.frontPhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.frontPhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.frontPhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.deviceCoordinates.sidePhotoObjectuser device x, y, z coordinates during Side photo
params.deviceCoordinates.sidePhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.sidePhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.sidePhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.photoFlowTypestringphoto flow type ("friend" or "hand").

示例

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

saia.api.person.updateAndCalculate(personId, {
  frontImage: <frontImage>,
  sideImage: <sideImage>,
})
  .then(taskSetUrl => saia.api.queue.getResults(taskSetUrl))
  .then(person => console.log(person))
  .catch(err => console.log(err));

person.calculate(id, hasVirtualTryOn, product) ⇒ Promise.&lt;string&gt;

通过ID

Kind手动重新计算Person的参数:Person
的实例方法 返回Promise.&lt;string&gt; - Taskset id

ParamTypeDescription
idnumberPerson's ID
hasVirtualTryOnbooleanshould process virtual try on
productanyproduct sku for virtual try on

Example

// in this example we update person's images
// and then manually start recalculation
const saia = new SAIA({
  key: '<your key>',
});

saia.api.person.update({
  frontImage: <frontImage>,
  sideImage: <sideImage>,
})
  .then(updatedFields => saia.api.person.calculate(updatedFields.id))
  .then(taskSetId => console.log(taskSetId))
  .catch(err => console.log(err));

person.virtualTryOn(id, product) ⇒ Promise.&lt;Object&gt;

为特定的人和产品处理虚拟试穿 结果也将在 person.get(id).virtualtryons 中可用 [ { “id”:tryonId, "productsku": "productSku" “创建”:“日期时间”, “图片:”https://url.to.tryon.image.com“ } ]

KindPerson
的实例方法 返回Promise.&lt;Object&gt; - 对象{上的虚拟尝试 “id”:tryonId, “product_sku”:“productSku” “创建”:“日期时间”, “图片:”https://url.to.tryon.image.com“ }

ParamTypeDescription
idnumberPerson's ID
productanyProduct sku

Product

Product类

Kind:全局类

new Product(host, axios)

Product的类构造函数

ParamTypeDescription
hoststringhost url
axiosAxiosaxios instance

product.get(url) ⇒ Promise.&lt;(Object\|Array)&gt;

通过页面 url 获取产品对象。 如果两个或多个产品具有相同的 url,它可以返回一个数组

KindProduct 的实例方法

ParamTypeDescription
urlstringproduct page url

示例

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

saia.api.product.get('https://saia.3dlook.me/test-product')
  .then(product => console.log(product))
  .catch(err => console.log(err));

product.getSize(params) ⇒ Promise.&lt;object&gt;

根据人员参数获取产品尺寸。 此方法使用尺寸推荐方法的旧实现

KindProduct

ParamTypeDescription
paramsObjectparameters
params.heightnumberperson's height
params.genderstringperson's gender
params.hipsnumberperson's volume_params.hips
params.chestnumberperson's volume_params.chest
params.waistnumberperson's volume_params.waist
params.urlstringproduct url

Example 的实例方法>

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

saia.api.product.getSize({
  height: 173,
  gender: 'female',
  hips: 89,
  chest: 87,
  waist: 73,
  url: 'https://saia.3dlook.me/test-product',
})
  .then(size => console.log(size))
  .catch(err => console.log(err));

product.getRecommendations(params) ⇒ Promise.&lt;object&gt;

根据用户测量结果获取所选产品的尺码建议。 此方法使用尺寸推荐方法的新实现。

种类Product

ParamTypeDescription
paramsObjectparameters
params.genderstringperson's gender
params.hipsnumberperson's volume_params.hips
params.chestnumberperson's volume_params.chest
params.waistnumberperson's volume_params.waist
params.urlstringproduct url

Example

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

saia.api.product.getRecommendations({
  gender: 'female',
  hips: 89,
  chest: 87,
  waist: 73,
  url: 'https://saia.3dlook.me/test-product',
})
  .then(size => console.log(size))
  .catch(err => console.log(err));

的实例方法/a>

Queue

Queue 类

Kind: 全局类

new Queue(host, axios)

Queue 的类构造

ParamTypeDescription
hoststringhost url
axiosAxiosaxios instance

queue.get(id) ⇒ Promise.&lt;object&gt;

通过获取有关任务的信息taskset id

KindQueue

ParamTypeDescription
idstringtaskset id

Example

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

saia.api.queue.get('4d563d3f-38ae-4b51-8eab-2b78483b153e')
  .then(task => console.log(task))
  .catch(err => console.log(err));

的实例方法

queue.getResults(id, [delay], [personId]) ⇒ Promise.&lt;object&gt;

获取人员处理

Kind的结果:Queue的实例方法

ParamTypeDescription
idstringtaskset id
[delay]numberdelay before next check
[personId]numberperson id

Example< /strong>

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

saia.api.queue.getResults('4d563d3f-38ae-4b51-8eab-2b78483b153e')
  .then(person => console.log(person))
  .catch(err => console.log(err));

// you also can specify the delay between checks
saia.api.queue.getResults('4d563d3f-38ae-4b51-8eab-2b78483b153e', 3400)
  .then(person => console.log(person))
  .catch(err => console.log(err));

Sizechart

产品类

种类:全局类

new Sizechart(host, axios)

产品的类构造函数

ParamTypeDescription
hoststringhost url
axiosAxiosaxios instance

sizechart.getSize(params) ⇒ Promise.&lt;object&gt;

根据人物参数Kind获取品牌和身体部位的尺码

Sizechart的实例方法>

ParamTypeDescription
paramsObjectparameters
params.genderstringperson's gender
params.hipsnumberperson's volume_params.hips
params.chestnumberperson's volume_params.chest
params.waistnumberperson's volume_params.waist
params.body_partnumberbody part
params.brandnumberbrand name
[params.customRecommendation]stringcustom recommendation url part for our clients. For internal usage only or if you have custom url and you know what you're doing

示例

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

saia.api.sizechart.getSize({
  gender: 'female',
  hips: 89,
  chest: 87,
  waist: 73,
  body_part: 'top',
  brand: 'Nike',
})
  .then(size => console.log(size))
  .catch(err => console.log(err));

SAIA

种类:全局类

new SAIA(options)

SAIA类构造

ParamTypeDescription
optionsObjectconfig parameters
options.keystringapi key
options.hoststringapi host url

示例

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

getBase64(file) ⇒ Promise.&lt;string&gt;

将File或Blob对象转换为base64字符串

Kind: 全局函数

ParamTypeDescription
fileFile | Blobimage file

getFileName(blob)

获取 Blob 扩展名的文件名

Kind: 全局函数

ParamTypeDescription
blobBlobfile

getTaskError(tasks) ⇒ string

获取错误描述

< strong>Kind: global function

ParamTypeDescription
tasksArrayarray of tasks

Testing

要运行测试,你需要在终端/consol:

Linux/macOS

$ export API_KEY='<your api key>' && export API_HOST='<host>' && npm test

Windows上运行这个命令

$ set API_KEY='<your api key>' && set API_HOST='<host>' && npm test

SAIA Javascript SDK

Build StatusVersionDependencies

Installing

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

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

Building

To build SAIA SDK, clone repository to your local machine

with https:

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

or with ssh:

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

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

cd saia-sdk

and build it:

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:

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));

API

Classes

API

API wrapper class

MTMClient

MTMClient class

Person

Person class

Product

Product class

Queue

Queue class

Sizechart

Product class

SAIA

Functions

getBase64(file)Promise.<string>

Convert File or Blob object to base64 string

getFileName(blob)

Get file name with extension for Blob

getTaskError(tasks)string

Get error description

API

API wrapper class

Kind: global class

new API(options)

Class constructor

ParamTypeDescription
optionsObjectoptions
options.hoststringAPI url
options.keystringAPI key

Example

const api = new API({
  key: '<your key>',
  host: '<api host url>',
});

MTMClient

MTMClient class

Kind: global class

new MTMClient(host, axios)

MTMClient's class constructor

ParamTypeDescription
hoststringhost url
axiosAxiosaxios instance

mtmClient.create(params) ⇒ Promise.&lt;number&gt;

Create mtm client

Kind: instance method of MTMClient
Returns: Promise.&lt;number&gt; - mtm client's id

ParamTypeDescription
paramsobjectmtm client's parameters
params.firstNamestringmtm client's first name
[params.lastName]stringmtm client's last name
params.unitstringmtm client's unit - cm or in
[params.phone]stringmtm client's phone number - cm or in
[params.email]stringmtm client's email - cm or in
[params.source]stringthe source of the request - dashboard, widget
[params.notes]stringadditional information about mtm client
[params.widgetId]stringwidget object id

Example

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

// create person only with metadata
// and get its id
saia.api.mtmClient.create({
  firstName: 'Stephen',
  lastName: 'King',
  unit: 'in',
})
  .then(mtmClientId => console.log(mtmClientId))
  .catch(err => console.log(err));

mtmClient.update(params) ⇒ Promise.&lt;number&gt;

Update mtm client

Kind: instance method of MTMClient
Returns: Promise.&lt;number&gt; - mtm client's id

ParamTypeDescription
paramsobjectmtm client's parameters
params.firstNamestringmtm client's first name
[params.lastName]stringmtm client's last name
params.unitstringmtm client's unit - cm or in
[params.phone]stringmtm client's phone number - cm or in
[params.email]stringmtm client's email - cm or in
[params.source]stringthe source of the request - dashboard, widget
[params.notes]stringadditional information about mtm client
[params.widgetId]stringwidget object id

Example

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

// update person only with metadata
// and get its id
const existingMtmClientId = 1;

saia.api.mtmClient.update(existingMtmClientId, {
  firstName: 'Stephen',
  lastName: 'King',
  unit: 'in',
})
  .then(mtmClientId => console.log(mtmClientId))
  .catch(err => console.log(err));

mtmClient.createPerson(mtmClientId, params) ⇒ Promise.&lt;(string\|number)&gt;

Create person for mtm client only with metadata (gender and height) or with photos (gender, height, frontImage, sideImage).

If you create Person only with metadata, then you will get Person's ID. If you create Person with metadata and images, you will get Taskset ID

Kind: instance method of MTMClient
Returns: Promise.&lt;(string\|number)&gt; - person's id or taskset id

ParamTypeDescription
mtmClientIdnumbermtm client id
paramsobjectperson's parameters
params.genderstringperson's gender
params.heightnumberperson's height
[params.measurementsType]stringtype of measurements - all
[params.frontImage]stringperson's Base64 encoded front photo
[params.sideImage]stringperson's Base64 encoded side photo
[params.weight]stringperson's weight in kg
[params.weightTopBorder]stringperson's top weight border in kg
[params.weightBottomBorder]stringperson's bottom weight border in kg

Example

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

// create person only with metadata
// and get its id
saia.api.mtmClient.createPerson(mtmClientId, {
  gender: 'male',
  height: 180,
})
  .then(personId => console.log(personId))
  .catch(err => console.log(err));

// create person only with metadata and images
// and get taskset id. You can use it to track
// calculation process by using saia.api.queue.getResults(taskSetId)
saia.api.mtmClient.createPerson(mtmClientId, {
  gender: 'male',
  height: 180,
  frontImage: <frontImage>,
  sideImage: <sideImage>,
})
  .then(taskSetId => console.log(taskSetId))
  .catch(err => console.log(err));

Person

Person class

Kind: global class

new Person(host, axios)

Person's class constructor

ParamTypeDescription
hoststringhost url
axiosAxiosaxios instance

person.create(params) ⇒ Promise.&lt;(string\|number)&gt;

Create person only with metadata (gender and height) or with photos (gender, height, frontImage, sideImage).

If you create Person only with metadata, then you will get Person's ID. If you create Person with metadata and images, you will get Taskset ID

Kind: instance method of Person
Returns: Promise.&lt;(string\|number)&gt; - person's id or taskset id

ParamTypeDescription
paramsobjectperson's parameters
params.genderstringperson's gender
params.heightnumberperson's height
[params.measurementsType]stringtype of measurements - all
[params.hasVirtualTryOn]booleanshould apply virtual try on
[params.product]anyproduct sku which would be used for virtual try on
[params.frontImage]stringperson's Base64 encoded front photo
[params.sideImage]stringperson's Base64 encoded side photo
[params.weight]stringperson's weight in kg
[params.weightTopBorder]stringperson's top weight border in kg
[params.weightBottomBorder]stringperson's bottom weight border in kg
[params.deviceCoordinates]Objectuser device x, y, z coordinates during photos
params.deviceCoordinates.frontPhotoObjectuser device x, y, z coordinates during Front photo
params.deviceCoordinates.frontPhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.frontPhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.frontPhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.deviceCoordinates.sidePhotoObjectuser device x, y, z coordinates during Side photo
params.deviceCoordinates.sidePhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.sidePhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.sidePhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.photoFlowTypestringphoto flow type ("friend" or "hand").

Example

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

// create person only with metadata
// and get its id
saia.api.person.create({
  gender: 'male',
  height: 180,
})
  .then(personId => console.log(personId))
  .catch(err => console.log(err));

// create person only with metadata and images
// and get taskset id. You can use it to track
// calculation process by using saia.api.queue.getResults(taskSetId)
saia.api.person.create({
  gender: 'male',
  height: 180,
  frontImage: <frontImage>,
  sideImage: <sideImage>,
})
  .then(taskSetId => console.log(taskSetId))
  .catch(err => console.log(err));

person.get(id) ⇒ Promise.&lt;Object&gt;

Get a specific Person by ID

Kind: instance method of Person
Returns: Promise.&lt;Object&gt; - Person

ParamTypeDescription
idnumberPerson's ID

Example

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

saia.api.person.get(40)
  .then(person => console.log(person))
  .catch(err => console.log(err));

person.update(id, params) ⇒ Promise.&lt;Object&gt;

Full or Partial update Person by ID. Returns person's object with metadate.

Kind: instance method of Person
Returns: Promise.&lt;Object&gt; - updated parameters

ParamTypeDescription
idnumberPerson''s ID
paramsObjectPerson's parameters
[params.gender]stringPerson's parameters
[params.height]numberPerson's height
[params.frontImage]stringPerson's Base64 encoded frontImage
[params.sideImage]stringPerson's Base64 encoded sideImage
[params.weight]stringperson's weight in kg
[params.weightTopBorder]stringperson's top weight border in kg
[params.weightBottomBorder]stringperson's bottom weight border in kg
[params.deviceCoordinates]Objectuser device x, y, z coordinates during photo
params.deviceCoordinates.frontPhotoObjectuser device x, y, z coordinates during Front photo
params.deviceCoordinates.frontPhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.frontPhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.frontPhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.deviceCoordinates.sidePhotoObjectuser device x, y, z coordinates during Side photo
params.deviceCoordinates.sidePhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.sidePhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.sidePhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.photoFlowTypestringphoto flow type ("friend" or "hand").

Example

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

saia.api.person.update(personId, {
  frontImage: <frontImage>,
  sideImage: <sideImage>,
})
  .then(updatedFields => console.log(updatedFields))
  .catch(err => console.log(err));

person.updateAndCalculate(id, params) ⇒ Promise.&lt;string&gt;

Update a new Person by ID with calculation start. Returns person's task set id.

Kind: instance method of Person
Returns: Promise.&lt;string&gt; - task set url

ParamTypeDescription
idnumberPerson''s ID
paramsObjectPerson's parameters
[params.measurementsType]stringtype of measurements - all
[params.hasVirtualTryOn]booleanshould apply virtual try on
[params.product]anyproduct sku which would be used for virtual try on
[params.gender]stringPerson's parameters
[params.height]numberPerson's height
[params.frontImage]stringPerson's Base64 encoded frontImage
[params.sideImage]stringPerson's Base64 encoded sideImage
[params.weight]stringperson's weight in kg
[params.weightTopBorder]stringperson's top weight border in kg
[params.weightBottomBorder]stringperson's bottom weight border in kg
[params.deviceCoordinates]Objectuser device x, y, z coordinates during photo
params.deviceCoordinates.frontPhotoObjectuser device x, y, z coordinates during Front photo
params.deviceCoordinates.frontPhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.frontPhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.frontPhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.deviceCoordinates.sidePhotoObjectuser device x, y, z coordinates during Side photo
params.deviceCoordinates.sidePhoto.betaXnumbervalue represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device.
params.deviceCoordinates.sidePhoto.gammaYnumbervalue represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device.
params.deviceCoordinates.sidePhoto.alphaZnumbervalue represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360.
params.photoFlowTypestringphoto flow type ("friend" or "hand").

Example

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

saia.api.person.updateAndCalculate(personId, {
  frontImage: <frontImage>,
  sideImage: <sideImage>,
})
  .then(taskSetUrl => saia.api.queue.getResults(taskSetUrl))
  .then(person => console.log(person))
  .catch(err => console.log(err));

person.calculate(id, hasVirtualTryOn, product) ⇒ Promise.&lt;string&gt;

Manual recalculate Person's parameters by ID

Kind: instance method of Person
Returns: Promise.&lt;string&gt; - Taskset id

ParamTypeDescription
idnumberPerson's ID
hasVirtualTryOnbooleanshould process virtual try on
productanyproduct sku for virtual try on

Example

// in this example we update person's images
// and then manually start recalculation
const saia = new SAIA({
  key: '<your key>',
});

saia.api.person.update({
  frontImage: <frontImage>,
  sideImage: <sideImage>,
})
  .then(updatedFields => saia.api.person.calculate(updatedFields.id))
  .then(taskSetId => console.log(taskSetId))
  .catch(err => console.log(err));

person.virtualTryOn(id, product) ⇒ Promise.&lt;Object&gt;

Processing virtual tryon for specific person and product result also would be available in person.get(id).virtualtryons [ { "id": tryonId, "productsku": "productSku" "created": 'datetime', "image: "https://url.to.tryon.image.com" } ]

Kind: instance method of Person
Returns: Promise.&lt;Object&gt; - virtual try on Object { "id": tryonId, "product_sku": "productSku" "created": 'datetime', "image: "https://url.to.tryon.image.com" }

ParamTypeDescription
idnumberPerson's ID
productanyProduct sku

Product

Product class

Kind: global class

new Product(host, axios)

Product's class constructor

ParamTypeDescription
hoststringhost url
axiosAxiosaxios instance

product.get(url) ⇒ Promise.&lt;(Object\|Array)&gt;

Get product object/objects by its page url. It can return an array if two or more products have the same url

Kind: instance method of Product

ParamTypeDescription
urlstringproduct page url

Example

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

saia.api.product.get('https://saia.3dlook.me/test-product')
  .then(product => console.log(product))
  .catch(err => console.log(err));

product.getSize(params) ⇒ Promise.&lt;object&gt;

Get sizes for product based on person parameters. This method uses old implemendation of a size recommendation method

Kind: instance method of Product

ParamTypeDescription
paramsObjectparameters
params.heightnumberperson's height
params.genderstringperson's gender
params.hipsnumberperson's volume_params.hips
params.chestnumberperson's volume_params.chest
params.waistnumberperson's volume_params.waist
params.urlstringproduct url

Example

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

saia.api.product.getSize({
  height: 173,
  gender: 'female',
  hips: 89,
  chest: 87,
  waist: 73,
  url: 'https://saia.3dlook.me/test-product',
})
  .then(size => console.log(size))
  .catch(err => console.log(err));

product.getRecommendations(params) ⇒ Promise.&lt;object&gt;

Get size recommendations for a selected product based on user measurements. This method uses new implementation of a size recommendation method.

Kind: instance method of Product

ParamTypeDescription
paramsObjectparameters
params.genderstringperson's gender
params.hipsnumberperson's volume_params.hips
params.chestnumberperson's volume_params.chest
params.waistnumberperson's volume_params.waist
params.urlstringproduct url

Example

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

saia.api.product.getRecommendations({
  gender: 'female',
  hips: 89,
  chest: 87,
  waist: 73,
  url: 'https://saia.3dlook.me/test-product',
})
  .then(size => console.log(size))
  .catch(err => console.log(err));

Queue

Queue class

Kind: global class

new Queue(host, axios)

Queue's class constructor

ParamTypeDescription
hoststringhost url
axiosAxiosaxios instance

queue.get(id) ⇒ Promise.&lt;object&gt;

Get information about tasks by taskset id

Kind: instance method of Queue

ParamTypeDescription
idstringtaskset id

Example

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

saia.api.queue.get('4d563d3f-38ae-4b51-8eab-2b78483b153e')
  .then(task => console.log(task))
  .catch(err => console.log(err));

queue.getResults(id, [delay], [personId]) ⇒ Promise.&lt;object&gt;

Get result of person processing

Kind: instance method of Queue

ParamTypeDescription
idstringtaskset id
[delay]numberdelay before next check
[personId]numberperson id

Example

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

saia.api.queue.getResults('4d563d3f-38ae-4b51-8eab-2b78483b153e')
  .then(person => console.log(person))
  .catch(err => console.log(err));

// you also can specify the delay between checks
saia.api.queue.getResults('4d563d3f-38ae-4b51-8eab-2b78483b153e', 3400)
  .then(person => console.log(person))
  .catch(err => console.log(err));

Sizechart

Product class

Kind: global class

new Sizechart(host, axios)

Product's class constructor

ParamTypeDescription
hoststringhost url
axiosAxiosaxios instance

sizechart.getSize(params) ⇒ Promise.&lt;object&gt;

Get sizes for brand and body part based on person parameters

Kind: instance method of Sizechart

ParamTypeDescription
paramsObjectparameters
params.genderstringperson's gender
params.hipsnumberperson's volume_params.hips
params.chestnumberperson's volume_params.chest
params.waistnumberperson's volume_params.waist
params.body_partnumberbody part
params.brandnumberbrand name
[params.customRecommendation]stringcustom recommendation url part for our clients. For internal usage only or if you have custom url and you know what you're doing

Example

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

saia.api.sizechart.getSize({
  gender: 'female',
  hips: 89,
  chest: 87,
  waist: 73,
  body_part: 'top',
  brand: 'Nike',
})
  .then(size => console.log(size))
  .catch(err => console.log(err));

SAIA

Kind: global class

new SAIA(options)

SAIA class constructor

ParamTypeDescription
optionsObjectconfig parameters
options.keystringapi key
options.hoststringapi host url

Example

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

getBase64(file) ⇒ Promise.&lt;string&gt;

Convert File or Blob object to base64 string

Kind: global function

ParamTypeDescription
fileFile | Blobimage file

getFileName(blob)

Get file name with extension for Blob

Kind: global function

ParamTypeDescription
blobBlobfile

getTaskError(tasks) ⇒ string

Get error description

Kind: global function

ParamTypeDescription
tasksArrayarray of tasks

Testing

To run tests, you need to run this command on terminal/consol:

Linux/macOS

$ export API_KEY='<your api key>' && export API_HOST='<host>' && npm test

Windows

$ set API_KEY='<your api key>' && set API_HOST='<host>' && npm test
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文