Skip to content

Commit 6d93cc8

Browse files
authored
Merge pull request #2 from prajapati-kaushik/acknowledge-alert
feat: acknowledgement alert
2 parents fd2b5eb + 13b003a commit 6d93cc8

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

src/Alert/AckAlertRequest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace JTL\OpsGenie\Client\Alert;
6+
7+
use JTL\OpsGenie\Client\OpsGenieRequest;
8+
9+
class AckAlertRequest implements OpsGenieRequest
10+
{
11+
/**
12+
* @var string
13+
*/
14+
private $alias;
15+
16+
/**
17+
* @var string
18+
*/
19+
private $user;
20+
21+
/**
22+
* @var string
23+
*/
24+
private $source;
25+
26+
/**
27+
* @var string
28+
*/
29+
private $note;
30+
31+
public function __construct(string $alias)
32+
{
33+
$this->alias = $alias;
34+
}
35+
36+
public function setUser(string $user): void
37+
{
38+
$this->user = $user;
39+
}
40+
41+
public function setSource(string $source): void
42+
{
43+
$this->source = $source;
44+
}
45+
46+
public function setNote(string $note): void
47+
{
48+
$this->note = $note;
49+
}
50+
51+
public function getHttpMethod(): string
52+
{
53+
return 'POST';
54+
}
55+
56+
public function getUrl(): string
57+
{
58+
return 'acknowledge';
59+
}
60+
61+
public function getBody(): array
62+
{
63+
$request = [];
64+
if (!empty($this->user)) {
65+
$request['user'] = $this->user;
66+
}
67+
68+
if (!empty($this->source)) {
69+
$request['source'] = $this->source;
70+
}
71+
72+
if (!empty($this->note)) {
73+
$request['note'] = $this->note;
74+
}
75+
76+
return $request;
77+
}
78+
}

src/Alert/AckAlertResponse.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace JTL\OpsGenie\Client\Alert;
4+
5+
use JTL\OpsGenie\Client\OpsGenieResponse;
6+
7+
class AckAlertResponse extends OpsGenieResponse
8+
{
9+
public function isSuccessful(): bool
10+
{
11+
return 202 === $this->getStatusCode();
12+
}
13+
}

src/AlertApiClient.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace JTL\OpsGenie\Client;
1212

13+
use JTL\OpsGenie\Client\Alert\AckAlertRequest;
14+
use JTL\OpsGenie\Client\Alert\AckAlertResponse;
1315
use JTL\OpsGenie\Client\Alert\CloseAlertRequest;
1416
use JTL\OpsGenie\Client\Alert\CloseAlertResponse;
1517
use JTL\OpsGenie\Client\Alert\CreateAlertRequest;
@@ -64,4 +66,14 @@ public function closeAlert(CloseAlertRequest $request): CloseAlertResponse
6466
{
6567
return $this->client->request($request, CloseAlertResponse::class);
6668
}
69+
70+
/**
71+
* @param CloseAlertRequest $request
72+
* @return AckAlertResponse
73+
* @throws \GuzzleHttp\Exception\GuzzleException
74+
*/
75+
public function ackAlert(AckAlertRequest $request): AckAlertResponse
76+
{
77+
return $this->client->request($request, AckAlertResponse::class);
78+
}
6779
}

0 commit comments

Comments
 (0)