This project has been deprecated. Please use mg-api-js.
Unofficial nodejs client for the MyGeotab API
$ npm install mg-api-node --save
var api = new API(userName, password, database);
api.authenticate(function(err, data) {
if(err){
console.log('Error', err);
return;
}
api.call('Get', {
typeName: 'User',
search: {
name: data.userName
}
}, function(err, data) {
if(err){
console.log('Error', err);
return;
}
console.log('User', data);
});
});
If you need to handle potential slow HTTP requests, you can access request.setTimeout by passing an optional timeout (ms) and timeoutCallback to api.call()
and api.multicall()
:
var api = new API(userName, password, database, server, {ssl: false}, sessionId);
// Timeout (ms) and TimeoutCallback
api.call('Get', {
typeName: 'User',
resultsLimit: 1
}, function(err, data) {
if(err){
console.log('Error', err);
return;
}
console.log('User', data);
}, 10000, function(){
console.log('Timeout');
});
// Just Timeout
api.call('Get', {
typeName: 'User',
resultsLimit: 1
}, function(err, data) {
if(err){
console.log('Error', err);
return;
}
console.log('User', data);
}, 10000);
It's also possible to supply session ID and direct server to re-use a session ID. This avoids costly authentication.
var api = new API(userName, password, database, server, options, sessionId);
api.call('Get', {
typeName: 'User',
resultsLimit: 1
}, function(err, data) {
if(err){
console.log('Error', err);
return;
}
console.log('User', data);
});
$ npm install -g mocha
$ npm install
$ mocha