tq1-public-sdk
v1.2.1
Published
Node.js SDK used to access TQ1 Public API described at http://docs.tq1publicapi.apiary.io
Downloads
5
Readme
TQ1 Node.js Public API SDK
Install
- Add
tq1-public-sdk
dependency to yourpackage.json
Usage
Setup
Provided with the Application Key
and an API Access Token
, create a client as following
var tq1 = require('tq1-public-sdk');
var client = tq1('my application key', 'my application token');
Calling the API
API call examples:
// Fetching metadata
client.fetchMetadata(function(err, data) {
// data will be an object like the one described at http://docs.tq1publicapi.apiary.io/#reference/authentication/fetch-metadata/get
});
// Sending Exclusive push notification to client with id 123456
var notification = {
'status': 0,
'parameters': {
'custom': {
'Client Code': ['123456']
}
},
'content': {
'title': 'Message title (for admin and reports purposes only)',
'message': 'push notification message (will be shown on user device)',
'scheduled_at': 1420741200,
},
'audienceText': ['Message for user with code 123456'],
"max_audience": 1
};
client.schedulePushExclusiveNotification(notification, function(err, data) {
// data will be an object like the one described at http://docs.tq1publicapi.apiary.io/#reference/authentication/new-exclusive-push-notification/post
});
Error handling
All calls that result in an error of some sort (validation or HTTP failure), will have an error object containing the following properties:
name
: It is a string constant with value equal to"TQError"
, which can also be checked/compared with the.constants.errorName
property of the clientmessage
: Contains an error message string informing the error reason.
client.schedulePushExclusiveNotification(null, function(err, data) {
// err.name == client.constants.errorName
// > true
});
Test
$ npm install
$ npm test