onprint-sdk-light
TypeScript icon, indicating that this package has built-in type declarations

0.6.0 • Public • Published

Onprint Javascript SDK Light

This SDK is the easiest way to explore LTU Tech image recognition tools by wraping ONprint API endpoint and provides simple methods to access it

Instalation

npm install onprint-sdk-light

Usage

There is two ways to use this SDK:

SDK Class Object

This object contains all the methods to request an Enriched Image, Pictures (by Id or File) and send clickstream action to feed the reporting

Initialize SDK

To initialize the SDK you need to provide informations used by our reporting service:

  • Device Header
  • Application Header
  • Api Key
import {SdkLight} from 'onprint-sdk-light';
 
const applicationHeader = {
    name: 'Your Application App Name',
    version: '1.0.0',
    id: 'Random Id' // Unique for each user
};
 
const deviceHeader = {
    name: 'A Device Name',
    version: '8.0.0',
    versionName: 'Oreo'
};
 
const sdk = new SdkLight(YOUR_API_KEY, applicationHeader, deviceHeader);

By default the lang is set to 'fr-FR' but you can change it with:

sdk.setLang('en-EN')

more precision with the Lang features here: ONprint API

Scan Enriched Image

The ONprint API provides you 2 ways to request Enriched Images

  • With Image Id

    try {
        const enrichedImage = await sdk.getEnrichedImageById('b9ceb71c-aad9-4c90-80c6-4fe894de85fb');
    } catch (err) {
        console.log(err);
    }
  • With Image File

    try {
        const imgBuffer = fs.readFileSync('image.jpeg');
        const enrichedImage = await sdk.getEnrichedImageByImage(imageBuffer);
    } catch (err) {
        console.log(err);
    }

Scan Picture

The ONprint API provides you 2 ways to request Pictures

  • With Image Id

    try {
        const picture = await sdk.getPictureByImage('b9ceb71c-aad9-4c90-80c6-4fe894de85fb');
    } catch (err) {
        console.log(err);
    }
  • With Image File

    try {
        const imgBuffer = fs.readFileSync('picture.jpeg');
        const pictures = await sdk.getPictureByImage(imageBuffer);
    } catch (err) {
        console.log(err);
    }

As you can see, the SDK methodes return Promise, if an error occure the SDK will throw an Error to catch.

Click on Action

This features is really important to get feedback of your user and have data on which content is most used. To work the Click methode need to get 2 arguments: - ActionId find in the EnrichedImages responses Actions attribute - SessionId Automaticly set to the last valid Enriched Image request

The methode return true in case of success

try {
    const enrichedImage = await sdk.getEnrichedImageById('b9ceb71c-aad9-4c90-80c6-4fe894de85fb');
    sdk.clickOnAction(enrichedImage.Actions[0].Id);
} catch (err) {
    console.log(err);
}

API Functions

If you prefer not use the SDK Class we provide you, it's possible to use directly the Onprint API call and have more controle with the functions return and behavior.

Enriched Image

Picture

Click Stream

Test

To run test simply launch the command with your API KEY

API_KEY=your_api_key npm run test

Support

You can contact me for any issue at bmartins@ltutech.com

License

© LTU Tech 2018 All Rights Reserved

Package Sidebar

Install

npm i onprint-sdk-light

Weekly Downloads

1

Version

0.6.0

License

none

Unpacked Size

22.8 kB

Total Files

12

Last publish

Collaborators

  • bootis
  • bmartins42