Skip to content

Commit f7f0c6d

Browse files
authored
Merge pull request #137 from ToshY/feature/136
Split `addAndUpdateEdgeRule` into specific `addEdgeRule` and `updateEdgeRule` methods
2 parents 81d19df + c4a317d commit f7f0c6d

File tree

4 files changed

+127
-15
lines changed

4 files changed

+127
-15
lines changed

docs/base-api.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,22 +1436,12 @@ $baseApi->deletePullZone(
14361436
);
14371437
```
14381438

1439-
#### [Delete Edge Rule](https://docs.bunny.net/reference/pullzonepublic_deleteedgerule)
1440-
1441-
```php
1442-
$baseApi->deleteEdgeRule(
1443-
pullZoneId: 1,
1444-
edgeRuleId: 'c71d9594-3bc6-4639-9896-ba3e96217587',
1445-
);
1446-
```
1447-
1448-
#### [Add/Update Edge Rule](https://docs.bunny.net/reference/pullzonepublic_addedgerule)
1439+
#### [Add Edge Rule](https://docs.bunny.net/reference/pullzonepublic_addedgerule)
14491440

14501441
```php
1451-
$baseApi->addOrUpdateEdgeRule(
1442+
$baseApi->addEdgeRule(
14521443
pullZoneId: 1,
14531444
body: [
1454-
'Guid' => 'c71d9594-3bc6-4639-9896-ba3e96217587',
14551445
'ActionType' => 4,
14561446
'ActionParameter1' => '',
14571447
'ActionParameter2' => '',
@@ -1515,6 +1505,27 @@ $baseApi->addOrUpdateEdgeRule(
15151505
- `1` = Match All
15161506
- `2` = Match None
15171507

1508+
#### [Update Edge Rule](https://docs.bunny.net/reference/pullzonepublic_addedgerule)
1509+
1510+
```php
1511+
$baseApi->updateEdgeRule(
1512+
pullZoneId: 1,
1513+
body: [
1514+
'Guid' => 'c71d9594-3bc6-4639-9896-ba3e96217587',
1515+
'Triggers' => [
1516+
[
1517+
'Type' => 7,
1518+
'PatternMatches' => ['75']
1519+
],
1520+
],
1521+
],
1522+
);
1523+
```
1524+
1525+
!!! note
1526+
1527+
- The keys `Guid` and `Triggers` in the body are required parameters when updating an edge rule.
1528+
15181529
#### [Set Edge Rule Enabled](https://docs.bunny.net/reference/pullzonepublic_setedgeruleenabled)
15191530

15201531
```php
@@ -1532,6 +1543,15 @@ $baseApi->setEdgeRuleEnabled(
15321543

15331544
- The key `Id` in the body denotes the pull zone ID (the same as the first argument) and is (for some reason) a required parameter.
15341545

1546+
#### [Delete Edge Rule](https://docs.bunny.net/reference/pullzonepublic_deleteedgerule)
1547+
1548+
```php
1549+
$baseApi->deleteEdgeRule(
1550+
pullZoneId: 1,
1551+
edgeRuleId: 'c71d9594-3bc6-4639-9896-ba3e96217587',
1552+
);
1553+
```
1554+
15351555
#### Set Zone Security Enabled
15361556

15371557
```php

src/BaseAPI.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
use ToshY\BunnyNet\Model\API\Base\DRMCertificate\ListDRMCertificates;
5959
use ToshY\BunnyNet\Model\API\Base\PullZone\AddCustomCertificate;
6060
use ToshY\BunnyNet\Model\API\Base\PullZone\AddCustomHostname;
61-
use ToshY\BunnyNet\Model\API\Base\PullZone\AddOrUpdateEdgeRule;
61+
use ToshY\BunnyNet\Model\API\Base\PullZone\AddEdgeRule;
62+
use ToshY\BunnyNet\Model\API\Base\PullZone\UpdateEdgeRule;
6263
use ToshY\BunnyNet\Model\API\Base\PullZone\AddPullZone;
6364
use ToshY\BunnyNet\Model\API\Base\PullZone\CheckPullZoneAvailability;
6465
use ToshY\BunnyNet\Model\API\Base\PullZone\DeleteCertificate;
@@ -1693,12 +1694,58 @@ public function deleteEdgeRule(
16931694
* @return BunnyClientResponseInterface
16941695
* @param int $pullZoneId
16951696
* @param array<string,mixed> $body
1697+
*
1698+
* @deprecated since 4.5 (to be removed in 5.0). Use {@link addEdgeRule} or {@link updateEdgeRule} instead.
16961699
*/
16971700
public function addOrUpdateEdgeRule(
16981701
int $pullZoneId,
16991702
array $body,
17001703
): BunnyClientResponseInterface {
1701-
$endpoint = new AddOrUpdateEdgeRule();
1704+
return $this->addEdgeRule($pullZoneId, $body);
1705+
}
1706+
1707+
/**
1708+
* @throws ClientExceptionInterface
1709+
* @throws Exception\BunnyClientResponseException
1710+
* @throws Exception\JSONException
1711+
* @throws Exception\InvalidTypeForKeyValueException
1712+
* @throws Exception\InvalidTypeForListValueException
1713+
* @throws Exception\ParameterIsRequiredException
1714+
* @return BunnyClientResponseInterface
1715+
* @param int $pullZoneId
1716+
* @param array<string,mixed> $body
1717+
*/
1718+
public function addEdgeRule(
1719+
int $pullZoneId,
1720+
array $body,
1721+
): BunnyClientResponseInterface {
1722+
$endpoint = new AddEdgeRule();
1723+
1724+
ParameterValidator::validate($body, $endpoint->getBody());
1725+
1726+
return $this->client->request(
1727+
endpoint: $endpoint,
1728+
parameters: [$pullZoneId],
1729+
body: BodyContentHelper::getBody($body),
1730+
);
1731+
}
1732+
1733+
/**
1734+
* @throws ClientExceptionInterface
1735+
* @throws Exception\BunnyClientResponseException
1736+
* @throws Exception\JSONException
1737+
* @throws Exception\InvalidTypeForKeyValueException
1738+
* @throws Exception\InvalidTypeForListValueException
1739+
* @throws Exception\ParameterIsRequiredException
1740+
* @return BunnyClientResponseInterface
1741+
* @param int $pullZoneId
1742+
* @param array<string,mixed> $body
1743+
*/
1744+
public function updateEdgeRule(
1745+
int $pullZoneId,
1746+
array $body,
1747+
): BunnyClientResponseInterface {
1748+
$endpoint = new UpdateEdgeRule();
17021749

17031750
ParameterValidator::validate($body, $endpoint->getBody());
17041751

src/Model/API/Base/PullZone/AddOrUpdateEdgeRule.php renamed to src/Model/API/Base/PullZone/AddEdgeRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use ToshY\BunnyNet\Model\EndpointBodyInterface;
1212
use ToshY\BunnyNet\Model\EndpointInterface;
1313

14-
class AddOrUpdateEdgeRule implements EndpointInterface, EndpointBodyInterface
14+
class AddEdgeRule implements EndpointInterface, EndpointBodyInterface
1515
{
1616
public function getMethod(): Method
1717
{
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ToshY\BunnyNet\Model\API\Base\PullZone;
6+
7+
use ToshY\BunnyNet\Enum\Header;
8+
use ToshY\BunnyNet\Enum\Method;
9+
use ToshY\BunnyNet\Enum\Type;
10+
use ToshY\BunnyNet\Model\AbstractParameter;
11+
use ToshY\BunnyNet\Model\EndpointBodyInterface;
12+
use ToshY\BunnyNet\Model\EndpointInterface;
13+
14+
class UpdateEdgeRule implements EndpointInterface, EndpointBodyInterface
15+
{
16+
public function getMethod(): Method
17+
{
18+
return Method::POST;
19+
}
20+
21+
public function getPath(): string
22+
{
23+
return 'pullzone/%d/edgerules/addOrUpdate';
24+
}
25+
26+
public function getHeaders(): array
27+
{
28+
return [
29+
Header::CONTENT_TYPE_JSON,
30+
];
31+
}
32+
33+
public function getBody(): array
34+
{
35+
return [
36+
new AbstractParameter(name: 'Guid', type: Type::STRING_TYPE, required: true),
37+
new AbstractParameter(name: 'Triggers', type: Type::ARRAY_TYPE, required: true, children: [
38+
new AbstractParameter(name: 'Type', type: Type::INT_TYPE),
39+
new AbstractParameter(name: 'PatternMatches', type: Type::ARRAY_TYPE, children: [
40+
new AbstractParameter(name: null, type: Type::STRING_TYPE),
41+
]),
42+
]),
43+
];
44+
}
45+
}

0 commit comments

Comments
 (0)