Discord notifications for PIREP and News events #433 (#1215)

* 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:
Nabeel S
2021-06-04 10:51:59 -04:00
committed by GitHub
parent 17447c6903
commit 9b2e466b7e
46 changed files with 1249 additions and 456 deletions

View File

@@ -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
*