Skip to content

Commit 902deb9

Browse files
committed
Remove guzzle
1 parent d73825e commit 902deb9

2 files changed

Lines changed: 11 additions & 20 deletions

File tree

src/Notifier/Adapters/SlackChannelAdapter.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
namespace Bow\Notifier\Adapters;
44

55
use Bow\Database\Barry\Model;
6+
use Bow\Http\Client\HttpClient;
67
use Bow\Notifier\Contracts\ChannelAdapterInterface;
78
use Bow\Notifier\Notifier;
8-
use GuzzleHttp\Client;
9-
use GuzzleHttp\Exception\GuzzleException;
109

1110
class SlackChannelAdapter implements ChannelAdapterInterface
1211
{
@@ -16,7 +15,7 @@ class SlackChannelAdapter implements ChannelAdapterInterface
1615
* @param Model $context
1716
* @param Notifier $notifier
1817
* @return void
19-
* @throws GuzzleException
18+
* @throws \Exception
2019
*/
2120
public function send(Model $context, Notifier $notifier): void
2221
{
@@ -36,15 +35,10 @@ public function send(Model $context, Notifier $notifier): void
3635
throw new \InvalidArgumentException('The webhook URL is required for Slack');
3736
}
3837

39-
$client = new Client();
38+
$client = new HttpClient();
4039

4140
try {
42-
$client->post($webhook_url, [
43-
'json' => $data['content'],
44-
'headers' => [
45-
'Content-Type' => 'application/json'
46-
]
47-
]);
41+
$client->acceptJson()->post($webhook_url, $data['content']);
4842
} catch (\Exception $e) {
4943
throw new \RuntimeException('Error while sending Slack notifier: ' . $e->getMessage());
5044
}

src/Notifier/Adapters/TelegramChannelAdapter.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
namespace Bow\Notifier\Adapters;
44

55
use Bow\Database\Barry\Model;
6+
use Bow\Http\Client\HttpClient;
67
use Bow\Notifier\Contracts\ChannelAdapterInterface;
78
use Bow\Notifier\Notifier;
89
use Exception;
9-
use GuzzleHttp\Client;
10-
use GuzzleHttp\Exception\GuzzleException;
1110
use InvalidArgumentException;
1211
use RuntimeException;
1312

@@ -38,7 +37,7 @@ public function __construct()
3837
* @param Model $context
3938
* @param Notifier $notifier
4039
* @return void
41-
* @throws GuzzleException
40+
* @throws Exception
4241
*/
4342
public function send(Model $context, Notifier $notifier): void
4443
{
@@ -52,16 +51,14 @@ public function send(Model $context, Notifier $notifier): void
5251
throw new InvalidArgumentException('The chat ID and message are required for Telegram');
5352
}
5453

55-
$client = new Client();
54+
$client = new HttpClient();
5655
$endpoint = "https://api.telegram.org/bot{$this->botToken}/sendMessage";
5756

5857
try {
59-
$client->post($endpoint, [
60-
'json' => [
61-
'chat_id' => $data['chat_id'],
62-
'text' => $data['message'],
63-
'parse_mode' => $data['parse_mode'] ?? 'HTML'
64-
]
58+
$client->acceptJson()->post($endpoint, [
59+
'chat_id' => $data['chat_id'],
60+
'text' => $data['message'],
61+
'parse_mode' => $data['parse_mode'] ?? 'HTML'
6562
]);
6663
} catch (Exception $e) {
6764
throw new RuntimeException('Error while sending Telegram message: ' . $e->getMessage());

0 commit comments

Comments
 (0)