setcronjob
v1.0.1
Published
SetCronJob API client library for node.js
Downloads
63
Maintainers
Readme
SetCronJob Client Library for Node.js
This module provides calls to the SetCronJob API for Nodejs. Setcronjob module provides you feature to set online schedulers for your application. This schedulers can call any api or task on on your server corresponding to different time settings. You can retriever your daily log with respective execution results and can enable and disable schedulers easily.
For more information on the API request and responses visit the SetCronJob API docs
Example
var setCronJob = require('setcronjob');
var cronJob = new setCronJob('xxxxxxxx');
//list cron for a token
cronJob.cron.list(function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
Installation
npm install setcronjob //install locally
npm install -g setcronjob //install globally
npm install setcronjob --save //install locally and save to package json
Quick Start
You will need valid Setcronjob Token to work with this module, You can obtain token after signing up (https://www.setcronjob.com/)
Cron Job:
var setCronJob = require('setcronjob');
var cronJob = new setCronJob('xxxxxxxx');
//list cron for a token
cronJob.cron.list(function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//get one cron job information
var params = {
id: 'xxxxxx'
};
cronJob.cron.get(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//Add cron job
var params = {
month: 3,
day: 25,
hour: 18,
minute: 0,
url: 'https://test.com:9000/api/v1//execute',
timezone: 'Asia/Kolkata',
postData: '{"postId":"xyz"}',
httpMethod: 'POST'
};
cronJob.cron.add(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//Edit cron
var params = {
id: 'xyz',
month: 4,
day: 26,
hour: 19,
minute: 20,
url: 'https://daytest.com:9000/api/v1//execute',
timezone: 'Asia/Kolkata',
postData: '{"postId":"xyz"}',
httpMethod: 'POST'
};
cronJob.cron.edit(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//Enable cron
var params = {
id: 'xyz'
};
cronJob.cron.enable(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//Disable cron
var params = {
id: 'xyz'
};
cronJob.cron.disable(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//delete cron
var params = {
id: 'xyz'
};
cronJob.cron.delete(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//run cron
var params = {
id: 'xyz'
};
cronJob.cron.run(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
})
//get logs
var params = {
id: 'xyz'
};
cronJob.cron.logs(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
Account job:
var setCronJob = require('setcronjob');
var cronJob = new setCronJob('xxxxxxxx');
//Edit account
var params = {
timezone: 'Asia/kolkatta'
};
cronJob.account.edit(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
Group Job:
var setCronJob = require('setcronjob');
var cronJob = new setCronJob('xxxxxxxx');
//list group
cronJob.group.list(function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//Get group
var params = {
id: 'xyz'
};
cronJob.group.get(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//Add group
var params = {
name: 'test-group'
};
cronJob.group.add(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//Edit group
var params = {
id: 'xyz',
name: 'test-edit'
};
cronJob.group.edit(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//Delete group
var params = {
id: 'xyz'
};
cronJob.group.delete(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//Vanish group
var params = {
id: 'xyz'
};
cronJob.group.vanish(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//Emp†y group
var params = {
id: 'xyz'
};
cronJob.group.empty(params, function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
Server Job:
var setCronJob = require('setcronjob');
var cronJob = new setCronJob('xxxxxxxx');
//Get server time
cronJob.server.get(function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//get supported time zones
cronJob.server.timezones(function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//get user agents
cronJob.server.userAgent(function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
//get server ip
cronJob.server.ip(function (err, result) {
if (err) {
console.log("Error : ", err)
} else {
console.log("Result : ", result)
}
});
Tests
To run tests type npm test. To run tests with coverage type npm coverage.
Examples
Contributors
Originally authored by @princesoni1989
LICENSE
setcronjob is released under the ISC License Copyright (c) 2016 Prince Soni
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.