mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
API ability to manage webhooks.
This commit is contained in:
73
app/Api/V1/Requests/Webhook/CreateRequest.php
Normal file
73
app/Api/V1/Requests/Webhook/CreateRequest.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/*
|
||||
* CreateRequest.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\Api\V1\Requests\Webhook;
|
||||
|
||||
use FireflyIII\Rules\IsBoolean;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* Class CreateRequest
|
||||
*/
|
||||
class CreateRequest extends FormRequest
|
||||
{
|
||||
use ChecksLogin, ConvertsDataTypes;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getData(): array
|
||||
{
|
||||
$triggers = array_flip(config('firefly.webhooks.triggers'));
|
||||
$responses = array_flip(config('firefly.webhooks.responses'));
|
||||
$deliveries = array_flip(config('firefly.webhooks.deliveries'));
|
||||
|
||||
return [
|
||||
'active' => $this->boolean('active'),
|
||||
'trigger' => $triggers[$this->string('trigger')] ?? 0,
|
||||
'response' => $responses[$this->string('response')] ?? 0,
|
||||
'delivery' => $deliveries[$this->string('delivery')] ?? 0,
|
||||
'url' => $this->string('url'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Rules for this request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$triggers = implode(',', array_values(config('firefly.webhooks.triggers')));
|
||||
$responses = implode(',', array_values(config('firefly.webhooks.responses')));
|
||||
$deliveries = implode(',', array_values(config('firefly.webhooks.deliveries')));
|
||||
|
||||
return [
|
||||
'active' => [new IsBoolean],
|
||||
'trigger' => sprintf('required|in:%s', $triggers),
|
||||
'response' => sprintf('required|in:%s', $responses),
|
||||
'delivery' => sprintf('required|in:%s', $deliveries),
|
||||
'url' => ['required', 'url', 'starts_with:https://', 'uniqueWebhook'],
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user