Source code reformated.

This commit is contained in:
Kirill Kirilenko 2017-02-15 20:22:18 +03:00
parent 81bb25f4fe
commit 592751a50c
23 changed files with 1118 additions and 1069 deletions

View file

@ -6,212 +6,213 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
namespace telebotxx namespace telebotxx {
class Attachment
{ {
class Attachment public:
enum class Type
{ {
public: Audio,
enum class Type Document,
{ Game,
Audio, PhotoSizeArray,
Document, Sticker,
Game, Video,
PhotoSizeArray, Voice,
Sticker, Contact,
Video, Location,
Voice, Venue
Contact,
Location,
Venue
};
Attachment(Type type);
Attachment(const Attachment&);
Attachment(Attachment&&);
virtual ~Attachment() = 0;
Type getType() const;
void swap(Attachment& other) noexcept;
private:
Type attachmentType_;
}; };
using AttachmentPtr = std::shared_ptr<Attachment>; Attachment(Type type);
Attachment(const Attachment&);
Attachment(Attachment&&);
virtual ~Attachment() = 0;
class PhotoSize Type getType() const;
{
public:
PhotoSize();
PhotoSize(const PhotoSize&);
PhotoSize(PhotoSize&&);
~PhotoSize();
const std::string& getFileId() const; void swap(Attachment& other) noexcept;
void setFileId(const std::string& fileId);
int getWidth() const; private:
void setWidth(int width); Type attachmentType_;
};
int getHeight() const; using AttachmentPtr = std::shared_ptr<Attachment>;
void setHeight(int height);
int getFileSize() const; class PhotoSize
void setFileSize(int fileSize); {
public:
PhotoSize();
PhotoSize(const PhotoSize&);
PhotoSize(PhotoSize&&);
~PhotoSize();
void swap(PhotoSize& other) noexcept; const std::string& getFileId() const;
void setFileId(const std::string& fileId);
const PhotoSize& operator=(PhotoSize other) noexcept; int getWidth() const;
void setWidth(int width);
private: int getHeight() const;
std::string fileId_; void setHeight(int height);
int width_;
int height_;
int fileSize_;
};
using PhotoSizePtr = std::shared_ptr<PhotoSize>; int getFileSize() const;
void setFileSize(int fileSize);
class PhotoSizeArray : public Attachment void swap(PhotoSize& other) noexcept;
{
public:
PhotoSizeArray();
PhotoSizeArray(const PhotoSizeArray&);
PhotoSizeArray(PhotoSizeArray&&);
~PhotoSizeArray();
const std::vector<PhotoSize>& getArray() const; const PhotoSize& operator=(PhotoSize other) noexcept;
void setArray(const std::vector<PhotoSize>& array);
void swap(PhotoSizeArray& other) noexcept; private:
std::string fileId_;
int width_;
int height_;
int fileSize_;
};
const PhotoSizeArray& operator=(PhotoSizeArray other) noexcept; using PhotoSizePtr = std::shared_ptr<PhotoSize>;
private: class PhotoSizeArray : public Attachment
std::vector<PhotoSize> array_; {
}; public:
PhotoSizeArray();
PhotoSizeArray(const PhotoSizeArray&);
PhotoSizeArray(PhotoSizeArray&&);
~PhotoSizeArray();
using PhotoSizeArrayPtr = std::shared_ptr<PhotoSizeArray>; const std::vector<PhotoSize>& getArray() const;
void setArray(const std::vector<PhotoSize>& array);
class Audio : public Attachment void swap(PhotoSizeArray& other) noexcept;
{
public:
Audio();
Audio(const Audio&);
Audio(Audio&&);
~Audio();
const std::string& getFileId() const; const PhotoSizeArray& operator=(PhotoSizeArray other) noexcept;
void setFileId(const std::string& fileId);
int getDuration() const; private:
void setDuration(int duration); std::vector<PhotoSize> array_;
};
const std::string& getPerformer() const; using PhotoSizeArrayPtr = std::shared_ptr<PhotoSizeArray>;
void setPerformer(const std::string& performer);
const std::string& getTitle() const; class Audio : public Attachment
void setTitle(const std::string& title); {
public:
Audio();
Audio(const Audio&);
Audio(Audio&&);
~Audio();
const std::string& getMimeType() const; const std::string& getFileId() const;
void setMimeType(const std::string& mimeType); void setFileId(const std::string& fileId);
int getFileSize() const; int getDuration() const;
void setFileSize(int fileSize); void setDuration(int duration);
void swap(Audio& other) noexcept; const std::string& getPerformer() const;
void setPerformer(const std::string& performer);
const Audio& operator=(Audio other) noexcept; const std::string& getTitle() const;
void setTitle(const std::string& title);
private: const std::string& getMimeType() const;
std::string fileId_; void setMimeType(const std::string& mimeType);
int duration_;
std::string performer_;
std::string title_;
std::string mimeType_;
int fileSize_;
};
class Document : public Attachment int getFileSize() const;
{ void setFileSize(int fileSize);
public:
Document();
Document(const Document&);
Document(Document&&);
~Document();
const std::string& getFileId() const; void swap(Audio& other) noexcept;
void setFileId(const std::string& fileId);
const PhotoSizePtr getThumb() const; const Audio& operator=(Audio other) noexcept;
void setThumb(const PhotoSizePtr& thumb);
const std::string& getFileName() const; private:
void setFileName(const std::string& fileName); std::string fileId_;
int duration_;
std::string performer_;
std::string title_;
std::string mimeType_;
int fileSize_;
};
const std::string& getMimeType() const; class Document : public Attachment
void setMimeType(const std::string& mimeType); {
public:
Document();
Document(const Document&);
Document(Document&&);
~Document();
int getFileSize() const; const std::string& getFileId() const;
void setFileSize(int fileSize); void setFileId(const std::string& fileId);
void swap(Document& other) noexcept; const PhotoSizePtr getThumb() const;
void setThumb(const PhotoSizePtr& thumb);
const Document& operator=(Document other) noexcept; const std::string& getFileName() const;
void setFileName(const std::string& fileName);
private: const std::string& getMimeType() const;
std::string fileId_; void setMimeType(const std::string& mimeType);
PhotoSizePtr thumb_;
std::string fileName_;
std::string mimeType_;
int fileSize_;
};
class Sticker : public Attachment int getFileSize() const;
{ void setFileSize(int fileSize);
public:
Sticker();
Sticker(const Sticker&);
Sticker(Sticker&&);
~Sticker();
const std::string& getFileId() const; void swap(Document& other) noexcept;
void setFileId(const std::string& fileId);
int getWidth() const; const Document& operator=(Document other) noexcept;
void setWidth(int width);
int getHeight() const; private:
void setHeight(int height); std::string fileId_;
PhotoSizePtr thumb_;
std::string fileName_;
std::string mimeType_;
int fileSize_;
};
const PhotoSizePtr getThumb() const; class Sticker : public Attachment
void setThumb(const PhotoSizePtr& thumb); {
public:
Sticker();
Sticker(const Sticker&);
Sticker(Sticker&&);
~Sticker();
const std::string& getEmoji() const; const std::string& getFileId() const;
void setEmoji(const std::string& emoji); void setFileId(const std::string& fileId);
int getFileSize() const; int getWidth() const;
void setFileSize(int fileSize); void setWidth(int width);
void swap(Sticker& other) noexcept; int getHeight() const;
void setHeight(int height);
const Sticker& operator=(Sticker other) noexcept; const PhotoSizePtr getThumb() const;
void setThumb(const PhotoSizePtr& thumb);
private: const std::string& getEmoji() const;
std::string fileId_; void setEmoji(const std::string& emoji);
int width_;
int height_; int getFileSize() const;
PhotoSizePtr thumb_; void setFileSize(int fileSize);
std::string emoji_;
int fileSize_; void swap(Sticker& other) noexcept;
};
const Sticker& operator=(Sticker other) noexcept;
private:
std::string fileId_;
int width_;
int height_;
PhotoSizePtr thumb_;
std::string emoji_;
int fileSize_;
};
void swap(PhotoSize& lhs, PhotoSize& rhs);
void swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs);
void swap(Audio& lhs, Audio& rhs);
void swap(Document& lhs, Document& rhs);
void swap(Sticker& lhs, Sticker& rhs);
void swap(PhotoSize& lhs, PhotoSize& rhs);
void swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs);
void swap(Audio& lhs, Audio& rhs);
void swap(Document& lhs, Document& rhs);
void swap(Sticker& lhs, Sticker& rhs);
} }
#endif // TELEBOTXX_ATTACHMENT_HPP #endif // TELEBOTXX_ATTACHMENT_HPP

View file

