Socket
Socket
Sign inDemoInstall

quander-node-sdk

Package Overview
Dependencies
60
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    quander-node-sdk

SDK for Quander REST APIs


Version published
Maintainers
3
Install size
6.94 MB
Created

Readme

Source

QUANDER NODE SDK

Installation

npm install quander-node-sdk

Usage

To write an app using the SDK

  • Register for a developer account and get your client_id and secret.
  • Add dependency 'quander-node-sdk' in your package.json file.
  • Require 'quander-node-sdk' in your file
var Quander = require('quander-node-sdk').Quander;
  • Create config options, with parameters (mode, client_id, secret).
var quander = new Quander({
  baseUrl: 'http://dev.quander.io/api',
  tokenUrl: 'http://dev.quander.io',
  clientId: '1a1t2u7b9540ggkk8s0gc4wcwcwwow40k4osw40cwo44swcoo0',
  clientSecret: '1a1t2u7b9540ggkk8s0gc4wcwcwwow40k4osw40cwo44swcoo0'
});
  • Login with username/password
quander.login(req.body.username, req.body.password).then((accessToken) => {
});
  • If you already have your access token
quander.setAccessToken(user);

How to use the resources

  • Accessing your resources
var accountManager = quander.createResource('accounts');
var projectManager = quander.createResource('projects', {account: account});
  • getList operation
accountManager.getList().then(function (accounts) {
  res.send(accounts instanceof ResourceCollection); // true
  res.send(accounts);
});

// Using Pagination
accountManager.getList({limit: 2, page: 1}).then(function (accounts) {
  res.send(accounts instanceof ResourceCollection); // true  
  res.send(accounts);
});

// Example of return for getList operation (ResourceCollection object):
//{
//  "data": [
//    {
//      "id": 115,
//      ...
//    },
//    {
//      "id": 34,
//      ...
//    }
//  ],
//  "page": 1,
//  "limit": 100,
//  "pages": 1,
//  "total": 2
//}

  • get operation ".get(uuid)"
accountManager.get('ccfb1d41-7c0b-4cb1-8836-606f0d8d5511').then(function (account) {
  res.send(account);
});
  • post operation ".post(payload, data)"
mediaManager.post({
  posterurl: 'https://www.google.com/logos/doodles/2015/new-years-eve-2015-5985438795825152-hp2x.gif',
  url: 'https://www.google.com/logos/doodles/2015/new-years-eve-2015-5985438795825152-hp2x.gif',
  type: 'image',
  referenceId: 'REFEREFEFEFEF',
  metadata: ''
}).then((media) =>{
  res.send(media);
});

// Post multipart/form-data with the payload and files
mediaManager.post({
  type: 'image',
  referenceId: 'REFEREFEFEFEF',
  metadata: ''
}, {
  media: fs.createReadStream('/..../test.gif'),
  poster: fs.createReadStream('/....p/test.gif')
}).then((media) =>{
  res.send(media);
});

Available Resources and Operations

  • Account => getList, get, post
  • Project(account) => getList
  • Experience(project) => getList
  • Media(project) => getList
  • Media(attendee) => getList
  • Media(experience) => post
  • Attendee(project) => post

Handling Error

There are 2 types of error, one coming from the sdk (QuanderSdkError), and the other one from the api responses (QuanderApiError).

accountManager.getList().then(function (accounts) {
  res.send(accounts);
}).catch((error) => {
  res.send(error instanceof Error);
  // return true
  
  res.send(error instanceof QuanderApiError);
  // return true
});
  • Example: Handling expired token
try {
  quander.setAccessToken(token);
} catch (e) {
  if (e instanceof QuanderSdkError && QuanderSdkError.TOKEN_EXPIRED === e.errorCode) {
    // Call the api to request the new access token
    return quander.getRefreshedToken(token).then((token) => {
      quander.setAccessToken(token);
    }).catch((e) => {
      // Refresh token also expired or not valid
      if (e instanceof QuanderApiError && QuanderApiError.REFRESH_TOKEN_INVALID === e.errorCode) {
        res.redirect('/login');
      }
    });
  }
}

Available Errors

  • QuanderSdkError
KeyDescription
BAD_RESOURCEResource not supported by the sdk
BAD_OPERATIONOperation not supported by the sdk
TOKEN_EXPIREDToken is expired, you should request a new one through the api
  • QuanderApiError
KeyDescription
INVALID_GRANTYou can't authenticate with that method
REFRESH_TOKEN_INVALIDYour refresh token is invalid, you have to authenticate again
BAD_REQUESTGeneral error. The server cannot or will not process the request.
FORBIDDENThe request was a valid request, but the server is refusing to respond to it.
NOT_FOUNDResource could not be found but may be available in the future.
CONFLICTIndicates that the request could not be processed because of conflict in the request.

Debugging

  • Enable debug
Quander.enableDebug();

Keywords

FAQs

Last updated on 02 Nov 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc