crastos/updown-sdk

I got bored so I wrote an SDK for updown.io.

v0.1.0 2022-12-27 13:54 UTC

This package is auto-updated.

Last update: 2023-09-23 05:52:18 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

I got bored so I wrote an SDK for updown.io.

It's functional but still a work-in-progress.

use function \Crastos\Updown\updown;

updown($api_key)->checks->all()->toJson();
# => [{"token":"a1b2","url":"https://example.com", ... }]

Installation

You can install the package via composer:

composer require crastos/updown-sdk

This package requires an HTTP client as well. You can view supported clients via composer:

composer suggest crastos/updown-sdk

Usage

The fastest way to get up and running is with the helper function.

use function \Crastos\Updown\updown;

updown($api_key)->checks->all()->toJson();
# => [{"token":"a1b2","url":"https://example.com", ... }]

Under the hood, this will instantiate an HTTP client and the SDK class which will navigate the API path and return the appropriate endpoint as needed. You can do this manually as well if you prefer to have more control over what's going on.

$client = new \Crastos\Updown\Http\Client($api_key);
$updown = new \Crastos\Updown\Updown($client);

/** @var \Crastos\Updown\Http\Endpoints\Checks */
$endpoint = $updown->checks;

/** @var \Crastos\Updown\Http\Resources\ResourceRepository<int, \Crastos\Updown\Http\Resources\Check> */
$repository = $endpoint->all();

/** @var \Crastos\Updown\Http\Resources\Check */
$resource = $repository->first();

$resource->toJson();
# => {"token":"a1b2","url":"https://example.com", ... }

Laravel

Add updown.io secret to .env

# /.env
UPDOWN_SERVER_SECRET=asdf1234

Add updown.io secret to config/services.php

# config/services.php
[
    // ...
    'updown' => [
        'secret' => env('UPDOWN_SERVER_SECRET'),
    ],
]

Now you can access the SDK via app('updown').

app('updown')->checks->all()->json()
# => [{"token":"a1b2","url":"https://example.com", ... }]