@ -1,5 +1,5 @@
#ifndef TELEBOTXX_BOTAPI_H #ifndef TELEBOTXX_BOTAPI_HPP
#define TELEBOTXX_BOTAPI_H #define TELEBOTXX_BOTAPI_HPP
#include "User.hpp" #include "User.hpp"
#include "Message.hpp" #include "Message.hpp"
@ -10,85 +10,86 @@
#include <string> #include <string>
#include <memory> #include <memory>
namespace telebotxx namespace telebotxx {
template <typename RequestType, typename T>
void setRequestOption(RequestType& request, T t)
{ {
template <typename RequestType, typename T> request.setOption(t);
void setRequestOption(RequestType& request, T t)
{
request.setOption(t);
}
template <typename RequestType, typename T, typename... Ts>
void setRequestOption(RequestType& request, T&& t, Ts&&... ts)
{
setRequestOption(request, std::forward<T>(t));
setRequestOption(request, std::forward<Ts>(ts)...);
};
class BotApi
{
public:
/// \param [in] token bot's secret token
BotApi(const std::string& token);
~BotApi();
/// \brief Get basic information about the bot
/// \return User object with information about the bot
User getMe();
/// \brief Send text message
/// \param chatId chat identifier
/// \param text text
/// \return Message object, recieved from the server
Message sendMessage(ChatId&& chatId, Text&& text);
/// \brief Send text message
/// \param chatId chat identifier
/// \param text text
/// \param args parameters
/// \return Message object, recieved from the server
template<typename... Ts>
Message sendMessage(ChatId&& chatId, Text&& text, Ts&&... args)
{
SendMessageRequest request(getTelegramMainUrl(), std::forward<ChatId>(chatId), std::forward<Text>(text));
setRequestOption(request, std::forward<Ts>(args)...);
return request.execute();
}
/// \brief Send image
/// \param [in] chatId chat identifier
/// \param [in] photo photo
/// \return Message object, recieved from the server
Message sendPhoto(ChatId&& chatId, Photo&& photo);
/// \brief Send image
/// \param [in] chatId chat identifier
/// \param [in] photo photo
/// \param [in] args parameters
/// \return Message object, recieved from the server
template<typename... Ts>
Message sendPhoto(ChatId&& chatId, Photo&& photo, Ts&&... args)
{
SendPhotoRequest request(getTelegramMainUrl(), std::forward<ChatId>(chatId), std::forward<Photo>(photo));
setRequestOption(request, std::forward<Ts>(args)...);
return request.execute();
}
/// \brief Get updates using long polling
/// \param offset identifier of the first update to be returned
/// \param limit maximum number of updates to be retrieved
/// \param timeout timeout in seconds for long polling
/// \return Updates (vector of Update)
Updates getUpdates(int offset = 0, unsigned short limit = 0, unsigned timeout = 0);
private:
std::string getTelegramMainUrl() const;
class Impl;
std::unique_ptr<Impl> impl_;
};
} }
#endif // TELEBOTXX_BOTAPI_H template <typename RequestType, typename T, typename... Ts>
void setRequestOption(RequestType& request, T&& t, Ts&&... ts)
{
setRequestOption(request, std::forward<T>(t));
setRequestOption(request, std::forward<Ts>(ts)...);
};
class BotApi
{
public:
/// \param [in] token bot's secret token
BotApi(const std::string& token);
~BotApi();
/// \brief Get basic information about the bot
/// \return User object with information about the bot
User getMe();
/// \brief Send text message
/// \param chatId chat identifier
/// \param text text
/// \return Message object, recieved from the server
Message sendMessage(ChatId&& chatId, Text&& text);
/// \brief Send text message
/// \param chatId chat identifier
/// \param text text
/// \param args parameters
/// \return Message object, recieved from the server
template <typename... Ts>
Message sendMessage(ChatId&& chatId, Text&& text, Ts&&... args)
{
SendMessageRequest request(getTelegramMainUrl(), std::forward<ChatId>(chatId), std::forward<Text>(text));
setRequestOption(request, std::forward<Ts>(args)...);
return request.execute();
}
/// \brief Send image
/// \param [in] chatId chat identifier
/// \param [in] photo photo
/// \return Message object, recieved from the server
Message sendPhoto(ChatId&& chatId, Photo&& photo);
/// \brief Send image
/// \param [in] chatId chat identifier
/// \param [in] photo photo
/// \param [in] args parameters
/// \return Message object, recieved from the server
template <typename... Ts>
Message sendPhoto(ChatId&& chatId, Photo&& photo, Ts&&... args)
{
SendPhotoRequest request(getTelegramMainUrl(), std::forward<ChatId>(chatId), std::forward<Photo>(photo));
setRequestOption(request, std::forward<Ts>(args)...);
return request.execute();
}
/// \brief Get updates using long polling
/// \param offset identifier of the first update to be returned
/// \param limit maximum number of updates to be retrieved
/// \param timeout timeout in seconds for long polling
/// \return Updates (vector of Update)
Updates getUpdates(int offset = 0, unsigned short limit = 0, unsigned timeout = 0);
private:
std::string getTelegramMainUrl() const;
class Impl;
std::unique_ptr<Impl> impl_;
};
}
#endif // TELEBOTXX_BOTAPI_HPP

View file

@ -5,64 +5,65 @@
#include <memory> #include <memory>
#include <cstdint> #include <cstdint>
namespace telebotxx namespace telebotxx {
class Chat
{ {
class Chat public:
enum class Type
{ {
public: Private,
enum class Type Group,
{ Supergroup,
Private, Channel
Group,
Supergroup,
Channel
};
Chat();
Chat(const Chat&);
Chat(Chat&&);
~Chat();
std::int64_t getId() const;
void setId(std::int64_t id);
Type getType() const;
void setType(Type type);
const std::string& getTitle() const;
void setTitle(const std::string& title);
const std::string& getUsername() const;
void setUsername(const std::string& username);
const std::string& getFirstName() const;
void setFirstName(const std::string& firstName);
const std::string& getLastName() const;
void setLastName(const std::string& lastName);
bool isAllAdmins() const;
void setAllAdmins(bool allAdmins);
void swap(Chat& other) noexcept;
const Chat& operator=(Chat other) noexcept;
private:
std::int64_t id_;
Type type_;
std::string title_;
std::string username_;
std::string firstName_;
std::string lastName_;
bool allAdmins_;
}; };
using ChatPtr = std::shared_ptr<Chat>; Chat();
Chat(const Chat&);
Chat(Chat&&);
~Chat();
void swap(Chat& lhs, Chat& rhs); std::int64_t getId() const;
void setId(std::int64_t id);
Type getType() const;
void setType(Type type);
const std::string& getTitle() const;
void setTitle(const std::string& title);
const std::string& getUsername() const;
void setUsername(const std::string& username);
const std::string& getFirstName() const;
void setFirstName(const std::string& firstName);
const std::string& getLastName() const;
void setLastName(const std::string& lastName);
bool isAllAdmins() const;
void setAllAdmins(bool allAdmins);
void swap(Chat& other) noexcept;
const Chat& operator=(Chat other) noexcept;
private:
std::int64_t id_;
Type type_;
std::string title_;
std::string username_;
std::string firstName_;
std::string lastName_;
bool allAdmins_;
};
using ChatPtr = std::shared_ptr<Chat>;
void swap(Chat& lhs, Chat& rhs);
Chat::Type chatTypeFromString(const std::string& str);
Chat::Type chatTypeFromString(const std::string& str);
} }
#endif // TELEBOTXX_CHAT_HPP #endif // TELEBOTXX_CHAT_HPP

View file

@ -3,33 +3,33 @@
#include <stdexcept> #include <stdexcept>
namespace telebotxx namespace telebotxx {
class ParseError : public std::invalid_argument
{ {
class ParseError : public std::invalid_argument public:
ParseError(const std::string& message)
: std::invalid_argument(message)
{ {
public: }
ParseError(const std::string& message) };
: std::invalid_argument(message)
{
}
};
class ApiError : public std::runtime_error class ApiError : public std::runtime_error
{
public:
ApiError(int code, const std::string& message)
: std::runtime_error(message), code_(code)
{ {
public: }
ApiError(int code, const std::string& message)
: std::runtime_error(message), code_(code)
{
}
int getCode() const int getCode() const
{ {
return code_; return code_;
} }
protected: protected:
int code_; int code_;
}; };
} }

View file

@ -1,12 +1,13 @@
#ifndef TELEBOTXX_LOGGING_HPP #ifndef TELEBOTXX_LOGGING_HPP
#define TELEBOTXX_LOGGING_HPP #define TELEBOTXX_LOGGING_HPP
namespace telebotxx namespace telebotxx {
{
extern bool debugMode; extern bool debugMode;
/// \brief Enable/disable debug output
void setDebugMode(bool enabled);
/// \brief Enable/disable debug output
void setDebugMode(bool enabled);
} }
#endif // TELEBOTXX_LOGGING_HPP #endif // TELEBOTXX_LOGGING_HPP

View file

