2017 © Pedro Peláez
 

library deadmanssnitch-sdk

Deadmanssnitch API SDK

image

zumba/deadmanssnitch-sdk

Deadmanssnitch API SDK

  • Friday, January 6, 2017
  • by jrbasso
  • Repository
  • 3 Watchers
  • 4 Stars
  • 1,988 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 7 % Grown

The README.md

Deadmansnitch API PHP SDK

This library allows for easy access to Deadmanssnitch's API., (*1)

You can use it to manage snitches through the API or to notify a snitch when a process completes., (*2)

Example Notifier use

<?php

use Zumba\Deadmanssnitch\Notifier;

$notifier = new Notifier();
$notifier->pingSnitch('snitch id', 'just checking in.');

Example API Use

<?php

use Zumba\Deadmanssnitch\Client;
use Zumba\Deadmanssnitch\Snitch;
use Zumba\Deadmanssnitch\Interval;
use Zumba\Deadmanssnitch\ResponseError;

$client = new Client('your api key here');

// creating a snitch
$snitch = new Snitch('My cool process', new Interval(Interval::I_DAILY), [
    'tags' => ['production', 'critical']
]);
try {
    $client->createSnitch($snitch);
} catch (ResponseError $e) {
    // Failed to create the snitch
    echo $e->getMessage();
}

echo $snitch;
// 12312412

Installation

composer require zumba/deadmanssnitch-sdk

Supported APIs

Supports pinging the nosnch.in domain for a specific snitch. See Notifier::pingSnitch(string $token, string $message = ''): void., (*3)

The SDK currently supports v1 of DMS's API., (*4)

  • Creating a snitch - Client::createSnitch(Snitch $snitch): void
  • Listing snitches - Client::listSnitches(array $tags = []): []Snitch
    • Includes ability to filter by tags
  • Examining snitches - Client::examineSnitch(string $token): Snitch
  • Editing a snitch - Client::editSnitch(Snitch $snitch): void
    • Also supports appending tags and removing a single tag (per the API).
    • Setting tags on a snitch and using edit will replace the tags with what is provided.
  • Pausing a snitch - Client::pauseSnitch(string $token): void
  • Deleting a snitch - Client::removeSnitch(string $token): void

Note, we will not support attaining an API key with username/password., (*5)

Advanced usage

You can provide your own http client and logger to use provided they satisfy the GuzzleHttp\ClientInterface and Psr\Log\LoggerInterface respectively:, (*6)

<?php

use Zumba\Deadmanssnitch\Client;
use GuzzleHttp\Client as GuzzleClient;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$http = new GuzzleClient([
    'base_uri' => Client::HOST,
    'auth' => ['my api key', '']
]);

$logger = new Logger('name');
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));

$client = new Client('my api key', $http, $logger);

However, please note that guzzle clients are immutable, so you will be responsible for setting the base URI and auth parameters. Internally, http_errors is disabled in order to wrap and use our own exceptions. If you do not disable this, you will need to catch Guzzle exceptions instead of Zumba\Deadmanssnitch\ResponseError., (*7)

The Versions