Skip to content

Commit

Permalink
ips() method added to Webhooks resource
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpmartins committed Nov 19, 2024
1 parent a3425b7 commit 56ca560
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Resources/Webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,35 @@ public function create(array $webhook): array
return $this->requestTransport->transport($request);
}

/**
* Get a list of webhook IPs.
*
* ## Usage
* ```php
* $result = $client->webhooks()->ips();
*
* foreach ($result["ips"] as $ip) {
* echo $ip; // string
* }
*
* $result["ips"][0]; // "189.51.60.9"
* $result["ips"][1]; // "138.97.124.129"
* $result["ips"][2]; // "177.71.136.66"
* ```
*
* @link https://developers.openpix.com.br/api#tag/webhook/paths/~1api~1v1~1webhook~1ips/get
*
* @return array<string, mixed>
*/
public function ips(): array
{
$request = (new Request())
->method("GET")
->path("/api/v1/webhook/ips");

return $this->requestTransport->transport($request);
}

/**
* Validate webhook signature.
*
Expand Down
20 changes: 20 additions & 0 deletions tests/Resources/WebhooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ public function testCreate(): void
$this->assertSame(["webhook" => []], $result);
}

public function testIps(): void
{
$requestTransportMock = $this->createMock(RequestTransport::class);
$requestTransportMock->expects($this->once())
->method("transport")
->willReturnCallback(function (Request $request) {
$this->assertSame("GET", $request->getMethod());
$this->assertSame("/api/v1/webhook/ips", $request->getPath());
$this->assertSame(null, $request->getBody());
$this->assertSame([], $request->getQueryParams());

return ["ips" => []];
});

$webhooks = new Webhooks($requestTransportMock);
$result = $webhooks->ips();

$this->assertSame(["ips" => []], $result);
}

public function testIsWebhookValidReturnsTrueWithValidWebhook(): void
{
$webhooks = new Webhooks($this->createStub(RequestTransport::class));
Expand Down

0 comments on commit 56ca560

Please sign in to comment.