@ -9,177 +9,178 @@
#include <ctime> #include <ctime>
#include <memory> #include <memory>
namespace telebotxx namespace telebotxx {
class MessageEntity
{ {
class MessageEntity public:
enum class Type
{ {
public: Mention,
enum class Type Hashtag,
{ BotCommand,
Mention, Url,
Hashtag, Email,
BotCommand, Bold,
Url, Italic,
Email, Code,
Bold, Pre,
Italic, TextLink,
Code, TextMention
Pre,
TextLink,
TextMention
};
MessageEntity();
MessageEntity(const MessageEntity&);
MessageEntity(MessageEntity&&);
~MessageEntity();
Type getType() const;
void setType(Type type);
int getOffset() const;
void setOffset(int offset);
size_t getLength() const;
void setLength(size_t length);
const std::string& getUrl() const;
void setUrl(const std::string& url);
const User& getUser() const;
void setUser(const User& user);
void swap(MessageEntity& other) noexcept;
const MessageEntity& operator=(MessageEntity other);
private:
Type type_;
int offset_;
std::size_t length_;
std::string url_;
User user_;
}; };
MessageEntity::Type messageEntityTypeFromString(const std::string& str); MessageEntity();
MessageEntity(const MessageEntity&);
MessageEntity(MessageEntity&&);
~MessageEntity();
using MessageEntities = std::vector<MessageEntity>; Type getType() const;
void setType(Type type);
class Message; int getOffset() const;
using MessagePtr = std::shared_ptr<Message>; void setOffset(int offset);
class Message size_t getLength() const;
{ void setLength(size_t length);
public:
Message();
Message(const Message&);
Message(Message&&);
~Message();
int getId() const; const std::string& getUrl() const;
void setId(int id); void setUrl(const std::string& url);
const UserPtr getFrom() const; const User& getUser() const;
void setFrom(UserPtr from); void setUser(const User& user);
time_t getDate() const; void swap(MessageEntity& other) noexcept;
void setDate(time_t date);
const Chat& getChat() const; const MessageEntity& operator=(MessageEntity other);
void setChat(const Chat& chat);
const UserPtr getForwardFrom() const; private:
void setForwardFrom(UserPtr forwardFrom); Type type_;
int offset_;
std::size_t length_;
std::string url_;
User user_;
};
const ChatPtr getForwardFromChat() const; MessageEntity::Type messageEntityTypeFromString(const std::string& str);
void setForwardFromChat(ChatPtr forwardFromChat);
time_t getForwardDate() const; using MessageEntities = std::vector<MessageEntity>;
void setForwardDate(time_t forwardDate);
const MessagePtr getReplyToMessage() const; class Message;
void setReplyToMessage(MessagePtr replyToMessage); using MessagePtr = std::shared_ptr<Message>;
time_t getEditDate() const; class Message
void setEditDate(time_t editDate); {
public:
Message();
Message(const Message&);
Message(Message&&);
~Message();
const std::string& getText() const; int getId() const;
void setText(const std::string& text); void setId(int id);
const MessageEntities& getEntities() const; const UserPtr getFrom() const;
void setEntities(MessageEntities&& entities); void setFrom(UserPtr from);
const AttachmentPtr getAttachment() const; time_t getDate() const;
void setAttachment(AttachmentPtr attachment); void setDate(time_t date);
const std::string& getCaption() const; const Chat& getChat() const;
void setCaption(const std::string& caption); void setChat(const Chat& chat);
const UserPtr getNewChatMember() const; const UserPtr getForwardFrom() const;
void setNewChatMember(UserPtr newChatMember); void setForwardFrom(UserPtr forwardFrom);
const UserPtr getLeftChatMember() const; const ChatPtr getForwardFromChat() const;
void setLeftChatMember(UserPtr leftChatMember); void setForwardFromChat(ChatPtr forwardFromChat);
const std::string& getNewChatTitle() const; time_t getForwardDate() const;
void setNewChatTitle(const std::string& newChatTitle); void setForwardDate(time_t forwardDate);
const PhotoSizeArrayPtr getNewChatPhoto() const; const MessagePtr getReplyToMessage() const;
void setNewChatPhoto(PhotoSizeArrayPtr newChatPhoto); void setReplyToMessage(MessagePtr replyToMessage);
bool isDeleteChatPhoto() const; time_t getEditDate() const;
void setDeleteChatPhoto(bool deleteChatPhoto); void setEditDate(time_t editDate);
bool isGroupChatCreated() const; const std::string& getText() const;
void setGroupChatCreated(bool groupChatCreated); void setText(const std::string& text);
bool isSuperGroupChatCreated() const; const MessageEntities& getEntities() const;
void setSuperGroupChatCreated(bool superGroupChatCreated); void setEntities(MessageEntities&& entities);
bool isChannelChatCreated() const; const AttachmentPtr getAttachment() const;
void setChannelChatCreated(bool channelChatCreated); void setAttachment(AttachmentPtr attachment);
std::int64_t getMigrateToChatId() const; const std::string& getCaption() const;
void setMigrateToChatId(std::int64_t migrateToChatId); void setCaption(const std::string& caption);
std::int64_t getMigrateFromChatId() const; const UserPtr getNewChatMember() const;
void setMigrateFromChatId(std::int64_t migrateFromChatId); void setNewChatMember(UserPtr newChatMember);
const MessagePtr getPinnedMessage() const; const UserPtr getLeftChatMember() const;
void setPinnedMessage(MessagePtr pinnedMessage); void setLeftChatMember(UserPtr leftChatMember);
void swap(Message& other) noexcept; const std::string& getNewChatTitle() const;
void setNewChatTitle(const std::string& newChatTitle);
const Message& operator=(Message other) noexcept; const PhotoSizeArrayPtr getNewChatPhoto() const;
void setNewChatPhoto(PhotoSizeArrayPtr newChatPhoto);
private: bool isDeleteChatPhoto() const;
int id_; void setDeleteChatPhoto(bool deleteChatPhoto);
UserPtr from_;
std::time_t date_; bool isGroupChatCreated() const;
Chat chat_; void setGroupChatCreated(bool groupChatCreated);
UserPtr forwardFrom_;
ChatPtr forwardFromChat_; bool isSuperGroupChatCreated() const;
std::time_t forwardDate_; void setSuperGroupChatCreated(bool superGroupChatCreated);
MessagePtr replyToMessage_;
std::time_t editDate_; bool isChannelChatCreated() const;
std::string text_; void setChannelChatCreated(bool channelChatCreated);
MessageEntities entities_;
AttachmentPtr attachment_; std::int64_t getMigrateToChatId() const;
std::string caption_; void setMigrateToChatId(std::int64_t migrateToChatId);
UserPtr newChatMember_;
UserPtr leftChatMember_; std::int64_t getMigrateFromChatId() const;
std::string newChatTitle_; void setMigrateFromChatId(std::int64_t migrateFromChatId);
PhotoSizeArrayPtr newChatPhoto_;
bool deleteChatPhoto_; const MessagePtr getPinnedMessage() const;
bool groupChatCreated_; void setPinnedMessage(MessagePtr pinnedMessage);
bool superGroupChatCreated_;
bool channelChatCreated_; void swap(Message& other) noexcept;
std::int64_t migrateToChatId_;
std::int64_t migrateFromChatId_; const Message& operator=(Message other) noexcept;
MessagePtr pinnedMessage_;
}; private:
int id_;
UserPtr from_;
std::time_t date_;
Chat chat_;
UserPtr forwardFrom_;
ChatPtr forwardFromChat_;
std::time_t forwardDate_;
MessagePtr replyToMessage_;
std::time_t editDate_;
std::string text_;
MessageEntities entities_;
AttachmentPtr attachment_;
std::string caption_;
UserPtr newChatMember_;
UserPtr leftChatMember_;
std::string newChatTitle_;
PhotoSizeArrayPtr newChatPhoto_;
bool deleteChatPhoto_;
bool groupChatCreated_;
bool superGroupChatCreated_;
bool channelChatCreated_;
std::int64_t migrateToChatId_;
std::int64_t migrateFromChatId_;
MessagePtr pinnedMessage_;
};
void swap(Message& lhs, Message& rhs);
void swap(Message& lhs, Message& rhs);
} }
#endif // TELEBOTXX_MESSAGE_HPP #endif // TELEBOTXX_MESSAGE_HPP

View file

