Allow setting a custom Guzzle HTTP Client for requests.

parent 41cfa0b6
...@@ -6,6 +6,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -6,6 +6,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
## [Unreleased] ## [Unreleased]
### Added ### Added
- Documents can be sent by providing its contents via Psr7 stream (as opposed to passing a file path). - Documents can be sent by providing its contents via Psr7 stream (as opposed to passing a file path).
- Allow setting a custom Guzzle HTTP Client for requests (#511).
### Changed ### Changed
### Deprecated ### Deprecated
### Removed ### Removed
......
...@@ -104,16 +104,32 @@ class Request ...@@ -104,16 +104,32 @@ class Request
* *
* @param \Longman\TelegramBot\Telegram $telegram * @param \Longman\TelegramBot\Telegram $telegram
* *
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function initialize(Telegram $telegram) public static function initialize(Telegram $telegram)
{ {
if (is_object($telegram)) { if (!($telegram instanceof Telegram)) {
self::$telegram = $telegram; throw new TelegramException('Invalid Telegram pointer!');
self::$client = new Client(['base_uri' => self::$api_base_uri]); }
} else {
throw new TelegramException('Telegram pointer is empty!'); self::$telegram = $telegram;
self::setClient(new Client(['base_uri' => self::$api_base_uri]));
}
/**
* Set a custom Guzzle HTTP Client object
*
* @param Client $client
*
* @throws TelegramException
*/
public static function setClient(Client $client)
{
if (!($client instanceof Client)) {
throw new TelegramException('Invalid GuzzleHttp\Client pointer!');
} }
self::$client = $client;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment