bearer/bearer-php

This package is abandoned and no longer maintained. The author suggests using the bearer/php-agent package instead.
There is no license information available for the latest version (v2.1) of this package.

The Bearer PHP client helps you call any API in minutes with out-of-the-box managed authentication and log monitoring.

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

This package is auto-updated.

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


README

This is the official PHP client for interacting with Bearer.sh.

Installation

Install the package by running:

composer require bearer/bearer-php

Usage

Get your Bearer Secret Key and integration id from the Dashboard and use the Bearer client as follows:

Calling any APIs

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

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

More advanced examples

Note: to run the following examples, you'll need to activate the GitHub API first. To activate it, log in to the Dashboard then click on "Add an api" and select "GitHub API".

Passing query parameters

$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" ] ]);

Authenticating users

$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 ] ]);

Available methods

The following methods are available out-of-the-box: GET, POST, PUT, DELETE, OPTIONS. If you want to dynamically perform requests, use the request($method) function:

$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 ] ]);

Setting the request timeout

You can customize your http client by specifying httpClientSettings as a Bearer\Client or $bearer-integration parameter. By default Bearer client request and connection timeouts are set to 5 seconds. Bearer allows to increase the request timeout to up to 30 seconds

$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" ] ]);

Learn more on how to use custom functions with Bearer.sh.

Development

Install composer

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