@ -4,128 +4,129 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace telebotxx namespace telebotxx {
class ChatId
{ {
class ChatId public:
ChatId(int);
ChatId(const std::string&);
ChatId(const ChatId&);
ChatId(ChatId&&);
~ChatId();
enum class Type { Id, Username };
Type getType() const;
const int getId() const;
const std::string getUsername() const;
private:
Type type_;
union
{ {
public:
ChatId(int);
ChatId(const std::string&);
ChatId(const ChatId&);
ChatId(ChatId&&);
~ChatId();
enum class Type { Id, Username };
Type getType() const;
const int getId() const;
const std::string getUsername() const;
private:
Type type_;
union
{
int id_;
std::string username_;
};
};
using Text = std::string;
using Caption = std::string;
enum class ParseMode
{
Plain,
Markdown,
Html
};
class DisableWebPagePreview
{
public:
DisableWebPagePreview(bool disabled = true);
bool value() const;
private:
bool disable_;
};
class DisableNotification
{
public:
DisableNotification(bool disabled = true);
bool value() const;
private:
bool disable_;
};
class ReplyTo
{
public:
explicit ReplyTo(int id);
int value() const;
private:
int id_; int id_;
std::string username_;
}; };
};
class Buffer using Text = std::string;
using Caption = std::string;
enum class ParseMode
{
Plain,
Markdown,
Html
};
class DisableWebPagePreview
{
public:
DisableWebPagePreview(bool disabled = true);
bool value() const;
private:
bool disable_;
};
class DisableNotification
{
public:
DisableNotification(bool disabled = true);
bool value() const;
private:
bool disable_;
};
class ReplyTo
{
public:
explicit ReplyTo(int id);
int value() const;
private:
int id_;
};
class Buffer
{
public:
Buffer(const char *buffer, std::size_t size, const std::string& filename);
explicit Buffer(const std::vector<char>& data, const std::string& filename);
const char *data() const;
const std::size_t size() const;
const std::string filename() const;
private:
const char *data_;
std::size_t size_;
std::string filename_;
};
class File
{
public:
explicit File(const std::string& filename);
const std::string& getFilename() const;
private:
std::string filename_;
};
class Url
{
public:
explicit Url(const std::string& url);
const std::string& getUrl() const;
private:
std::string url_;
};
class Photo
{
public:
explicit Photo(int id);
explicit Photo(const Buffer&);
explicit Photo(const File&);
explicit Photo(const Url&);
Photo(const Photo&);
Photo(Photo&&);
~Photo();
enum class Type { Id, Buffer, File, Url };
Type getType() const;
int getId() const;
const Buffer& getBuffer() const;
const File& getFile() const;
const Url& getUrl() const;
private:
Type type_;
union
{ {
public: int id_;
Buffer(const char* buffer, std::size_t size, const std::string& filename); Buffer buffer_;
explicit Buffer(const std::vector<char>& data, const std::string& filename); File file_;
const char* data() const; Url url_;
const std::size_t size() const;
const std::string filename() const;
private:
const char* data_;
std::size_t size_;
std::string filename_;
}; };
};
class File
{
public:
explicit File(const std::string& filename);
const std::string& getFilename() const;
private:
std::string filename_;
};
class Url
{
public:
explicit Url(const std::string& url);
const std::string& getUrl() const;
private:
std::string url_;
};
class Photo
{
public:
explicit Photo(int id);
explicit Photo(const Buffer&);
explicit Photo(const File&);
explicit Photo(const Url&);
Photo(const Photo&);
Photo(Photo&&);
~Photo();
enum class Type { Id, Buffer, File, Url};
Type getType() const;
int getId() const;
const Buffer& getBuffer() const;
const File& getFile() const;
const Url& getUrl() const;
private:
Type type_;
union
{
int id_;
Buffer buffer_;
File file_;
Url url_;
};
};
} }
#endif // TELEBOTXX_REQUEST_OPTIONS_HPP #endif // TELEBOTXX_REQUEST_OPTIONS_HPP

View file

@ -4,35 +4,34 @@
#include <telebotxx/RequestOptions.hpp> #include <telebotxx/RequestOptions.hpp>
#include <telebotxx/Message.hpp> #include <telebotxx/Message.hpp>
#include <boost/optional.hpp>
#include <string> #include <string>
#include <memory> #include <memory>
namespace telebotxx namespace telebotxx {
class SendMessageRequest
{ {
class SendMessageRequest public:
{ SendMessageRequest(const std::string& telegramMainUrl, const ChatId& chat, const Text& text);
public: ~SendMessageRequest();
SendMessageRequest(const std::string& telegramMainUrl, const ChatId& chat, const Text& text);
~SendMessageRequest();
void setParseMode(ParseMode mode); void setParseMode(ParseMode mode);
void setDisableWebPagePreview(const DisableWebPagePreview& disableWebPagePreview); void setDisableWebPagePreview(const DisableWebPagePreview& disableWebPagePreview);
void setDisableNotification(const DisableNotification& disableNotification); void setDisableNotification(const DisableNotification& disableNotification);
void setReplyToMessageId(const ReplyTo& replyToMessageId); void setReplyToMessageId(const ReplyTo& replyToMessageId);
void setOption(ParseMode mode); void setOption(ParseMode mode);
void setOption(const DisableWebPagePreview& disableWebPagePreview); void setOption(const DisableWebPagePreview& disableWebPagePreview);
void setOption(const DisableNotification& disableNotification); void setOption(const DisableNotification& disableNotification);
void setOption(const ReplyTo& replyToMessageId); void setOption(const ReplyTo& replyToMessageId);
Message execute(); Message execute();
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
} }
#endif // TELEBOTXX_SEND_MESSAGE_REQUEST_HPP #endif // TELEBOTXX_SEND_MESSAGE_REQUEST_HPP

View file

@ -4,32 +4,32 @@
#include <telebotxx/RequestOptions.hpp> #include <telebotxx/RequestOptions.hpp>
#include <telebotxx/Message.hpp> #include <telebotxx/Message.hpp>
#include <boost/optional.hpp>
#include <string> #include <string>
#include <memory> #include <memory>
namespace telebotxx namespace telebotxx {
class SendPhotoRequest
{ {
class SendPhotoRequest public:
{ SendPhotoRequest(const std::string& telegramMainUrl, const ChatId& chat, const Photo& photo);
public: ~SendPhotoRequest();
SendPhotoRequest(const std::string& telegramMainUrl, const ChatId& chat, const Photo& photo);
~SendPhotoRequest();
void setCaption(const Caption& caption); void setCaption(const Caption& caption);
void setDisableNotification(const DisableNotification& disableNotification); void setDisableNotification(const DisableNotification& disableNotification);
void setReplyToMessageId(const ReplyTo& replyToMessageId); void setReplyToMessageId(const ReplyTo& replyToMessageId);
void setOption(const Caption& caption);
void setOption(const DisableNotification& disableNotification);
void setOption(const ReplyTo& replyToMessageId);
Message execute(); void setOption(const Caption& caption);
void setOption(const DisableNotification& disableNotification);
void setOption(const ReplyTo& replyToMessageId);
Message execute();
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
} }
#endif // TELEBOTXX_SEND_PHOTO_REQUEST_HPP #endif // TELEBOTXX_SEND_PHOTO_REQUEST_HPP

View file

@ -6,68 +6,68 @@
#include <vector> #include <vector>
#include <memory> #include <memory>
namespace telebotxx namespace telebotxx {
class Update
{ {
class Update public:
enum class Type
{ {
public: Message,
enum class Type EditedMessage,
{ InlineQuery,
Message, ChosenInlineResult,
EditedMessage, CallbackQuery
InlineQuery,
ChosenInlineResult,
CallbackQuery
};
Update(int id, Type type);
Update(const Update&);
Update(Update&&);
virtual ~Update() = 0;
int getId() const;
Type getType() const;
void swap(Update& other) noexcept;
private:
int id_;
Type updateType_;
}; };
using UpdatePtr = std::shared_ptr<Update>; Update(int id, Type type);
using Updates = std::vector<UpdatePtr>; Update(const Update&);
Update(Update&&);
virtual ~Update() = 0;
class MessageUpdate : public Update int getId() const;
{ Type getType() const;
public:
MessageUpdate(int id, const Message& message);
MessageUpdate(const MessageUpdate&);
MessageUpdate(MessageUpdate&&);
~MessageUpdate();
const Message& getMessage() const; void swap(Update& other) noexcept;
void swap(MessageUpdate& other) noexcept; private:
int id_;
Type updateType_;
};
const MessageUpdate& operator=(MessageUpdate other); using UpdatePtr = std::shared_ptr<Update>;
using Updates = std::vector<UpdatePtr>;
private: class MessageUpdate : public Update
Message message_; {
}; public:
MessageUpdate(int id, const Message& message);
MessageUpdate(const MessageUpdate&);
MessageUpdate(MessageUpdate&&);
~MessageUpdate();
class EditedMessageUpdate: public MessageUpdate const Message& getMessage() const;
{
public:
EditedMessageUpdate(int id, const Message& message);
EditedMessageUpdate(const EditedMessageUpdate&);
EditedMessageUpdate(EditedMessageUpdate&&);
~EditedMessageUpdate();
void swap(EditedMessageUpdate& other) noexcept; void swap(MessageUpdate& other) noexcept;
const EditedMessageUpdate& operator=(EditedMessageUpdate other); const MessageUpdate& operator=(MessageUpdate other);
};
private:
Message message_;
};
class EditedMessageUpdate : public MessageUpdate
{
public:
EditedMessageUpdate(int id, const Message& message);
EditedMessageUpdate(const EditedMessageUpdate&);
EditedMessageUpdate(EditedMessageUpdate&&);
~EditedMessageUpdate();
void swap(EditedMessageUpdate& other) noexcept;
const EditedMessageUpdate& operator=(EditedMessageUpdate other);
};
} }

View file

@ -4,57 +4,58 @@
#include <string> #include <string>
#include <memory> #include <memory>
namespace telebotxx namespace telebotxx {
class User
{ {
class User public:
{ User();
public: User(const User&);
User(); User(User&&);
User(const User&); ~User();
User(User&&);
~User();
/// \brief Get id /// \brief Get id
int getId() const; int getId() const;
/// \brief Set id /// \brief Set id
void setId(int id); void setId(int id);
/// \brief Get first name /// \brief Get first name
const std::string& getFirstName() const; const std::string& getFirstName() const;
/// \brief Set first name /// \brief Set first name
void setFirstName(const std::string& firstName); void setFirstName(const std::string& firstName);
/// \brief Get last name /// \brief Get last name
const std::string& getLastName() const; const std::string& getLastName() const;
/// \brief Set last name /// \brief Set last name
void setLastName(const std::string& lastName); void setLastName(const std::string& lastName);
/// \brief Get username /// \brief Get username
const std::string& getUsername() const; const std::string& getUsername() const;
/// \brief Set username /// \brief Set username
void setUsername(const std::string& username); void setUsername(const std::string& username);
/// \brief Get string representation of user /// \brief Get string representation of user
const std::string toString() const; const std::string toString() const;
void swap(User&) noexcept; void swap(User&) noexcept;
const User& operator=(User other); const User& operator=(User other);
private: private:
int id_; int id_;
std::string firstName_; std::string firstName_;
std::string lastName_; std::string lastName_;
std::string username_; std::string username_;
}; };
using UserPtr = std::shared_ptr<User>; using UserPtr = std::shared_ptr<User>;
std::ostream& operator<<(std::ostream& os, const User& user);
std::ostream& operator<<(std::ostream& os, const User& user);
} }
#endif // TELEBOTXX_USER_H #endif // TELEBOTXX_USER_H

View file

@ -1,14 +1,16 @@
#include <telebotxx/Attachment.hpp> #include <telebotxx/Attachment.hpp>
using namespace telebotxx; namespace telebotxx {
Attachment::Attachment(Type type) Attachment::Attachment(Type type)
: attachmentType_(type) : attachmentType_(type)
{ {
} }
Attachment::Attachment(const Attachment&) = default; Attachment::Attachment(const Attachment&) = default;
Attachment::Attachment(Attachment&&) = default; Attachment::Attachment(Attachment&&) = default;
Attachment::~Attachment() = default; Attachment::~Attachment() = default;
Attachment::Type Attachment::getType() const Attachment::Type Attachment::getType() const
@ -24,14 +26,16 @@ void Attachment::swap(Attachment& other) noexcept
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
PhotoSize::PhotoSize() PhotoSize::PhotoSize()
: width_(-1), : width_(-1),
height_(-1), height_(-1),
fileSize_(-1) fileSize_(-1)
{ {
} }
PhotoSize::PhotoSize(const PhotoSize&) = default; PhotoSize::PhotoSize(const PhotoSize&) = default;
PhotoSize::PhotoSize(PhotoSize&&) = default; PhotoSize::PhotoSize(PhotoSize&&) = default;
PhotoSize::~PhotoSize() = default; PhotoSize::~PhotoSize() = default;
const std::string& PhotoSize::getFileId() const const std::string& PhotoSize::getFileId() const
@ -97,7 +101,9 @@ PhotoSizeArray::PhotoSizeArray()
} }
PhotoSizeArray::PhotoSizeArray(const PhotoSizeArray&) = default; PhotoSizeArray::PhotoSizeArray(const PhotoSizeArray&) = default;
PhotoSizeArray::PhotoSizeArray(PhotoSizeArray&&) = default; PhotoSizeArray::PhotoSizeArray(PhotoSizeArray&&) = default;
PhotoSizeArray::~PhotoSizeArray() = default; PhotoSizeArray::~PhotoSizeArray() = default;
const std::vector<PhotoSize>& PhotoSizeArray::getArray() const const std::vector<PhotoSize>& PhotoSizeArray::getArray() const
@ -125,14 +131,16 @@ const PhotoSizeArray& PhotoSizeArray::operator=(PhotoSizeArray other) noexcept
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
Audio::Audio() Audio::Audio()
: Attachment(Type::Audio), : Attachment(Type::Audio),
duration_(-1), duration_(-1),
fileSize_(-1) fileSize_(-1)
{ {
} }
Audio::Audio(const Audio&) = default; Audio::Audio(const Audio&) = default;
Audio::Audio(Audio&&) = default; Audio::Audio(Audio&&) = default;
Audio::~Audio() = default; Audio::~Audio() = default;
const std::string& Audio::getFileId() const const std::string& Audio::getFileId() const
@ -216,13 +224,15 @@ const Audio& Audio::operator=(Audio other) noexcept
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
Document::Document() Document::Document()
: Attachment(Type::Document), : Attachment(Type::Document),
fileSize_(-1) fileSize_(-1)
{ {
} }
Document::Document(const Document&) = default; Document::Document(const Document&) = default;
Document::Document(Document&&) = default; Document::Document(Document&&) = default;
Document::~Document() = default; Document::~Document() = default;
const std::string& Document::getFileId() const const std::string& Document::getFileId() const
@ -295,13 +305,15 @@ const Document& Document::operator=(Document other) noexcept
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
Sticker::Sticker() Sticker::Sticker()
: Attachment(Type::Sticker), : Attachment(Type::Sticker),
fileSize_(-1) fileSize_(-1)
{ {
} }
Sticker::Sticker(const Sticker&) = default; Sticker::Sticker(const Sticker&) = default;
Sticker::Sticker(Sticker&&) = default; Sticker::Sticker(Sticker&&) = default;
Sticker::~Sticker() = default; Sticker::~Sticker() = default;
const std::string& Sticker::getFileId() const const std::string& Sticker::getFileId() const
@ -384,27 +396,29 @@ const Sticker& Sticker::operator=(Sticker other) noexcept
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
void telebotxx::swap(PhotoSize& lhs, PhotoSize& rhs) void swap(PhotoSize& lhs, PhotoSize& rhs)
{ {
lhs.swap(rhs); lhs.swap(rhs);
} }
void telebotxx::swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs) void swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs)
{ {
lhs.swap(rhs); lhs.swap(rhs);
} }
void telebotxx::swap(Audio& lhs, Audio& rhs) void swap(Audio& lhs, Audio& rhs)
{ {
lhs.swap(rhs); lhs.swap(rhs);
} }
void telebotxx::swap(Document& lhs, Document& rhs) void swap(Document& lhs, Document& rhs)
{ {
lhs.swap(rhs); lhs.swap(rhs);
} }
void telebotxx::swap(Sticker& lhs, Sticker& rhs) void swap(Sticker& lhs, Sticker& rhs)
{ {
lhs.swap(rhs); lhs.swap(rhs);
} }
}

