Completed
Push — master ( 4a5840...1f0278 )
by
unknown
11s
created

WebhookList::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Moip\Resource;
4
5
use Moip\Helper\Pagination;
6
use stdClass;
7
8
/**
9
 * Class Webhook.
10
 */
11
class WebhookList extends MoipResource
12
{
13
    /**
14
     * Path accounts API.
15
     *
16
     * @const string
17
     */
18
    const PATH = 'webhooks';
19
20
    /**
21
     * Initialize a new instance.
22
     */
23
    public function initialize()
24
    {
25
        $this->data = new stdClass();
26
        $this->data->webhooks = [];
27
    }
28
29
    /**
30
     * Get webhooks.
31
     *
32
     * @return array
33
     */
34
    public function getWebhooks()
35
    {
36
        return $this->getIfSet('webhooks');
37
    }
38
39
    /**
40
     * Get a webhook.
41
     *
42
     * @param Pagination $pagination
43
     * @param string     $resource_id
44
     * @param string     $event
45
     *
46
     * @return stdClass
47
     */
48
    public function get(Pagination $pagination = null, $resource_id = null, $event = null)
49
    {
50
        $params = [];
51
52
        if (!is_null($resource_id)) {
53
            $params['resourceId'] = $resource_id;
54
        }
55
56
        if (!is_null($event)) {
57
            $params['event'] = $event;
58
        }
59
60
        return $this->getByPath($this->generateListPath($pagination, null, $params));
61
    }
62
63
    /**
64
     * Mount structure of Webhook List.
65
     *
66
     * @param \stdClass $response
67
     *
68
     * @return \Moip\Resource\WebhookList Webhook List
69
     */
70
    protected function populate(stdClass $response)
71
    {
72
        $webhookList = clone $this;
73
        $webhookList->data = new stdClass();
74
75
        $webhookList->data->webhooks = $response->webhooks;
76
77
        return $webhookList;
78
    }
79
}
80