bearer/bearer-php

此包已被废弃,不再维护。作者建议使用 bearer/php-agent 包。
此包最新版本(v2.1)没有提供许可证信息。

Bearer PHP 客户端帮助您在几分钟内调用任何 API,并提供开箱即用的管理认证和日志监控。

v2.1 2019-12-09 09:40 UTC

This package is auto-updated.

Last update: 2020-07-29 09:57:05 UTC


README

这是与 Bearer.sh 交互的官方 PHP 客户端。

安装

通过运行以下命令安装包:

composer require bearer/bearer-php

使用方法

仪表板 获取您的 Bearer 密钥 和集成 ID,并按照以下方式使用 Bearer 客户端:

调用任何 API

$bearer = new Bearer\Client('BEARER_SECRET_KEY'); // find it on https://app.bearer.sh/keys

$api = $bearer->integration('api_name');
$api->get('/api-endpoint');

更高级的示例

注意:要运行以下示例,您需要首先激活 GitHub API。要激活它,请登录到 仪表板,然后点击“添加 API”并选择“GitHub API”。

传递查询参数

$bearer = new Bearer\Client('BEARER_SECRET_KEY'); // find it on https://app.bearer.sh/keys

$github = $bearer->integration('github');
$github->get('/users/bearer/repos', [ "query" => [ "direction" => "desc" ] ]);

用户认证

$bearer = new Bearer\Client('BEARER_SECRET_KEY'); // find it on https://app.bearer.sh/keys

$github = $bearer->integration('github');
$github
    ->auth("AUTH_ID") // Generate a user identity from the Dashboard
    ->put('/user/starred/bearer/bearer', [ "headers" => [ "Content-Length" => 0 ] ]);

可用方法

以下方法开箱即用: GETPOSTPUTDELETEOPTIONS。如果您想动态执行请求,请使用 request($method) 函数。

$bearer = new Bearer\Client('BEARER_SECRET_KEY'); // find it on https://app.bearer.sh/keys

$github = $bearer->integration('github');
$github
    ->auth("AUTH_ID") // Generate a user identity from the Dashboard
    ->request('PUT', '/user/starred/bearer/bearer', [ "headers" => [ "Content-Length" => 0 ] ]);

设置请求超时

您可以通过指定 httpClientSettings 作为 Bearer\Client 或 $bearer-integration 参数来自定义您的 http 客户端。默认情况下,Bearer 客户端的请求和连接超时设置为 5 秒。Bearer 允许将请求超时增加到最多 30 秒。

$bearer = new Bearer\Client('BEARER_SECRET_KEY', [CURLOPT_TIMEOUT => 10]); // sets timeout to 10 seconds

$github = $bearer->integration('github', [CURLOPT_CONNECTTIMEOUT => 1]); // sets connect timeout to 1 second
$github->get('/repos', [ "query" => [ "direction" => "desc" ] ]);

了解更多有关如何在 Bearer.sh 中使用自定义函数的信息。

开发

安装 composer

$ composer install
# run tests
$ vendor/bin/phpunit tests