View file

@ -10,7 +10,7 @@
#include <cpr/cpr.h> #include <cpr/cpr.h>
using namespace telebotxx; namespace telebotxx {
class BotApi::Impl class BotApi::Impl
{ {
@ -41,7 +41,7 @@ public:
{ {
auto r = cpr::Post(cpr::Url{telegramMainUrl_ + "/sendPhoto"}, auto r = cpr::Post(cpr::Url{telegramMainUrl_ + "/sendPhoto"},
cpr::Multipart{{"chat_id", chat}, cpr::Multipart{{"chat_id", chat},
{"photo", cpr::File{filename}}, {"photo", cpr::File{filename}},
{"caption", caption} {"caption", caption}
} }
); );
@ -181,3 +181,5 @@ std::string BotApi::getTelegramMainUrl() const
{ {
return impl_->getTelegramMainUrl(); return impl_->getTelegramMainUrl();
} }
}

View file

@ -1,7 +1,7 @@
#include <telebotxx/Chat.hpp> #include <telebotxx/Chat.hpp>
#include <stdexcept> #include <stdexcept>
using namespace telebotxx; namespace telebotxx {
Chat::Chat() Chat::Chat()
: id_(-1), : id_(-1),
@ -11,7 +11,9 @@ Chat::Chat()
} }
Chat::Chat(const Chat&) = default; Chat::Chat(const Chat&) = default;
Chat::Chat(Chat&&) = default; Chat::Chat(Chat&&) = default;
Chat::~Chat() = default; Chat::~Chat() = default;
std::int64_t Chat::getId() const std::int64_t Chat::getId() const
@ -102,12 +104,12 @@ const Chat& Chat::operator=(Chat other) noexcept
return *this; return *this;
} }
void telebotxx::swap(Chat& lhs, Chat& rhs) void swap(Chat& lhs, Chat& rhs)
{ {
lhs.swap(rhs); lhs.swap(rhs);
} }
Chat::Type telebotxx::chatTypeFromString(const std::string& str) Chat::Type chatTypeFromString(const std::string& str)
{ {
if (str == "private") if (str == "private")
return Chat::Type::Private; return Chat::Type::Private;
@ -120,3 +122,5 @@ Chat::Type telebotxx::chatTypeFromString(const std::string& str)
else else
throw std::invalid_argument("Unknown chat type"); throw std::invalid_argument("Unknown chat type");
} }
}

View file

