summaryrefslogtreecommitdiff
path: root/include/tgbot/Bot.h
diff options
context:
space:
mode:
authorOleg Morozenkov <m@oleg.rocks>2018-07-23 02:35:50 +0300
committerOleg Morozenkov <m@oleg.rocks>2018-07-23 02:35:50 +0300
commit98b8b7e4338b71ee46c4301b0bf2ae667be9a99d (patch)
tree32f8b0d32048b2d83b57773c0efa3db9600b8701 /include/tgbot/Bot.h
parent1dd3affe306793d2129f121c11e43c45ae8690da (diff)
parent167e3e7607e43a0f06c7f87ced94f481e6525b0e (diff)
Merge branch 'master' into nicholascw-master
Diffstat (limited to 'include/tgbot/Bot.h')
-rw-r--r--include/tgbot/Bot.h72
1 files changed, 40 insertions, 32 deletions
diff --git a/include/tgbot/Bot.h b/include/tgbot/Bot.h
index 8dd4c16..e2d9027 100644
--- a/include/tgbot/Bot.h
+++ b/include/tgbot/Bot.h
@@ -24,57 +24,65 @@
#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 {
/**
* @brief This object holds other objects specific for this bot instance.
- *
+ *
* @ingroup general
*/
class Bot {
public:
- explicit Bot(const std::string& token) : _token(token), _api(token), _eventHandler(&_eventBroadcaster) {
- }
+ 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;
+ static HttpClient& _getDefaultHttpClient() {
+ static BoostHttpOnlySslClient instance;
+ return instance;
+ }
+
+ const std::string _token;
+ const Api _api;
+ EventBroadcaster _eventBroadcaster;
+ const EventHandler _eventHandler;
};
}