1
|
|
|
<?php |
2
|
|
|
namespace CodeCloud\Bundle\ShopifyBundle\Api\Endpoint; |
3
|
|
|
|
4
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\DeleteParams; |
5
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\GetJson; |
6
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PostJson; |
7
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PutJson; |
8
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource; |
9
|
|
|
|
10
|
|
|
class WebhookEndpoint extends AbstractEndpoint |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @param array $query |
14
|
|
|
* @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[] |
15
|
|
|
*/ |
16
|
|
|
public function findAll(array $query = array()) |
17
|
|
|
{ |
18
|
|
|
$request = new GetJson('/admin/webhooks.json', $query); |
19
|
|
|
$response = $this->sendPaged($request, 'webhooks'); |
20
|
|
|
return $this->createCollection($response); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param array $query |
25
|
|
|
* @return int |
26
|
|
|
*/ |
27
|
|
|
public function countAll(array $query = array()) |
28
|
|
|
{ |
29
|
|
|
$request = new GetJson('/admin/webhooks/count.json', $query); |
30
|
|
|
$response = $this->send($request); |
31
|
|
|
return $response->get('count'); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param int $webhookId |
36
|
|
|
* @param array $fields |
37
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
38
|
|
|
*/ |
39
|
|
|
public function findOne($webhookId, array $fields = array()) |
40
|
|
|
{ |
41
|
|
|
$params = $fields ? array('fields' => implode(',', $fields)) : array(); |
42
|
|
|
$request = new GetJson('/admin/webhooks/' . $webhookId . '.json', $params); |
43
|
|
|
$response = $this->send($request); |
44
|
|
|
return $this->createEntity($response->get('webhook')); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param GenericResource $webhook |
49
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
50
|
|
|
*/ |
51
|
|
|
public function create(GenericResource $webhook) |
52
|
|
|
{ |
53
|
|
|
$request = new PostJson('/admin/webhooks.json', array('webhook' => $webhook->toArray())); |
54
|
|
|
$response = $this->send($request); |
55
|
|
|
return $this->createEntity($response->get('webhook')); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $webhook |
60
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
61
|
|
|
*/ |
62
|
|
|
public function update($webhookId, GenericResource $webhook) |
63
|
|
|
{ |
64
|
|
|
$request = new PutJson('/admin/webhooks/' . $webhookId . '.json', array('webhook' => $webhook->toArray())); |
65
|
|
|
$response = $this->send($request); |
66
|
|
|
return $this->createEntity($response->get('webhook')); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param int $webhookId |
71
|
|
|
*/ |
72
|
|
|
public function delete($webhookId) |
73
|
|
|
{ |
74
|
|
|
$request = new DeleteParams('/admin/webhooks/' . $webhookId . '.json'); |
75
|
|
|
$this->send($request); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|