Webhooks::webhook()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Amelia\Monzo\Api;
4
5
use Amelia\Monzo\Models\Webhook;
6
7
trait Webhooks
8
{
9
    /**
10
     * Get a user's webhooks.
11
     *
12
     * @param string|null $account
13
     * @return \Amelia\Monzo\Models\Webhook[]|\Illuminate\Support\Collection
14
     */
15
    public function webhooks(string $account = null)
16
    {
17
        $results = $this->call('GET', 'webhooks', [
18
            'account_id' => $account ?? $this->getAccountId(),
19
        ], [], 'webhooks');
20
21
        return collect($results)->map(function ($item) {
22
            return new Webhook($item, $this);
23
        });
24
    }
25
26
    /**
27
     * Get an individual webhook by ID.
28
     *
29
     * @param string $id
30
     * @return \Amelia\Monzo\Models\Webhook
31
     */
32
    public function webhook(string $id)
33
    {
34
        $result = $this->call('GET', "webhooks/$id", [], [], 'webhooks');
35
36
        return new Webhook($result, $this);
37
    }
38
39
    /**
40
     * Delete a webhook by ID.
41
     *
42
     * @param string $id
43
     * @return void
44
     */
45
    public function deleteWebhook(string $id)
46
    {
47
        $this->call('DELETE', "webhooks/$id");
48
    }
49
50
    /**
51
     * Register a webhook to an optional account.
52
     *
53
     * @param string $url
54
     * @param string|null $account
55
     * @return \Amelia\Monzo\Models\Webhook
56
     */
57
    public function registerWebhook(string $url, string $account = null)
58
    {
59
        $result = $this->call('POST', 'webhooks', [], [
60
            'url' => $url,
61
            'account_id' => $account ?? $this->getAccountId(),
62
        ], 'webhook');
63
64
        return new Webhook($result, $this);
65
    }
66
}
67