mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-03 20:56:21 +00:00
API ability to manage webhooks.
This commit is contained in:
@@ -36,19 +36,6 @@ class UserTransformer extends AbstractTransformer
|
||||
/** @var UserRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* UserTransformer constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->repository = app(UserRepositoryInterface::class);
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform user.
|
||||
*
|
||||
|
||||
73
app/Transformers/WebhookTransformer.php
Normal file
73
app/Transformers/WebhookTransformer.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/*
|
||||
* WebhookTransformer.php
|
||||
* Copyright (c) 2020 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
use FireflyIII\Models\Webhook;
|
||||
|
||||
/**
|
||||
* Class WebhookTransformer
|
||||
*/
|
||||
class WebhookTransformer extends AbstractTransformer
|
||||
{
|
||||
private array $enums;
|
||||
|
||||
/**
|
||||
* WebhookTransformer constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// array merge kills the keys
|
||||
$this->enums = config('firefly.webhooks.triggers') + config('firefly.webhooks.responses') + config('firefly.webhooks.deliveries');
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform webhook.
|
||||
*
|
||||
* @param Webhook $webhook
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Webhook $webhook): array
|
||||
{
|
||||
return [
|
||||
'id' => (int)$webhook->id,
|
||||
'created_at' => $webhook->created_at->toAtomString(),
|
||||
'updated_at' => $webhook->updated_at->toAtomString(),
|
||||
'active' => $webhook->active,
|
||||
'trigger' => $this->getEnum($webhook->trigger),
|
||||
'response' => $this->getEnum($webhook->response),
|
||||
'delivery' => $this->getEnum($webhook->delivery),
|
||||
'url' => $webhook->url,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => sprintf('/webhooks/%d', $webhook->id),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function getEnum(int $value)
|
||||
{
|
||||
return $this->enums[$value] ?? 'UNKNOWN_VALUE';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user