/snitcher

Simple API client for deadmanssnitch.com

Primary LanguageRubyMIT LicenseMIT

Snitcher

Simple API client for Dead Man's Snitch

Gem Version Build Status Code Climate Coverage Status

Snitches get Stitches

Usage

To check in for one of your snitches:

Snitcher.snitch("c2354d53d2")

You also may provide a message with the check in:

Snitcher.snitch("c2354d53d2", message: "Finished in 23.8 seconds.")

Errors can be reported by providing the status option. A status of nil, 0, or "" are all considered a success. Any other status is treated as a failure.

Snitcher.snitch("c2354d53d2", status: 1)

The default timeout of 5 seconds can be overridden:

Snitcher.snitch("c2354d53d2", timeout: 10)

API Access

Setup

Initialize the API client directly with your api key:

require "snitcher/api"

client = Snitcher::API::Client.new("my_awesome_key")

Heroku

Dead Man's Snitch exposes the DEADMANSSNITCH_API_KEY environment variable for accessing the API.

require "snitcher/api"

client = Snitcher::API::Client.new(ENV["DEADMANSSNITCH_API_KEY"])

Listing Snitches

client.snitches

Returns an array of Snitches.

Retrieve a Single Snitch

token = "c2354d53d2"
client.snitch(token)

Returns a Snitch.

Retrieve Snitches That Match a Set of Tags

client.snitches(tags: ["critical", "sales"])

Returns an array of Snitches.

Create a Snitch

Both :name and :interval are required. Optional attributes include :notes, and :tags. For a full list see the API documentation.

attributes = {
  name: "Nightly User Data Backups",
  interval: "daily",
  notes: "User login and usage data",
  tags: ["users", "critical"],
}
client.create_snitch(attributes)

Returns the newly-created Snitch.

Updating a Snitch

You only need to pass the update_snitch function the attributes you want to change. The rest of a Snitch's attributes will remain the same.

token = "c2354d53d2"
attrs = { "name": "Important Nightly User Data Backups" }
client.update_snitch(token, attrs)

Returns the edited Snitch.

Adding Tags to a Snitch

This function adds tags to a Snitch, retaining whatever tags it already has.

token = "c2354d53d2"
tags  = ["spring_campaign", "support"]
client.add_tags(token, tags)

Returns an array of all of the Snitch's tags.

Deleting a Tag From a Snitch

This function is for deleting a single tag from a Snitch.

token = "c2354d53d2"
tag = "support"
client.remove_tag(token, tag)

Returns an array of all of the Snitch's remaining tags.

Setting the Tags on a Snitch

token = "c2354d53d2"
client.update_snitch(token, tags: [ "production", "critical" ])

Removing all Tags from a Snitch

token = "c2354d53d2"
client.update_snitch(token, tags: [])

Pause a Snitch

token = "c2354d53d2"
client.pause_snitch(token)

Returns a nil object.

Delete a Snitch

token = "c2354d53d2"
client.delete_snitch(token)

Returns a nil object.

Contributing

Snitcher is open source and contributions from the community are encouraged! No contribution is too small. Please consider:

  • adding features
  • squashing bugs
  • updating documentation
  • fixing typos

For the best chance of having your changes merged, please:

  1. fork the project
  2. push your changes, with tests
  3. submit a pull request with at least one animated GIF

Thanks

A big thank you to Randy Schmidt for dreaming up Dead Man's Snitch in the first place and for entrusting its future to Collective Idea.

Copyright

See LICENSE.txt for details.