@ -3,313 +3,314 @@
#include <cstdint> #include <cstdint>
namespace telebotxx namespace telebotxx {
namespace impl {
template<typename T> bool is(const rapidjson::Value& obj);
template<> bool is<int>(const rapidjson::Value& obj) { return obj.IsInt(); }
template<> bool is<std::int64_t>(const rapidjson::Value& obj) { return obj.IsInt64(); }
template<> bool is<bool>(const rapidjson::Value& obj) { return obj.IsBool(); }
template<> bool is<std::string>(const rapidjson::Value& obj) { return obj.IsString(); }
template<typename T> const T get(const rapidjson::Value& obj);
template<> const int get(const rapidjson::Value& obj) { return obj.GetInt(); }
template<> const std::int64_t get(const rapidjson::Value& obj) { return obj.GetInt64(); }
template<> const bool get(const rapidjson::Value& obj) { return obj.GetBool(); }
template<> const std::string get(const rapidjson::Value& obj) { return obj.GetString(); }
template<typename T> const T null();
template<> const int null() { return 0; }
template<> const std::int64_t null() { return 0; }
template<> const bool null() { return false; }
template<> const std::string null() { return ""; }
}
template<typename T>
const T parse(const rapidjson::Value& obj, const char* name, bool required)
{ {
namespace impl if (obj.HasMember(name))
{ {
template<typename T> bool is(const rapidjson::Value& obj); if (impl::is<T>(obj[name]))
template<> bool is<int>(const rapidjson::Value& obj) { return obj.IsInt(); } return impl::get<T>(obj[name]);
template<> bool is<std::int64_t>(const rapidjson::Value& obj) { return obj.IsInt64(); }
template<> bool is<bool>(const rapidjson::Value& obj) { return obj.IsBool(); }
template<> bool is<std::string>(const rapidjson::Value& obj) { return obj.IsString(); }
template<typename T> const T get(const rapidjson::Value& obj);
template<> const int get(const rapidjson::Value& obj) { return obj.GetInt(); }
template<> const std::int64_t get(const rapidjson::Value& obj) { return obj.GetInt64(); }
template<> const bool get(const rapidjson::Value& obj) { return obj.GetBool(); }
template<> const std::string get(const rapidjson::Value& obj) { return obj.GetString(); }
template<typename T> const T null();
template<> const int null() { return 0; }
template<> const std::int64_t null() { return 0; }
template<> const bool null() { return false; }
template<> const std::string null() { return ""; }
}
template <typename T>
const T parse(const rapidjson::Value& obj, const char* name, bool required)
{
if (obj.HasMember(name))
{
if (impl::is<T>(obj[name]))
return impl::get<T>(obj[name]);
else
throw ParseError(std::string("Field '")+ name + "' has invalid type");
}
else if (required)
throw ParseError(std::string("Field '")+ name + "' not found");
else else
return impl::null<T>(); throw ParseError(std::string("Field '") + name + "' has invalid type");
} }
else if (required)
throw ParseError(std::string("Field '") + name + "' not found");
else
return impl::null<T>();
}
const rapidjson::Value& parseObject(const rapidjson::Value& parent, const char* name, bool required, bool& found) const rapidjson::Value& parseObject(const rapidjson::Value& parent, const char* name, bool required, bool& found)
{
if (parent.HasMember(name))
{ {
if (parent.HasMember(name)) if (parent[name].IsObject())
{ {
if (parent[name].IsObject()) found = true;
{ return parent[name];
found = true;
return parent[name];
}
else
throw ParseError(std::string("Field '")+ name + "' has invalid type");
}
else if (required)
throw ParseError(std::string("Field '")+ name + "' not found");
else
{
found = false;
return parent;
}
}
const rapidjson::Value& parseArray(const rapidjson::Value& parent, const char* name, bool required, bool& found)
{
if (parent.HasMember(name))
{
if (parent[name].IsArray())
{
found = true;
return parent[name];
}
else
throw ParseError(std::string("Field '")+ name + "' has invalid type");
}
else if (required)
throw ParseError(std::string("Field '")+ name + "' not found");
else
{
found = false;
return parent;
}
}
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& obj)
{
auto photo = std::make_unique<PhotoSize>();
photo->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
photo->setWidth(parse<int>(obj, "width", REQUIRED));
photo->setHeight(parse<int>(obj, "height", REQUIRED));
photo->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
return photo;
}
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
return parsePhotoSize(obj);
} }
else else
return nullptr; throw ParseError(std::string("Field '") + name + "' has invalid type");
} }
else if (required)
std::unique_ptr<PhotoSizeArray> parsePhotoSizeArray(const rapidjson::Value& parent, const char* name, bool required) throw ParseError(std::string("Field '") + name + "' not found");
else
{ {
bool found; found = false;
auto& obj = parseArray(parent, name, required, found); return parent;
if (found)
{
std::vector<PhotoSize> photos;
for (auto& elem : obj.GetArray())
{
auto photo = parsePhotoSize(elem);
photos.push_back(std::move(*photo));
}
auto result = std::make_unique<PhotoSizeArray>();
result->setArray(photos);
return result;
}
else
return nullptr;
}
std::unique_ptr<Audio> parseAudio(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto audio = std::make_unique<Audio>();
audio->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
audio->setDuration(parse<int>(obj, "duration", REQUIRED));
audio->setPerformer(parse<std::string>(obj, "performer", OPTIONAL));
audio->setTitle(parse<std::string>(obj, "title", OPTIONAL));
audio->setMimeType(parse<std::string>(obj, "mime_type", OPTIONAL));
audio->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
return audio;
}
else
return nullptr;
}
std::unique_ptr<Document> parseDocument(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto document = std::make_unique<Document>();
document->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
document->setThumb(parsePhotoSize(obj, "thumb", OPTIONAL));
document->setFileName(parse<std::string>(obj, "file_name", OPTIONAL));
document->setMimeType(parse<std::string>(obj, "mime_type", OPTIONAL));
document->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
return document;
}
else
return nullptr;
}
std::unique_ptr<Sticker> parseSticker(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto sticker = std::make_unique<Sticker>();
sticker->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
sticker->setWidth(parse<int>(obj, "width", REQUIRED));
sticker->setHeight(parse<int>(obj, "height", REQUIRED));
sticker->setThumb(parsePhotoSize(obj, "thumb", OPTIONAL));
sticker->setEmoji(parse<std::string>(obj, "emoji", OPTIONAL));
sticker->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
return sticker;
}
else
return nullptr;
}
std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto message = std::make_unique<Message>();
message->setId(parse<int>(obj, "message_id", REQUIRED));
message->setFrom(parseUser(obj, "from", OPTIONAL));
message->setDate(parse<int>(obj, "date", REQUIRED));
message->setChat(*parseChat(obj, "chat", REQUIRED));
message->setForwardFrom(parseUser(obj, "forward_from", OPTIONAL));
message->setForwardFromChat(parseChat(obj, "forward_from_chat", OPTIONAL));
message->setForwardDate(parse<int>(obj, "forward_date", OPTIONAL));
message->setReplyToMessage(parseMessage(obj, "reply_to_message", OPTIONAL));
message->setEditDate(parse<int>(obj, "edit_date", OPTIONAL));
message->setText(parse<std::string>(obj, "text", OPTIONAL));
//message->setEntities(parseEntities(obj, "entities", OPTIONAL));
/// \todo: Parse one of the possible attachments
std::shared_ptr<Attachment> attachment;
if (!(attachment = parsePhotoSizeArray(obj, "photo", OPTIONAL)))
if (!(attachment = parseAudio(obj, "audio", OPTIONAL)))
if (!(attachment = parseDocument(obj, "document", OPTIONAL)))
attachment = parseSticker(obj, "sticker", OPTIONAL);
message->setAttachment(attachment);
message->setCaption(parse<std::string>(obj, "caption", OPTIONAL));
message->setNewChatMember(parseUser(obj, "new_chat_member", OPTIONAL));
message->setLeftChatMember(parseUser(obj, "left_chat_member", OPTIONAL));
message->setNewChatTitle(parse<std::string>(obj, "new_chat_title", OPTIONAL));
message->setNewChatPhoto(parsePhotoSizeArray(obj, "new_chat_photo", OPTIONAL));
message->setDeleteChatPhoto(parse<bool>(obj, "delete_chat_photo", OPTIONAL));
message->setGroupChatCreated(parse<bool>(obj, "group_chat_created", OPTIONAL));
message->setSuperGroupChatCreated(parse<bool>(obj, "supergroup_chat_created", OPTIONAL));
message->setChannelChatCreated(parse<bool>(obj, "channel_chat_created", OPTIONAL));
message->setMigrateToChatId(parse<std::int64_t>(obj, "migrate_to_chat_id", OPTIONAL));
message->setMigrateFromChatId(parse<std::int64_t>(obj, "migrate_from_chat_id", OPTIONAL));
message->setPinnedMessage(parseMessage(obj, "pinned_message", OPTIONAL));
return message;
}
else
return nullptr;
}
std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto chat = std::make_unique<Chat>();
chat->setId(parse<std::int64_t>(obj, "id", REQUIRED));
chat->setType(chatTypeFromString(parse<std::string>(obj, "type", REQUIRED)));
chat->setTitle(parse<std::string>(obj, "title", OPTIONAL));
chat->setUsername(parse<std::string>(obj, "username", OPTIONAL));
chat->setFirstName(parse<std::string>(obj, "first_name", OPTIONAL));
chat->setLastName(parse<std::string>(obj, "last_name", OPTIONAL));
chat->setAllAdmins(parse<bool>(obj, "all_members_are_administrators", OPTIONAL));
return chat;
}
else
return nullptr;
}
std::unique_ptr<Update> parseUpdate(const rapidjson::Value& obj)
{
int id = parse<int>(obj, "update_id", REQUIRED);
std::unique_ptr<Message> message;
if ((message = parseMessage(obj, "message", OPTIONAL)))
return std::make_unique<MessageUpdate>(id, *message);
else if ((message = parseMessage(obj, "edited_message", OPTIONAL)))
return std::make_unique<EditedMessageUpdate>(id, *message);
/// \todo: other updates
else
throw ParseError("Unknown update type");
}
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseArray(parent, name, required, found);
if (found)
{
std::vector<UpdatePtr> updates;
for (auto& elem : obj.GetArray())
{
auto update = parseUpdate(elem);
updates.emplace_back(std::move(update));
}
return std::make_unique<Updates>(std::move(updates));
}
else
return nullptr;
}
std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto user = std::make_unique<User>();
user->setId(parse<int>(obj, "id", REQUIRED));
user->setFirstName(parse<std::string>(obj, "first_name", REQUIRED));
user->setLastName(parse<std::string>(obj, "last_name", OPTIONAL));
user->setUsername(parse<std::string>(obj, "username", OPTIONAL));
return user;
}
else
return nullptr;
}
void checkResponse(const rapidjson::Document& doc)
{
if (!doc.IsObject())
throw ParseError("Object expected");
// Get status
bool ok = parse<bool>(doc, "ok", REQUIRED);
if (!ok)
{
int code = parse<int>(doc, "error_code", REQUIRED);
std::string description(parse<std::string>(doc, "description", REQUIRED));
throw ApiError(code, description);
}
} }
} }
const rapidjson::Value& parseArray(const rapidjson::Value& parent, const char* name, bool required, bool& found)
{
if (parent.HasMember(name))
{
if (parent[name].IsArray())
{
found = true;
return parent[name];
}
else
throw ParseError(std::string("Field '") + name + "' has invalid type");
}
else if (required)
throw ParseError(std::string("Field '") + name + "' not found");
else
{
found = false;
return parent;
}
}
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& obj)
{
auto photo = std::make_unique<PhotoSize>();
photo->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
photo->setWidth(parse<int>(obj, "width", REQUIRED));
photo->setHeight(parse<int>(obj, "height", REQUIRED));
photo->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
return photo;
}
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
return parsePhotoSize(obj);
}
else
return nullptr;
}
std::unique_ptr<PhotoSizeArray> parsePhotoSizeArray(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseArray(parent, name, required, found);
if (found)
{
std::vector<PhotoSize> photos;
for (auto& elem : obj.GetArray())
{
auto photo = parsePhotoSize(elem);
photos.push_back(std::move(*photo));
}
auto result = std::make_unique<PhotoSizeArray>();
result->setArray(photos);
return result;
}
else
return nullptr;
}
std::unique_ptr<Audio> parseAudio(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto audio = std::make_unique<Audio>();
audio->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
audio->setDuration(parse<int>(obj, "duration", REQUIRED));
audio->setPerformer(parse<std::string>(obj, "performer", OPTIONAL));
audio->setTitle(parse<std::string>(obj, "title", OPTIONAL));
audio->setMimeType(parse<std::string>(obj, "mime_type", OPTIONAL));
audio->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
return audio;
}
else
return nullptr;
}
std::unique_ptr<Document> parseDocument(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto document = std::make_unique<Document>();
document->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
document->setThumb(parsePhotoSize(obj, "thumb", OPTIONAL));
document->setFileName(parse<std::string>(obj, "file_name", OPTIONAL));
document->setMimeType(parse<std::string>(obj, "mime_type", OPTIONAL));
document->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
return document;
}
else
return nullptr;
}
std::unique_ptr<Sticker> parseSticker(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto sticker = std::make_unique<Sticker>();
sticker->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
sticker->setWidth(parse<int>(obj, "width", REQUIRED));
sticker->setHeight(parse<int>(obj, "height", REQUIRED));
sticker->setThumb(parsePhotoSize(obj, "thumb", OPTIONAL));
sticker->setEmoji(parse<std::string>(obj, "emoji", OPTIONAL));
sticker->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
return sticker;
}
else
return nullptr;
}
std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto message = std::make_unique<Message>();
message->setId(parse<int>(obj, "message_id", REQUIRED));
message->setFrom(parseUser(obj, "from", OPTIONAL));
message->setDate(parse<int>(obj, "date", REQUIRED));
message->setChat(*parseChat(obj, "chat", REQUIRED));
message->setForwardFrom(parseUser(obj, "forward_from", OPTIONAL));
message->setForwardFromChat(parseChat(obj, "forward_from_chat", OPTIONAL));
message->setForwardDate(parse<int>(obj, "forward_date", OPTIONAL));
message->setReplyToMessage(parseMessage(obj, "reply_to_message", OPTIONAL));
message->setEditDate(parse<int>(obj, "edit_date", OPTIONAL));
message->setText(parse<std::string>(obj, "text", OPTIONAL));
//message->setEntities(parseEntities(obj, "entities", OPTIONAL));
/// \todo: Parse one of the possible attachments
std::shared_ptr<Attachment> attachment;
if (!(attachment = parsePhotoSizeArray(obj, "photo", OPTIONAL)))
if (!(attachment = parseAudio(obj, "audio", OPTIONAL)))
if (!(attachment = parseDocument(obj, "document", OPTIONAL)))
attachment = parseSticker(obj, "sticker", OPTIONAL);
message->setAttachment(attachment);
message->setCaption(parse<std::string>(obj, "caption", OPTIONAL));
message->setNewChatMember(parseUser(obj, "new_chat_member", OPTIONAL));
message->setLeftChatMember(parseUser(obj, "left_chat_member", OPTIONAL));
message->setNewChatTitle(parse<std::string>(obj, "new_chat_title", OPTIONAL));
message->setNewChatPhoto(parsePhotoSizeArray(obj, "new_chat_photo", OPTIONAL));
message->setDeleteChatPhoto(parse<bool>(obj, "delete_chat_photo", OPTIONAL));
message->setGroupChatCreated(parse<bool>(obj, "group_chat_created", OPTIONAL));
message->setSuperGroupChatCreated(parse<bool>(obj, "supergroup_chat_created", OPTIONAL));
message->setChannelChatCreated(parse<bool>(obj, "channel_chat_created", OPTIONAL));
message->setMigrateToChatId(parse<std::int64_t>(obj, "migrate_to_chat_id", OPTIONAL));
message->setMigrateFromChatId(parse<std::int64_t>(obj, "migrate_from_chat_id", OPTIONAL));
message->setPinnedMessage(parseMessage(obj, "pinned_message", OPTIONAL));
return message;
}
else
return nullptr;
}
std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto chat = std::make_unique<Chat>();
chat->setId(parse<std::int64_t>(obj, "id", REQUIRED));
chat->setType(chatTypeFromString(parse<std::string>(obj, "type", REQUIRED)));
chat->setTitle(parse<std::string>(obj, "title", OPTIONAL));
chat->setUsername(parse<std::string>(obj, "username", OPTIONAL));
chat->setFirstName(parse<std::string>(obj, "first_name", OPTIONAL));
chat->setLastName(parse<std::string>(obj, "last_name", OPTIONAL));
chat->setAllAdmins(parse<bool>(obj, "all_members_are_administrators", OPTIONAL));
return chat;
}
else
return nullptr;
}
std::unique_ptr<Update> parseUpdate(const rapidjson::Value& obj)
{
int id = parse<int>(obj, "update_id", REQUIRED);
std::unique_ptr<Message> message;
if ((message = parseMessage(obj, "message", OPTIONAL)))
return std::make_unique<MessageUpdate>(id, *message);
else if ((message = parseMessage(obj, "edited_message", OPTIONAL)))
return std::make_unique<EditedMessageUpdate>(id, *message);
/// \todo: other updates
else
throw ParseError("Unknown update type");
}
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseArray(parent, name, required, found);
if (found)
{
std::vector<UpdatePtr> updates;
for (auto& elem : obj.GetArray())
{
auto update = parseUpdate(elem);
updates.emplace_back(std::move(update));
}
return std::make_unique<Updates>(std::move(updates));
}
else
return nullptr;
}
std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
{
auto user = std::make_unique<User>();
user->setId(parse<int>(obj, "id", REQUIRED));
user->setFirstName(parse<std::string>(obj, "first_name", REQUIRED));
user->setLastName(parse<std::string>(obj, "last_name", OPTIONAL));
user->setUsername(parse<std::string>(obj, "username", OPTIONAL));
return user;
}
else
return nullptr;
}
void checkResponse(const rapidjson::Document& doc)
{
if (!doc.IsObject())
throw ParseError("Object expected");
// Get status
bool ok = parse<bool>(doc, "ok", REQUIRED);
if (!ok)
{
int code = parse<int>(doc, "error_code", REQUIRED);
std::string description(parse<std::string>(doc, "description", REQUIRED));
throw ApiError(code, description);
}
}
}

