1.0.13 • Published 7 years ago

quander-node-sdk v1.0.13

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago

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

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago