checkitonus / cachet-api
Cachet API 的 PHP 实现
1.0.12
2020-07-07 12:47 UTC
Requires
- php: >=5.6.0
- cocur/slugify: ^2.5
- composer/semver: ^1.4
- guzzlehttp/guzzle: ^6.3
- nesbot/carbon: ^1
- tightenco/collect: ^5.4
Requires (Dev)
- psy/psysh: *
README
易于使用的 Cachet API 实现。
安装
$ composer require checkitonus/cachet-api
{
"require": {
"checkitonus/cachet-api": "~1"
}
}
然后,在您的 PHP 文件中,您只需 require 自定义加载器即可
require_once 'vendor/autoload.php'; use CheckItOnUs\Cachet\Server; $server = new Server([ 'api_key' => 'API-KEY', 'base_url' => 'https://demo.cachethq.io', // The base URL for the Cachet installation ]); // Should return pong echo $server->ping();
API 组件
安装完成后,您将能够访问多个对象,这些对象都会调用 API 并根据需要检索数据。
请注意:尽管所有这些示例都使用了 Component
类,但它们适用于以下对象
- CheckItOnUs\Cachet\Component
- CheckItOnUs\Cachet\ComponentGroup
- CheckItOnUs\Cachet\Incident
- CheckItOnUs\Cachet\IncidentUpdate (开发中 - Cachet 2.4 功能)
require_once 'vendor/autoload.php'; use CheckItOnUs\Cachet\Server; use CheckItOnUs\Cachet\Component; $server = new Server([ 'api_key' => 'API-KEY', 'base_url' => 'https://demo.cachethq.io', // The base URL for the Cachet installation ]); // 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\Cachet\Server; use CheckItOnUs\Cachet\Component; $server = new Server([ 'api_key' => 'API-KEY', 'base_url' => 'https://demo.cachethq.io', // The base URL for the Cachet installation ]); // Fluent API $component = (new Component($server)) ->setName('Name Here') ->setStatus(Component::OPERATIONAL) ->create();
更新
require_once 'vendor/autoload.php'; use CheckItOnUs\Cachet\Server; use CheckItOnUs\Cachet\Component; $server = new Server([ 'api_key' => 'API-KEY', 'base_url' => 'https://demo.cachethq.io', // The base URL for the Cachet installation ]); // Fluent API Component::on($server) ->findById(1) ->setName('Name Here') ->setStatus(Component::OPERATIONAL) ->update();
删除
require_once 'vendor/autoload.php'; use CheckItOnUs\Cachet\Server; use CheckItOnUs\Cachet\Component; $server = new Server([ 'api_key' => 'API-KEY', 'base_url' => 'https://demo.cachethq.io', // The base URL for the Cachet installation ]); // Fluent API Component::on($server) ->findById(1) ->delete();