View file

@ -10,44 +10,45 @@
#include <rapidjson/document.h> #include <rapidjson/document.h>
namespace telebotxx namespace telebotxx {
{
const bool REQUIRED = true;
const bool OPTIONAL = false;
/// \brief Parse JSON object to Chat const bool REQUIRED = true;
/// \param parent reference to parent JSON object const bool OPTIONAL = false;
/// \param name field with Chat object
/// \param required REQUIRED or OPTIONAL
/// \return pointer to Chat
std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Parse JSON object to User /// \brief Parse JSON object to Chat
/// \param parent reference to parent JSON object /// \param parent reference to parent JSON object
/// \param name field with Document object /// \param name field with Chat object
/// \param required REQUIRED or OPTIONAL /// \param required REQUIRED or OPTIONAL
/// \return pointer to User /// \return pointer to Chat
std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required); std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Parse JSON object to Message /// \brief Parse JSON object to User
/// \param parent reference to parent JSON object /// \param parent reference to parent JSON object
/// \param name field with Message object /// \param name field with Document object
/// \param required REQUIRED or OPTIONAL /// \param required REQUIRED or OPTIONAL
/// \return pointer to Message /// \return pointer to User
std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required); std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Parse JSON array of Update /// \brief Parse JSON object to Message
/// \param parent reference to parent JSON object /// \param parent reference to parent JSON object
/// \param name field with array of Update objects /// \param name field with Message object
/// \param required REQUIRED or OPTIONAL /// \param required REQUIRED or OPTIONAL
/// \return Updates (vector of UpdatePtr> /// \return pointer to Message
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required); std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Parse JSON array of Update
/// \param parent reference to parent JSON object
/// \param name field with array of Update objects
/// \param required REQUIRED or OPTIONAL
/// \return Updates (vector of UpdatePtr>
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Check JSON response
///
/// Throws an exception if error code recieved.
/// \param doc reference to JSON document
void checkResponse(const rapidjson::Document& doc);
/// \brief Check JSON response
///
/// Throws an exception if error code recieved.
/// \param doc reference to JSON document
void checkResponse(const rapidjson::Document& doc);
} }
#endif // TELEBOTXX_JSON_OBJECTS_HPP #endif // TELEBOTXX_JSON_OBJECTS_HPP

