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:
- With the SDK Class
- With the API wrapped functions
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
; 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 = YOUR_API_KEY applicationHeader deviceHeader;
By default the lang is set to 'fr-FR' but you can change it with:
sdk
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
tryconst enrichedImage = await sdk;catch errconsole; -
With Image File
tryconst imgBuffer = fs;const enrichedImage = await sdk;catch errconsole;
Scan Picture
The ONprint API provides you 2 ways to request Pictures
-
With Image Id
tryconst picture = await sdk;catch errconsole; -
With Image File
tryconst imgBuffer = fs;const pictures = await sdk;catch errconsole;
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; sdk; catch err console;
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