diff options
Diffstat (limited to 'include/tgbot/Bot.h')
-rw-r--r-- | include/tgbot/Bot.h | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/include/tgbot/Bot.h b/include/tgbot/Bot.h index b8c8a85..e2d9027 100644 --- a/include/tgbot/Bot.h +++ b/include/tgbot/Bot.h @@ -24,11 +24,12 @@ #define TGBOT_CPP_BOT_H #include <string> - +#include <utility> #include "tgbot/Api.h" #include "tgbot/EventBroadcaster.h" #include "tgbot/EventHandler.h" #include "tgbot/net/HttpClient.h" +#include "tgbot/net/BoostHttpOnlySslClient.h" namespace TgBot { @@ -40,44 +41,48 @@ namespace TgBot { class Bot { public: - explicit Bot(const std::string& token, const HttpClient &httpClientDriver = BoostHttpClient::getInstance()) - : _token(token), _api(token, httpClientDriver), _eventHandler(&_eventBroadcaster), _httpClientDriver(httpClientDriver) { - } + explicit Bot(std::string token, const HttpClient& httpClient = _getDefaultHttpClient()) + : _token(std::move(token)), _api(_token, httpClient), _eventHandler(_eventBroadcaster) { + } - /** - * @return Token for accessing api. - */ - inline const std::string& getToken() const { - return _token; - } + /** + * @return Token for accessing api. + */ + inline const std::string& getToken() const { + return _token; + } - /** - * @return Object which can execute Telegram Bot API methods. - */ - inline const Api& getApi() const { - return _api; - } + /** + * @return Object which can execute Telegram Bot API methods. + */ + inline const Api& getApi() const { + return _api; + } - /** - * @return Object which holds all event listeners. - */ - inline EventBroadcaster& getEvents() { - return _eventBroadcaster; - } + /** + * @return Object which holds all event listeners. + */ + inline EventBroadcaster& getEvents() { + return _eventBroadcaster; + } - /** - * @return Object which handles new update objects. Usually it's only needed for TgLongPoll, TgWebhookLocalServer and TgWebhookTcpServer objects. - */ - inline const EventHandler& getEventHandler() const { - return _eventHandler; - } + /** + * @return Object which handles new update objects. Usually it's only needed for TgLongPoll, TgWebhookLocalServer and TgWebhookTcpServer objects. + */ + inline const EventHandler& getEventHandler() const { + return _eventHandler; + } private: - const std::string _token; - const Api _api; - EventBroadcaster _eventBroadcaster; - const EventHandler _eventHandler; - const HttpClient& _httpClientDriver; + static HttpClient& _getDefaultHttpClient() { + static BoostHttpOnlySslClient instance; + return instance; + } + + const std::string _token; + const Api _api; + EventBroadcaster _eventBroadcaster; + const EventHandler _eventHandler; }; } |