* Discord notifications for events #433 * Style fixes * Check for blank webhook urls and disable * Cleanup items after review * Changes and fixes * Style fixes * Don't load env for testing * Fix status text * Refactor saving fields/fares so events get the latest data * Cleanup * Style fixes
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Support;
|
||||
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
|
||||
/**
|
||||
* Helper for HTTP stuff
|
||||
@@ -11,9 +12,8 @@ class HttpClient
|
||||
{
|
||||
private $httpClient;
|
||||
|
||||
public function __construct(
|
||||
GuzzleClient $httpClient
|
||||
) {
|
||||
public function __construct(GuzzleClient $httpClient)
|
||||
{
|
||||
$this->httpClient = $httpClient;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,29 @@ class HttpClient
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uri
|
||||
* @param $body
|
||||
* @param array $opts
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function post($uri, $body, array $opts = [])
|
||||
{
|
||||
$opts = array_merge([
|
||||
'connect_timeout' => 2,
|
||||
RequestOptions::JSON => $body,
|
||||
], $opts);
|
||||
|
||||
$response = $this->httpClient->post($uri, $opts);
|
||||
$content_type = $response->getHeaderLine('content-type');
|
||||
if (strpos($content_type, 'application/json') !== false) {
|
||||
$body = \GuzzleHttp\json_decode($body, true);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a file to a given path
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user