mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Always execute migration 9999 (can be used to fix things manually) Optimized meal plan navigation / date range filtering Prepared next release Pulled translations from Transifex Various code optimizations
49 lines
852 B
PHP
49 lines
852 B
PHP
<?php
|
|
|
|
namespace Grocy\Helpers;
|
|
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\ExceptionRequestException;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
class WebhookRunner
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->client = new Client(['timeout' => 2.0]);
|
|
}
|
|
|
|
private $client;
|
|
|
|
public function run($url, $args, $json = false)
|
|
{
|
|
$reqArgs = [];
|
|
if ($json)
|
|
{
|
|
$reqArgs = ['json' => $args];
|
|
}
|
|
else
|
|
{
|
|
$reqArgs = ['form_params' => $args];
|
|
}
|
|
try
|
|
{
|
|
file_put_contents('php://stderr', 'Running Webhook: ' . $url . "\n" . print_r($reqArgs, true));
|
|
|
|
$this->client->request('POST', $url, $reqArgs);
|
|
}
|
|
catch (RequestException $e)
|
|
{
|
|
file_put_contents('php://stderr', 'Webhook failed: ' . $url . "\n" . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function runAll($urls, $args)
|
|
{
|
|
foreach ($urls as $url)
|
|
{
|
|
$this->run($url, $args);
|
|
}
|
|
}
|
|
}
|