checkitonus/statuspage-sdk

Atlassian 状态页 API 的 PHP 实现

0.1.3 2018-10-08 20:34 UTC

This package is auto-updated.

Last update: 2024-09-27 22:14:41 UTC


README

CheckItOn.Us Logo

Build Status

易于使用的状态页 API 实现。

安装

$ composer require checkitonus/statuspage-sdk
{
    "require": {
        "checkitonus/statuspage-api": "master"
    }
}

然后,在你的 PHP 文件中,你只需要 require 自动加载器

require_once 'vendor/autoload.php';

use CheckItOnUs\StatusPage\Server;

$server = new Server([
    'api_key' => 'API-KEY',
    'base_url' => 'https://api.statuspage.io/v1/pages'
]);

// Should return your first component
echo $server->components()->first()->toApi();

API 组件

安装完成后,你将能够访问几个对象,这些对象都可以调用 API 并按需检索数据。

请注意:尽管所有这些示例都使用了 Component 类,但以下对象也可以使用

  • CheckItOnUs\StatusPage\Component
  • CheckItOnUs\StatusPage\Incident
require_once 'vendor/autoload.php';

use CheckItOnUs\StatusPage\Server;
use CheckItOnUs\StatusPage\Component;

$server = new Server([
    'api_key' => 'API-KEY',
]);

// Find a component based on the name
$component = Component::on($server)->findByName('API');

// Find a component based on the ID
$component = Component::on($server)->findById(1);

// Find all components
Component::on($server)->all();

CRUD 操作

创建

require_once 'vendor/autoload.php';

use CheckItOnUs\StatusPage\Server;
use CheckItOnUs\StatusPage\Component;

$server = new Server([
    'api_key' => 'API-KEY',
]);

// Fluent API
$component = (new Component($server))
                ->setName('Name Here')
                ->setStatus(Component::OPERATIONAL)
                ->create();

更新

require_once 'vendor/autoload.php';

use CheckItOnUs\StatusPage\Server;
use CheckItOnUs\StatusPage\Component;

$server = new Server([
    'api_key' => 'API-KEY',
]);

// Fluent API
Component::on($server)
    ->findById(1)
    ->setName('Name Here')
    ->setStatus(Component::OPERATIONAL)
    ->update();

删除

require_once 'vendor/autoload.php';

use CheckItOnUs\StatusPage\Server;
use CheckItOnUs\StatusPage\Component;

$server = new Server([
    'api_key' => 'API-KEY',
]);

// Fluent API
Component::on($server)
    ->findById(1)
    ->delete();