summaryrefslogtreecommitdiff
path: root/include/tgbot/Bot.h
diff options
context:
space:
mode:
authorOleg Morozenkov <m@oleg.rocks>2018-07-23 01:56:42 +0300
committerOleg Morozenkov <m@oleg.rocks>2018-07-23 01:56:42 +0300
commitd47ee877be5d1175bdc36f2d87881ddaf875a8e9 (patch)
tree7fd20cdc1236fe6b832ae980de12afd7071ebab9 /include/tgbot/Bot.h
parentcea20d4078f2088dea0dd589f1cc9dd7ee22461b (diff)
Refactor http clients, fix webhook server, add more samples, change tabs to 4 spaces
Diffstat (limited to 'include/tgbot/Bot.h')
-rw-r--r--include/tgbot/Bot.h71
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;
};
}