Passed
Push — develop ( 5aaf1d...94414b )
by Edwin
02:19
created

Webhook::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
3
namespace ShopifyClient\Resource;
4
5
/**
6
 * https://help.shopify.com/api/reference/webhook
7
 */
8
class Webhook extends AbstractResource
9
{
10
    /**
11
     * @var bool
12
     */
13
    protected $countable = true;
14
15
    /**
16
     * @param float $id
17
     * @param array $fields
18
     * @return array
19
     */
20 1
    public function get(float $id, array $fields = [])
21
    {
22 1
        $response = $this->request('GET', sprintf('/admin/webhooks/%s.json', $id), [
23
            'query' => [
24 1
                'fields' => $fields
25
            ]
26
        ]);
27
28 1
        return $response['webhook'];
29
    }
30
31
    /**
32
     * @param array $query
33
     * @return array
34
     */
35 1
    public function all(array $query = [])
36
    {
37 1
        $response = $this->request('GET', '/admin/webhooks.json', [
38 1
            'query' => $query
39
        ]);
40
41 1
        return $response['webhooks'];
42
    }
43
44
    /**
45
     * @param array $query
46
     * @return array
47
     */
48 1
    public function count(array $query = [])
49
    {
50 1
        $response = $this->request('GET', '/admin/webhooks/count.json', [
51 1
            'query' => $query
52
        ]);
53
54 1
        return $response['count'];
55
    }
56
57
    /**
58
     * @param array $params
59
     * @return array
60
     */
61 1
    public function create(array $params = [])
62
    {
63 1
        $response = $this->request('POST', '/admin/webhooks.json', [
64 1
            'body' => json_encode([
65 1
                'webhook' => $params,
66
            ]),
67
        ]);
68
69 1
        return $response['webhook'];
70
    }
71
72
    /**
73
     * @param float $id
74
     * @param array $params
75
     * @return array
76
     */
77 1
    public function update(float $id, array $params = [])
78
    {
79 1
        $response = $this->request('PUT', sprintf('/admin/webhooks/%s.json', $id), [
80 1
            'body' => json_encode([
81 1
                'webhook' => $params,
82
            ]),
83
        ]);
84
85 1
        return $response['webhook'];
86
    }
87
88
    /**
89
     * @param float $id
90
     */
91 1
    public function delete(float $id)
92
    {
93 1
        $this->request('DELETE', sprintf('/admin/webhooks/%s.json', $id));
94 1
    }
95
}
96