noplanman / service-webhook-handler
Library to handle Webhooks from various services.
1.0.0
2022-05-27 22:46 UTC
Requires
- php: ^8.0
- ext-curl: *
- ext-json: *
- ext-openssl: *
- cache/void-adapter: ^1.0
- psr/simple-cache: ^1.0|^2.0|^3.0
Requires (Dev)
- ext-memcached: *
- ext-redis: *
- cache/filesystem-adapter: ^1.0
- cache/memcached-adapter: ^1.0
- cache/redis-adapter: ^1.0
- matthiasmullie/scrapbook: ^1.4
- nyholm/psr7: ^1.1
- php-http/curl-client: ^2.0
- php-http/mock-client: ^1.3
- phpunit/phpunit: ^9.5
Suggests
- cache/filesystem-adapter: Cache to files
- cache/memcached-adapter: Cache to memcache
- cache/redis-adapter: Cache to redis
This package is auto-updated.
Last update: 2024-12-05 01:34:04 UTC
README
PHP library to handle Webhooks from various services.
Requirements
- PHP >= 8.0
- Any PSR-17 implementation
- Any PSR-18 implementation
Quick install via Composer
This command will get you up and running quickly with a Guzzle HTTP client.
composer require noplanman/service-webhook-handler:^1.0 guzzlehttp/guzzle:^7.4.3 guzzlehttp/psr7:^2.2
HTTP Client
You can explicitly set an HTTP client with:
use NPM\ServiceWebhookHandler\Utils;
// Example with Guzzle ($ composer require guzzlehttp/guzzle:^7.4.3 guzzlehttp/psr7:^2.2)
use GuzzleHttp\Client;
Utils::setClient(new Client());
use NPM\ServiceWebhookHandler\Utils;
// Example with HTTPlug with cURL ($ composer require php-http/curl-client:^2.0 nyholm/psr7:^1.1)
use Http\Client\Curl\Client;
Utils::setClient(new Client());
Caching
To enable caching, add any PSR-16 compatible adapter and set the cache provider:
use NPM\ServiceWebhookHandler\Utils;
// Example with redis ($ composer require cache/redis-adapter)
use Cache\Adapter\Redis\RedisCachePool;
$client = new Redis();
$client->connect('127.0.0.1', 6379);
Utils::setCache(new RedisCachePool($client));
use NPM\ServiceWebhookHandler\Utils;
// Example with memcached ($ composer require cache/memcached-adapter)
use Cache\Adapter\Memcached\MemcachedCachePool;
$client = new Memcached();
$client->addServer('localhost', 11211);
Utils::setCache(new MemcachedCachePool($client));
Usage
Very basic functionality provided so far for:
GitHub
use NPM\ServiceWebhookHandler\Handlers\GitHubHandler;
$handler = new GitHubHandler('webhook_secret');
if ($handler->validate()) {
// All good, use the received data!
$data = $handler->getData();
}
GitLab
use NPM\ServiceWebhookHandler\Handlers\GitLabHandler;
$handler = new GitLabHandler('webhook_secret');
if ($handler->validate()) {
// All good, use the received data!
$data = $handler->getData();
}
Travis CI
use NPM\ServiceWebhookHandler\Handlers\TravisCIHandler;
$handler = new TravisCIHandler();
if ($handler->validate()) {
// All good, use the received data!
$data = $handler->getData();
}
Telegram Login
Docs - TelegramLoginHandler.php
use NPM\ServiceWebhookHandler\Handlers\TelegramLoginHandler;
$handler = new TelegramLoginHandler('123:BOT_API_KEY');
if ($handler->validate()) {
// All good, use the received data!
$data = $handler->getData();
}