Bearer client for the PHP programming language

Overview

Bearer PHP Client

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
You might also like...
A simple functional programming library for PHP
A simple functional programming library for PHP

bingo-functional A simple functional programming library for PHP. Requirement(s) PHP 7 or higher Rationale PHP, a language not commonly associated wit

Small library providing some functional programming tools for PHP, based on Rambda

Functional library for PHP. Features: set of useful functions helpful in functional programming all functions are automatically curried every array ca

Learning design patterns by implementing them in various programming languages.

design-patterns Learning design patterns by implementing them in various programming languages. Creational design patterns Creational design patterns

A Finite State Machine System based on Chapter 3.1 of Game Programming Gems 1 by Eric Dybsand

A Finite State Machine System based on Chapter 3.1 of Game Programming Gems 1 by Eric Dybsand,Written by Roberto Cezar Bianchini, July 2010 ported to php by MrFerrys.

Utilities for concurrent programming of PocketMine-MP plugins.
Utilities for concurrent programming of PocketMine-MP plugins.

Utilities for concurrent programming of PocketMine-MP plugins Overview Plugin that implements the pthreads channels and in the future, promises (which

A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.
A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP
Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP

Hprose 3.0 for PHP Introduction Hprose is a High Performance Remote Object Service Engine. It is a modern, lightweight, cross-language, cross-platform

PHP Expression Language

PHP Expression Language The purpose of this library is to provide a common base for an PHP Expression Language. This is not really a creative library

Simple customizable captcha script for bot prevention in php language.

phpCaptcha Simple customizable captcha script for bot prevention in php language. Usage ?php session_start(); $status = ""; if ($_SESSION['captcha']

Comments
  • Logging support

    Logging support

    Allows to log using the following format:

    [2019-10-17T07:34:32.684377+00:00] bearer.DEBUG: sending requesturl: https://proxy.staging.bearer.sh/postman_echo//get?foo=bar,method:GET,params:?foo=bar,body: ,headers: ["Authorization: sk_production_Xs3hErAxOajxayx7PD7eT9WamrHRtW6p"],http_client_settings: {"13":5,"78":5} [] []
    
    [2019-10-17T07:34:33.529970+00:00] bearer.INFO: request id: 1-5da81989-55ff1730fdb9cd207b912250 [] []
    
    opened by RadekMolenda 0
  • Use proxy URL

    Use proxy URL

    Breaking change

    • update client to use proxy url
    • remove custom function invocation support
    • remove setApiKey and favor setSecretKey instead
    • setup CI/CD
    opened by RadekMolenda 0
  • fix: safe array keys check

    fix: safe array keys check

    What

    Strict check that a key exists within an array (use array_key_exists instead of `is_null).

    Why

    Otherwise, some framework (e.g. Symfony) will throw an error if the key does not exist.

    opened by Frenchcooc 0
Releases(v2.0.1)
Owner
Bearer
Automate data security risk assessment for cloud-native applications.
Bearer
A repository for showcasing my knowledge of the PHP programming language, and continuing to learn the language.

Learning PHP (programming language) I know very little about PHP. This document will list all my knowledge of the PHP programming language. Basic synt

Sean P. Myrick V19.1.7.2 2 Oct 29, 2022
🦭 Kirby, but headless only – KQL with bearer token, Express-esque middlewares & more

Kirby Headless Starter ℹ️ Send a Bearer test authorization header with a request to the live playground to test this headless starter. This starter ki

Johann Schopplich 36 Dec 28, 2022
This is a plugin written in PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform

This is a plugin written in PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform. It allows you to hear the sound

Thành Nhân 10 Sep 27, 2022
This example shows how to use Anychart library with the PHP programming language, Laravel framework and MySQL database.

PHP basic template This example shows how to use Anychart library with the PHP programming language, Laravel framework and MySQL database. Running To

AnyChart Integrations and Templates 23 Jul 17, 2022
All about docker projects either from dockerfile or compose. Anyway, here the project is in the form of a service, for the programming language I will make it later

Docker Project by ItsArul Hey, yo guys okay, this time I made some projects from Docker. Anyway, this project is open source, for example, if you want

Kiyo 10 Nov 4, 2022
PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP language

php-text-analysis PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP l

null 464 Dec 28, 2022
Simple game server with php without socket programming. Uses the Api request post(json).

QMA server Simple game server with php without socket programming. Uses the Api request post(json). What does this code do? Register the user as a gue

reza malekpour 3 Sep 4, 2021