From 0ccac89815ee92c69fefc148cfb272faf7309136 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 20 May 2016 15:34:44 -0400 Subject: Started implementing user streams You can now start a user stream and end it yourself. If it disconnects abnormally, it will reconnect with a backoff as described by Twitter. Some data structures have some fields parsed now; tweets have IDs, text, and authors. Users have IDs, screen names, and names. Notifications from the stream are parsed completely. The ability to follow and unfollow users has also been added, as well as the ability to get a list of friends and followers, and to reply to a tweet. --- src/notification.h | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 src/notification.h (limited to 'src/notification.h') diff --git a/src/notification.h b/src/notification.h new file mode 100644 index 0000000..da83b0f --- /dev/null +++ b/src/notification.h @@ -0,0 +1,145 @@ +#ifndef NOTIFICATION_H_69AEF4CC +#define NOTIFICATION_H_69AEF4CC + +#include +#include +#include +#include "tweet.h" +#include "user.h" +#include "list.h" +#include "direct_message.h" + +namespace twitter { + + enum class disconnect_code { + shutdown, + duplicate, + stall, + normal, + token_revoked, + admin_logout, + limit, + exception, + broker, + load, + unknown + }; + + class notification { + public: + enum class type { + // Tweet object + tweet, + + // User object + update_user, + block, + unblock, + follow, + followed, + unfollow, + + // User and tweet + favorite, + favorited, + unfavorite, + unfavorited, + quoted, + + // List + list_created, + list_destroyed, + list_updated, + + // User and list + list_add, + list_added, + list_remove, + list_removed, + list_subscribe, + list_subscribed, + list_unsubscribe, + list_unsubscribed, + + // Warning + stall, + follow_limit, + unknown_warning, + + // User ID and tweet ID + deletion, + scrub_location, + + // Special + limit, + withhold_status, + withhold_user, + disconnect, + friends, + direct, + + // Nothing + unknown, + invalid + }; + + type getType() const; + + notification(); + notification(std::string data, const user& current_user); + notification(const notification& other); + notification& operator=(const notification& other); + ~notification(); + + tweet getTweet() const; + user getUser() const; + list getList() const; + tweet_id getTweetID() const; + user_id getUserID() const; + std::vector getCountries() const; + disconnect_code getDisconnectCode() const; + std::set getFriends() const; + direct_message getDirectMessage() const; + int getLimit() const; + std::string getWarning() const; + + operator bool() const; + + private: + union { + tweet _tweet; + user _user; + list _list; + struct { + user _user; + tweet _tweet; + } _user_and_tweet; + struct { + user _user; + list _list; + } _user_and_list; + std::string _warning; + struct { + user_id _user_id; + tweet_id _tweet_id; + } _user_id_and_tweet_id; + int _limit; + struct { + user_id _user_id; + tweet_id _tweet_id; + std::vector _countries; + } _withhold_status; + struct { + user_id _user_id; + std::vector _countries; + } _withhold_user; + disconnect_code _disconnect; + std::set _friends; + direct_message _direct_message; + }; + type _type; + }; + +}; + +#endif /* end of include guard: NOTIFICATION_H_69AEF4CC */ -- cgit 1.4.1