Completed
Push — master ( 84b41c...1fa072 )
by Mads
01:01
created

Webhook::updateWebhook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Fenerum\API;
6
7
class Webhook extends Base
8
{
9
    /**
10
     * @return array|null
11
     * @throws \GuzzleHttp\Exception\GuzzleException
12
     */
13
    public function listWebhooks(): ?array
14
    {
15
        return $this->client->get('webhooks/');
16
    }
17
18
    /**
19
     * @param string $uuid
20
     * @return array|null
21
     * @throws \GuzzleHttp\Exception\GuzzleException
22
     */
23
    public function getWebhook(string $uuid): ?array
24
    {
25
        return $this->client->get('webhooks/'.$uuid.'/');
26
    }
27
28
    /**
29
     * @param array $data
30
     * @return array|null
31
     * @throws \GuzzleHttp\Exception\GuzzleException
32
     * @throws \Illuminate\Validation\ValidationException
33
     */
34
    public function createWebhook(array $data): ?array
35
    {
36
        $validated = $this->validate($data, [
37
            'endpoint' => 'required|string',
38
            'basic_auth_username' => 'string',
39
            'basic_auth_password' => 'string',
40
            'enabled' => 'boolean',
41
            'events' => 'array',
42
        ]);
43
44
        return $this->client->post('webhooks/', $validated);
45
    }
46
47
    /**
48
     * @param array $data
49
     * @param string $uuid
50
     * @return array|null
51
     * @throws \GuzzleHttp\Exception\GuzzleException
52
     * @throws \Illuminate\Validation\ValidationException
53
     */
54
    public function updateWebhook(array $data, string $uuid): ?array
55
    {
56
        $validated = $this->validate($data, [
57
            'endpoint' => 'required|string',
58
            'basic_auth_username' => 'string',
59
            'basic_auth_password' => 'string',
60
            'enabled' => 'boolean',
61
            'events' => 'array',
62
        ]);
63
64
        return $this->client->put('webhooks/'.$uuid.'/', $validated);
65
    }
66
}
67