1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Resova\Endpoints; |
4
|
|
|
|
5
|
|
|
use Resova\Client; |
6
|
|
|
use Resova\Interfaces\QueryInterface; |
7
|
|
|
use Resova\Models\Webhook; |
8
|
|
|
use Resova\Models\WebhookDelete; |
9
|
|
|
use Resova\Models\WebhookList; |
10
|
|
|
|
11
|
|
|
class Webhooks extends Client |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $namespace = __CLASS__; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param int $webhook_id The webhook id |
20
|
|
|
* |
21
|
|
|
* @return $this |
22
|
|
|
*/ |
23
|
|
|
public function __invoke(int $webhook_id): self |
24
|
|
|
{ |
25
|
|
|
$this->webhook_id = $webhook_id; |
|
|
|
|
26
|
|
|
|
27
|
|
|
return $this; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* List all webhooks |
32
|
|
|
* Returns a list of your promotions. The promotions are returned sorted by creation date, with the most recent promotion appearing first. |
33
|
|
|
* |
34
|
|
|
* @return \Resova\Interfaces\QueryInterface |
35
|
|
|
*/ |
36
|
|
|
public function all(): QueryInterface |
37
|
|
|
{ |
38
|
|
|
// Set HTTP params |
39
|
|
|
$this->type = 'get'; |
40
|
|
|
$this->endpoint = '/webhooks'; |
41
|
|
|
$this->response = WebhookList::class; |
|
|
|
|
42
|
|
|
|
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Create a webhook |
48
|
|
|
* |
49
|
|
|
* @param Webhook $webhook |
50
|
|
|
* |
51
|
|
|
* @return \Resova\Interfaces\QueryInterface |
52
|
|
|
*/ |
53
|
|
|
public function create(Webhook $webhook): QueryInterface |
54
|
|
|
{ |
55
|
|
|
$webhook->setRequired([ |
56
|
|
|
'endpoint', |
57
|
|
|
'events', |
58
|
|
|
]); |
59
|
|
|
|
60
|
|
|
// Set HTTP params |
61
|
|
|
$this->type = 'post'; |
62
|
|
|
$this->endpoint = '/webhooks'; |
63
|
|
|
$this->params = $webhook; |
64
|
|
|
$this->response = Webhook::class; |
|
|
|
|
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Update a webhook |
71
|
|
|
* |
72
|
|
|
* @param Webhook $webhook |
73
|
|
|
* |
74
|
|
|
* @return \Resova\Interfaces\QueryInterface |
75
|
|
|
*/ |
76
|
|
|
public function update(Webhook $webhook): QueryInterface |
77
|
|
|
{ |
78
|
|
|
$webhook->setRequired([ |
79
|
|
|
'endpoint', |
80
|
|
|
'events', |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
// Set HTTP params |
84
|
|
|
$this->type = 'put'; |
85
|
|
|
$this->endpoint = '/webhooks/' . $this->webhook_id; |
86
|
|
|
$this->params = $webhook; |
87
|
|
|
$this->response = Webhook::class; |
|
|
|
|
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Delete a webhook |
94
|
|
|
* |
95
|
|
|
* @return \Resova\Interfaces\QueryInterface |
96
|
|
|
*/ |
97
|
|
|
public function delete(): QueryInterface |
98
|
|
|
{ |
99
|
|
|
// Set HTTP params |
100
|
|
|
$this->type = 'delete'; |
101
|
|
|
$this->endpoint = '/webhooks/' . $this->webhook_id; |
102
|
|
|
$this->response = WebhookDelete::class; |
|
|
|
|
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|