Skip to content

Commit f5026f2

Browse files
authored
Merge pull request #64 from itorgov/webhook-management
Implemented the webhook manager
2 parents 58517d1 + 5b7050e commit f5026f2

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

readme.md

+15
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,21 @@ $worker->delete();
299299
$worker->restart($wait = true);
300300
```
301301

302+
## Site Webhooks
303+
304+
```php
305+
$forge->webhooks($serverId, $siteId);
306+
$forge->webhook($serverId, $siteId, $webhookId);
307+
$forge->createWebhook($serverId, $siteId, array $data);
308+
$forge->deleteWebhook($serverId, $siteId, $webhookId);
309+
```
310+
311+
On a Webhook Instance you may also call:
312+
313+
```php
314+
$webhook->delete();
315+
```
316+
302317
## Site SSL Certificates
303318

304319
```php

src/Actions/ManagesWebhooks.php

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Themsaid\Forge\Actions;
4+
5+
use Themsaid\Forge\Resources\Webhook;
6+
7+
trait ManagesWebhooks
8+
{
9+
/**
10+
* Get the collection of webhooks.
11+
*
12+
* @param integer $serverId
13+
* @param integer $siteId
14+
* @return Webhook[]
15+
*/
16+
public function webhooks($serverId, $siteId)
17+
{
18+
return $this->transformCollection(
19+
$this->get("servers/$serverId/sites/$siteId/webhooks")['webhooks'],
20+
Webhook::class,
21+
['server_id' => $serverId, 'site_id' => $siteId]
22+
);
23+
}
24+
25+
/**
26+
* Get a webhook instance.
27+
*
28+
* @param integer $serverId
29+
* @param integer $siteId
30+
* @param integer $webhookId
31+
* @return Webhook
32+
*/
33+
public function webhook($serverId, $siteId, $webhookId)
34+
{
35+
return new Webhook(
36+
$this->get("servers/$serverId/sites/$siteId/webhooks/$webhookId")['webhook']
37+
+ ['server_id' => $serverId, 'site_id' => $siteId], $this
38+
);
39+
}
40+
41+
/**
42+
* Create a new webhook.
43+
*
44+
* @param integer $serverId
45+
* @param integer $siteId
46+
* @param array $data
47+
* @return Webhook
48+
*/
49+
public function createWebhook($serverId, $siteId, array $data)
50+
{
51+
return new Webhook(
52+
$this->post("servers/$serverId/sites/$siteId/webhooks", $data)['webhook']
53+
+ ['server_id' => $serverId, 'site_id' => $siteId], $this
54+
);
55+
}
56+
57+
/**
58+
* Delete the given webhook.
59+
*
60+
* @param integer $serverId
61+
* @param integer $siteId
62+
* @param integer $webhookId
63+
* @return void
64+
*/
65+
public function deleteWebhook($serverId, $siteId, $webhookId)
66+
{
67+
$this->delete("servers/$serverId/sites/$siteId/webhooks/$webhookId");
68+
}
69+
}

src/Forge.php

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Forge
1515
Actions\ManagesWorkers,
1616
Actions\ManagesSSHKeys,
1717
Actions\ManagesRecipes,
18+
Actions\ManagesWebhooks,
1819
Actions\ManagesMysqlUsers,
1920
Actions\ManagesCredentials,
2021
Actions\ManagesCertificates,

src/Resources/Webhook.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Themsaid\Forge\Resources;
4+
5+
class Webhook extends Resource
6+
{
7+
/**
8+
* The id of the webhook.
9+
*
10+
* @var integer
11+
*/
12+
public $id;
13+
14+
/**
15+
* The destination url.
16+
*
17+
* @var string
18+
*/
19+
public $url;
20+
21+
/**
22+
* The date/time the webhook was created.
23+
*
24+
* @var string
25+
*/
26+
public $createdAt;
27+
28+
/**
29+
* Delete the given webhook.
30+
*
31+
* @return void
32+
*/
33+
public function delete()
34+
{
35+
return $this->forge->deleteWebhook($this->serverId, $this->siteId, $this->id);
36+
}
37+
}

0 commit comments

Comments
 (0)