View file

@ -1,11 +1,12 @@
#include <telebotxx/Logging.hpp> #include <telebotxx/Logging.hpp>
namespace telebotxx namespace telebotxx {
{
bool debugMode = false; bool debugMode = false;
void setDebugMode(bool enabled)
{
debugMode = enabled;
}
void setDebugMode(bool enabled)
{
debugMode = enabled;
}
} }

View file

@ -1,16 +1,18 @@
#include <telebotxx/Message.hpp> #include <telebotxx/Message.hpp>
using namespace telebotxx; namespace telebotxx {
MessageEntity::MessageEntity() MessageEntity::MessageEntity()
: type_(Type::Mention), : type_(Type::Mention),
offset_(-1), offset_(-1),
length_(0) length_(0)
{ {
} }
MessageEntity::MessageEntity(const MessageEntity&) = default; MessageEntity::MessageEntity(const MessageEntity&) = default;
MessageEntity::MessageEntity(MessageEntity&&) = default; MessageEntity::MessageEntity(MessageEntity&&) = default;
MessageEntity::~MessageEntity() = default; MessageEntity::~MessageEntity() = default;
MessageEntity::Type MessageEntity::getType() const MessageEntity::Type MessageEntity::getType() const
@ -79,7 +81,7 @@ const MessageEntity& MessageEntity::operator=(MessageEntity other)
return *this; return *this;
} }
MessageEntity::Type telebotxx::messageEntityTypeFromString(const std::string& str) MessageEntity::Type messageEntityTypeFromString(const std::string& str)
{ {
if (str == "mention") if (str == "mention")
return MessageEntity::Type::Mention; return MessageEntity::Type::Mention;
@ -108,12 +110,14 @@ MessageEntity::Type telebotxx::messageEntityTypeFromString(const std::string& st
} }
Message::Message() Message::Message()
: id_(-1) : id_(-1)
{ {
} }
Message::Message(const Message&) = default; Message::Message(const Message&) = default;
Message::Message(Message&&) = default; Message::Message(Message&&) = default;
Message::~Message() = default; Message::~Message() = default;
int Message::getId() const int Message::getId() const
@ -391,7 +395,9 @@ const Message& Message::operator=(Message other) noexcept
return *this; return *this;
} }
void telebotxx::swap(Message& lhs, Message& rhs) void swap(Message& lhs, Message& rhs)
{ {
lhs.swap(rhs); lhs.swap(rhs);
} }
}

View file

@ -1,6 +1,6 @@
#include <telebotxx/RequestOptions.hpp> #include <telebotxx/RequestOptions.hpp>
using namespace telebotxx; namespace telebotxx {
ChatId::ChatId(int id) ChatId::ChatId(int id)
: type_(Type::Id), id_(id) : type_(Type::Id), id_(id)
@ -95,7 +95,7 @@ int ReplyTo::value() const
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
Buffer::Buffer(const char *buffer, std::size_t size, const std::string& filename) Buffer::Buffer(const char* buffer, std::size_t size, const std::string& filename)
: data_(buffer), size_(size), filename_(filename) : data_(buffer), size_(size), filename_(filename)
{ {
} }
@ -140,7 +140,7 @@ const std::string& Url::getUrl() const
} }
Url::Url(const std::string& url) Url::Url(const std::string& url)
: url_(url) : url_(url)
{ {
} }
@ -207,7 +207,7 @@ Photo::~Photo()
{ {
if (type_ == Type::File) if (type_ == Type::File)
file_.~File(); file_.~File();
else if(type_ == Type::Url) else if (type_ == Type::Url)
url_.~Url(); url_.~Url();
} }
@ -235,3 +235,5 @@ const Url& Photo::getUrl() const
{ {
return url_; return url_;
} }
}

View file

@ -7,8 +7,9 @@
#include <rapidjson/writer.h> #include <rapidjson/writer.h>
#include <iostream> #include <iostream>
#include <boost/optional.hpp>
using namespace telebotxx; namespace telebotxx {
class SendMessageRequest::Impl class SendMessageRequest::Impl
{ {
@ -61,7 +62,8 @@ public:
if (parseMode_) if (parseMode_)
{ {
writer.String("parse_mode"); writer.String("parse_mode");
writer.String((parseMode_ == ParseMode::Markdown) ? "Markdown" : (parseMode_ == ParseMode::Html) ? "HTML" : "Plain"); writer.String(
(parseMode_ == ParseMode::Markdown) ? "Markdown" : (parseMode_ == ParseMode::Html) ? "HTML" : "Plain");
} }
// Add disable_web_page_preview // Add disable_web_page_preview
@ -173,3 +175,5 @@ Message SendMessageRequest::execute()
{ {
return impl_->execute(); return impl_->execute();
} }
}

View file

@ -1,5 +1,4 @@
#include <telebotxx/SendPhotoRequest.hpp> #include <telebotxx/SendPhotoRequest.hpp>
#include <telebotxx/Logging.hpp> #include <telebotxx/Logging.hpp>
#include "JsonObjects.hpp" #include "JsonObjects.hpp"
@ -8,8 +7,9 @@
#include <rapidjson/writer.h> #include <rapidjson/writer.h>
#include <iostream> #include <iostream>
#include <boost/optional.hpp>
using namespace telebotxx; namespace telebotxx {
class SendPhotoRequest::Impl class SendPhotoRequest::Impl
{ {
@ -137,3 +137,5 @@ Message SendPhotoRequest::execute()
{ {
return impl_->execute(); return impl_->execute();
} }
}

View file

@ -1,6 +1,6 @@
#include <telebotxx/Update.hpp> #include <telebotxx/Update.hpp>
using namespace telebotxx; namespace telebotxx {
Update::Update(int id, Type type) Update::Update(int id, Type type)
: id_(id), : id_(id),
@ -80,3 +80,5 @@ const EditedMessageUpdate& EditedMessageUpdate::operator=(EditedMessageUpdate ot
swap(other); swap(other);
return *this; return *this;
} }
}

View file

@ -1,7 +1,7 @@
#include <telebotxx/User.hpp> #include <telebotxx/User.hpp>
#include <sstream> #include <sstream>
using namespace telebotxx; namespace telebotxx {
User::User() User::User()
: id_(-1) : id_(-1)
@ -9,7 +9,9 @@ User::User()
} }
User::User(const User&) = default; User::User(const User&) = default;
User::User(User&&) = default; User::User(User&&) = default;
User::~User() = default; User::~User() = default;
int User::getId() const int User::getId() const
@ -73,8 +75,10 @@ const User& User::operator=(User other)
return *this; return *this;
} }
std::ostream& telebotxx::operator<<(std::ostream& os, const User& user) std::ostream& operator<<(std::ostream& os, const User& user)
{ {
os << user.toString(); os << user.toString();
return os; return os;
} }
}