1.0.1 • Published 8 years ago

sbtech-api-sdk v1.0.1

Weekly downloads
2
License
ISC
Repository
-
Last release
8 years ago

SBTech TypeScript / JavaScript SDK

Make API calls to SBTech API with our easy-to-use SDK.

Installation

To use as module in a Node.js / TypeScript project

We always recommend you bundle your dependencies with your application. You can do this using such tools as Webpack, Browserify and etc.

  1. Install it using npm:
npm install --save sbtech-api-sdk
  1. Require/import it into the project:
import { SBTechAPI } from 'sbtech-api-sdk'
var SBTechAPI = require('sbtech-api-sdk').SBTechAPI;

To self host for use in the browser

  1. Copy index.js file from dist folder of the repo ApiSDK.
  2. Include it in the browser:
<script type="text/javascript" src="index.js"></script>
  1. Use the global object SBTechLib.SBTechAPI:
console.log(SBTechLib.SBTechAPI);

Usage

  1. Create global object SBTech with property CurrentConfiguration to setup configuration.
   var SBTech = {
      CurrentConfiguration : {
          loginApiRootUrl: 'http://ngapi.sbtech.com/login/api',
          captchaApiRootUrl: 'http://ngapi.sbtech.com/captcha/api'
      }
    };
  1. Initialize the SBTech API using your JWT token which contains SessionId and SiteId in payload.
var sbtechAPI = new SBTechAPI(token);
  1. Call one of the API methods
sbtechAPI.LoginAPI.signin({name: 'example_name', password: 'example_password'})
    .then(function(response){
        console.log(response);
    })
    .catch(function(error){
        console.log(error);
    });

API

Overview

Each API call returns a promise. Any response with a status of < 200 or >= 300 will reject the promise. All the rest statuses is considered a success and will resolve the promise.

Error object of rejected promise contains:

  • {Number} statusCode: HTTP status code
  • {String} message: Error message
  • {Object} errorObject: Error object with detailed information

Methods

Login

SignIn
LoginAPI.signin(request: AuthenticationRequest):Promise<AuthenticationResponse>;
SignIn by token
LoginAPI.signInByToken(request: AuthenticationByTokenRequest):Promise<AuthenticationResponse>;
SignOut
LoginAPI.signout():Promise<AuthenticationResponse>;

Captcha

Get captcha image - returns image in base64
CaptchaAPI.getCaptchaImage():Promise<CaptchaResponse>;