npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

deadmanssnitch-client

v1.0.1

Published

A library for interacting with the Dead Man's Snitch API

Downloads

295

Readme

Dead Man's Snitch Client GitHub package.json version Build Status Coverage Status codecov

The deadmanssnitch-client Node.js library contains a simple and convenient HTTP client for making requests to Dead Man's Snitch check-ins and the Dead Man's Snitch REST API.

Table of contents

Installation

Using NPM:

$ npm install deadmanssnitch-client

Using Yarn:

$ yarn add deadmanssnitch-client

Usage

Initializing a client

The library exports a DeadMansSnitchClient class for interacting with Dead Man's Snitch check-ins and the Dead Man's Snitch REST API. You'll need an API key provided by Dead Man's Snitch in order to interact with the Dead Man's Snitch REST API. An API key is required for REST API calls, but it is not necessary for snitch check-ins. You can provide the API key as an apiKey option or set the API key as an environment variable using DMS_API_KEY. By default, the client will use the DMS_API_KEY environment variable if the apiKey option is not provided.

Example import methods:

const DeadMansSnitchClient = require('deadmanssnitch-client');

// Creating an API client.
const client = new DeadMansSnitchClient({
  apiKey: 'DEAD-MANS-SNITCH-API-KEY'
});
import DeadMansSnitchClient from 'deadmanssnitch-client';

// Creating an API client.
const client = new DeadMansSnitchClient({
  apiKey: 'DEAD-MANS-SNITCH-API-KEY'
});

Using environment variables in an application:

const DeadMansSnitchClient = require('deadmanssnitch-client');

// Set the API key as an environment variable.
process.env.DMS_API_KEY = 'DEAD-MANS-SNITCH-API-KEY';

const client = new DeadMansSnitchClient();

Setting environment variables before running an application:

Linux:

$ DMS_API_KEY=DEAD-MANS-SNITCH-API-KEY node app.js

Windows:

> cmd /C "set DMS_API_KEY=DEAD-MANS-SNITCH-API-KEY && node app.js"

Options

These are the available options for creating a DeadMansSnitchClient instance.

| Name | Default | Description | | ------------------- | --------------------------------- | ----------------------------------------------------------- | | apiKey | undefined | Dead Man's Snitch API Key | | timeout | 5000 | Number of milliseconds before the request times out | | apiBaseUrl | https://api.deadmanssnitch.com | Base URL for the Dead Man's Snitch REST API | | checkInBaseUrl | https://nosnch.in | Base URL for the Dead Man's Snitch check-ins | | fullResponse | false | Get the full response instead of just the body | | maxContentLength | 10000 | The max size of the HTTP response content in bytes | | maxBodyLength | 2000 | The max allowed size of the HTTP request body in bytes | | apiVersion | 1 | The REST API Version to use |

Examples

The checkIn and REST API methods return a Promise which resolves with the response data or rejects with an error.

Alternatively, the checkIn method and each of the REST API methods can also be provided a completion callback function as its last argument. When a callback function is used the corresponding method does not return a value. The arguments passed to the completion callback function are err and resp. The first argument (err) is always reserved for an exception/error and the second argument (resp) is always reserved for the data returned from the check-in or API call. If the corresponding method is completed successfully, then the first argument will be undefined. If the method fails, then the second argument will be undefined.

Create an instance:

const DeadMansSnitchClient = require('deadmanssnitch-client');

// Creating an API client.
const client = new DeadMansSnitchClient({
  apiKey: 'DEAD-MANS-SNITCH-API-KEY'
});

Check-in with a snitch:

async function performTask(token) {
  /*
   * Add task logic here.
   */

  // Check-in after a task completes.
  await client.checkIn(token);
}

Check-in with a snitch and add a message:

async function performTask(token) {
  /*
   * Add task logic here.
   */

  // Check-in after a task completes.
  await client.checkIn(token, `All's good man!`);
}

Get a list of snitches:

async function getAllSnitches() {
  try {
    return await client.getSnitches();
  } catch(err) {
    console.error(err);
  }
}

Get a certain snitch:

async function getSnitchInfo(token) {
  try {
    return await client.getSnitch(token);
  } catch(err) {
    console.error(err);
  }
}

Create a new snitch:

async function createNewSnitch() {
  try {
    return await client.createSnitch({
      name: 'Web App',
      interval: 'daily'
    });
  } catch(err) {
    console.error(err);
  }
}

Update a snitch using a callback function:

async function updateMySnitch(token, snitchInfo) {
  await client.updateSnitch(token, snitchInfo, (err, resp) => {
    if (err) {
      console.error(err);
    } else {
      console.log(resp);
    }
  });
}

Documentation

Change Log

The CHANGELOG contains descriptions of notable changes.

License

This software is licensed under the Apache 2 license.