Skip to content

Commit

Permalink
Merge pull request #311 from wri/release/jovial-jacaranda
Browse files Browse the repository at this point in the history
[RELEASE] Jovial Jacaranda
  • Loading branch information
roguenet authored Jul 9, 2024
2 parents bfbaa98 + ab9e3d2 commit df1dc23
Show file tree
Hide file tree
Showing 245 changed files with 11,975 additions and 1,309 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ jobs:
lintTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4
- name: Install deps
run: make composer
- name: Bring up Docker
run: make up
- name: Lint & Test
run: make test
- name: Store logs
uses: actions/upload-artifact@v4
if: always()
with:
name: PHP Logs
path: storage/logs/
if-no-files-found: ignore
77 changes: 77 additions & 0 deletions app/Clients/GreenhouseClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace App\Clients;

use App\Exceptions\ExternalAPIException;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Log;

class GreenhouseClient
{
protected string $url;

protected string $token;

protected Client $client;

public function __construct(Client $client)
{
$this->url = config('services.greenhouse_api.url');
$this->token = config('services.greenhouse_api.token');
$this->client = $client;
}

public function getEnabled(): bool
{
return ! empty($this->url) && ! empty($this->token);
}

/**
* @throws ExternalAPIException
*/
public function notifyPolygonUpdated(string $polygonUuid): ?array
{
return $this->runQuery('tmNotifyFeatureUpdated', $polygonUuid);
}

/**
* @throws ExternalAPIException
*/
public function notifyMediaDeleted(string $mediaUuid): ?array
{
return $this->runQuery('tmNotifyMediaDeleted', $mediaUuid);
}

/**
* @throws ExternalAPIException
*/
protected function runQuery(string $functionName, string $uuid): ?array
{
if (! $this->getEnabled()) {
return null;
}

try {
$response = $this->client->request('POST', $this->url, [
'headers' => [
'api-key' => $this->token,
'Content-Type' => 'application/json',
],
'body' => json_encode([
'query' => 'mutation ($uuid: Id!) { ' . $functionName . '(uuid: $uuid) { ok } }',
'variables' => [ 'uuid' => $uuid ],
]),
]);
} catch (GuzzleException $exception) {
Log::error(
"Exception sending query to Greenhouse [fn=$functionName, uuid=$uuid]: " .
$exception->getMessage()
);

throw new ExternalAPIException($exception->getMessage(), $exception->getCode(), $exception);
}

return json_decode($response->getBody()->getContents(), true);
}
}
Loading

0 comments on commit df1dc23

Please sign in to comment.