mirror of
https://github.com/UltraCoderRU/telebotxx.git
synced 2026-01-28 04:05:13 +00:00
Class BotApi transformed according to PIMPL idiom.
This commit is contained in:
parent
ce87968bbc
commit
e8e7f9b5bd
2 changed files with 95 additions and 68 deletions
|
|
@ -2,6 +2,7 @@
|
|||
#define TELEBOTXX_BOTAPI_H
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace telebotxx
|
||||
{
|
||||
|
|
@ -11,6 +12,8 @@ namespace telebotxx
|
|||
/// \param [in] token bot's secret token
|
||||
BotApi(const std::string& token);
|
||||
|
||||
~BotApi();
|
||||
|
||||
/// \brief Send text message
|
||||
/// \param [in] chat chat identifier
|
||||
/// \param [in] text message text
|
||||
|
|
@ -24,8 +27,8 @@ namespace telebotxx
|
|||
|
||||
|
||||
private:
|
||||
std::string token_;
|
||||
std::string telegramMainUrl_;
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@
|
|||
|
||||
using namespace telebotxx;
|
||||
|
||||
BotApi::BotApi(const std::string& token)
|
||||
class BotApi::Impl
|
||||
{
|
||||
public:
|
||||
Impl(const std::string& token)
|
||||
: token_(token)
|
||||
{
|
||||
telegramMainUrl_ = "https://api.telegram.org/bot" + token_;
|
||||
|
|
@ -18,7 +21,7 @@ BotApi::BotApi(const std::string& token)
|
|||
/// \todo run getMe command to check token
|
||||
}
|
||||
|
||||
void BotApi::sendMessage(const std::string &chat, const std::string &text)
|
||||
void sendMessage(const std::string& chat, const std::string& text)
|
||||
{
|
||||
// Construct JSON body and istream
|
||||
using namespace rapidjson;
|
||||
|
|
@ -60,7 +63,7 @@ void BotApi::sendMessage(const std::string &chat, const std::string &text)
|
|||
request.perform();
|
||||
}
|
||||
|
||||
void BotApi::sendPhoto(const std::string& chat, const std::istream& file, const std::string& caption)
|
||||
void sendPhoto(const std::string& chat, const std::istream& file, const std::string& caption)
|
||||
{
|
||||
// Construct HTTP request
|
||||
curlpp::Easy request;
|
||||
|
|
@ -86,3 +89,24 @@ void BotApi::sendPhoto(const std::string& chat, const std::istream& file, const
|
|||
}
|
||||
|
||||
|
||||
private:
|
||||
std::string token_;
|
||||
std::string telegramMainUrl_;
|
||||
};
|
||||
|
||||
BotApi::BotApi(const std::string& token)
|
||||
: impl_(std::make_unique<Impl>(token))
|
||||
{
|
||||
}
|
||||
|
||||
BotApi::~BotApi() = default;
|
||||
|
||||
void BotApi::sendMessage(const std::string& chat, const std::string& text)
|
||||
{
|
||||
return impl_->sendMessage(chat, text);
|
||||
}
|
||||
|
||||
void BotApi::sendPhoto(const std::string& chat, const std::istream& file, const std::string& caption)
|
||||
{
|
||||
return impl_->sendPhoto(chat, file, caption);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue