From 69fc8d805396b889b5e8c1c88e8129d93db77d29 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 20 Aug 2016 13:56:23 -0400 Subject: Updated API to use exceptions and make tweet/user objects more helpful --- src/tweet.h | 70 +++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 18 deletions(-) (limited to 'src/tweet.h') diff --git a/src/tweet.h b/src/tweet.h index 387f73a..3035d51 100644 --- a/src/tweet.h +++ b/src/tweet.h @@ -2,41 +2,75 @@ #define TWEET_H_CE980721 #include -#include "user.h" #include #include +#include +#include +#include "user.h" namespace twitter { + class client; + typedef unsigned long long tweet_id; class tweet { public: - tweet(); - tweet(std::string data); - tweet(const tweet& other); - tweet(tweet&& other); - ~tweet(); - tweet& operator=(tweet other); - friend void swap(tweet& first, tweet& second); + tweet(const client& tclient, std::string data); + + tweet(const tweet& other) = delete; + tweet& operator=(const tweet& other) = delete; + + tweet(tweet&& other) = default; + tweet& operator=(tweet&& other) = default; + + tweet_id getID() const + { + return _id; + } + + std::string getText() const + { + return _text; + } - tweet_id getID() const; - std::string getText() const; - const user& getAuthor() const; - bool isRetweet() const; - tweet getRetweet() const; - std::vector> getMentions() const; + const user& getAuthor() const + { + return *_author; + } - operator bool() const; + bool isRetweet() const + { + return _is_retweet; + } + + const tweet& getRetweet() const + { + assert(_is_retweet); + + return *_retweeted_status; + } + + const std::vector>& getMentions() const + { + return _mentions; + } + + std::string generateReplyPrefill() const; + + tweet reply(std::string message, std::list media_ids = {}) const; + + bool isMyTweet() const; private: - bool _valid; + + const client& _client; tweet_id _id; std::string _text; - user _author; + std::unique_ptr _author; bool _is_retweet = false; - tweet* _retweeted_status = nullptr; + std::unique_ptr _retweeted_status; std::vector> _mentions; }; -- cgit 1.4.1