dead-mans-snitch
v0.0.2
Published
API client for Dead Man's Snitch (https://deadmanssnitch.com)
Downloads
5
Readme
Dead Man's Snitch
This package provides a node.js library for talking to Dead Man's Snitch.
All methods return a Promise, so you should be familiar with them before making use of this library.
Usage
Create an API client instance
var DeadMansSnitch = require('dead-mans-snitch');
var client = new DeadMansSnitch.APIClient('YOUR-SECRET-API-KEY');
Get all snitches on your account
client.getSnitches()
.then(function (arrayOfSnitches) {
// …
});
Get detail on a single snitch
fetchSnitchSomehow()
.then(function (snitch) {
return client.getSnitch(snitch);
}).then(function (snitchDetail) {
// …
});
OR
return client.getSnitch('abc123')
then(function (snitch) {
// …
});
Creating a new snitch
var snitch = new DeadMansSnitch.Snitch({
name: 'Test Snitch',
interval: '15_minute'
notes: 'Optional notes about this snitch',
tags: ['optional_tags', 'production', 'backups']
});
client.createSnitch(snitch)
.then(function (newSnitch) {
console.log('Created', newSnitch.token);
});
Editing a snitch
fetchSnitchSomehow()
.then(function (snitch) {
snitch.notes = 'This is now using the new version of Backup';
return client.editSnitch(snitch);
}).then(function (snitch) {
console.log('Edited', snitch.token);
});
Adding one or more tags to a snitch
fetchSnitchSomehow()
.then(function (snitch) {
return client.addTags(snitch, ['production', 'backup'])
}).then(function (tags) {
console.log('Snitch now has tags', tags);
});
OR
client.addTags('abc123', ['production', 'backup'])
.then(function (tags) {
console.log('Snitch now has tags', tags);
});
Removing a tag from a snitch
fetchSnitchSomehow()
.then(function (snitch) {
return client.removeTag(snitch, 'production')
}).then(function () {
console.log('Removed!');
});
OR
client.removeTag('abc123', 'production')
.then(function () {
console.log('Removed!');
});
Changing tags on a snitch
To replace all the tags on a snitch, use client.editSnitch()
:
fetchSnitchSomehow()
.then(function (snitch) {
snitch.tags = ['production', 'backup'];
return client.editSnitch(snitch);
}).then(function (snitch) {
console.log('Edited', snitch.token);
});
Pausing a snitch
fetchSnitchSomehow()
.then(function (snitch) {
return client.pauseSnitch(snitch);
}).then(function () {
console.log('Paused');
});
OR
client.pauseSnitch('abc123')
.then(function () {
console.log('Paused!');
});
Deleting a snitch
fetchSnitchSomehow()
.then(function (snitch) {
return client.deleteSnitch(snitch);
}).then(function () {
console.log('Deleted!');
});
OR
client.deleteSnitch('abc123')
.then(function () {
console.log('Deleted!');
});