File: TwitterResponseParser.h

package info (click to toggle)
spectrum2 2.2.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,548 kB
  • sloc: cpp: 32,594; python: 1,751; javascript: 273; makefile: 34; sql: 31; xml: 10
file content (242 lines) | stat: -rw-r--r-- 8,688 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#ifndef TWITTERRESPOSNSEPARSER_H
#define TWITTERRESPOSNSEPARSER_H

#include <json/json.h>

#include <iostream>
#include <vector>
#include <string>
#include <utility>

namespace TwitterReponseTypes
{
	const std::string id = "id";
	const std::string id_list = "id_list";
	const std::string ids = "ids";
	const std::string name = "name";
	const std::string screen_name = "screen_name";
	const std::string statuses_count = "statuses_count";
	const std::string created_at = "created_at";
	const std::string text = "full_text";
	const std::string truncated = "truncated";
	const std::string in_reply_to_status_id = "in_reply_to_user_id";
	const std::string in_reply_to_user_id = "in_reply_to_user_id";
	const std::string in_reply_to_screen_name = "in_reply_to_screen_name";
	const std::string retweet_count = "retweet_count";
	const std::string retweeted_status = "retweeted_status";
	const std::string favorited = "favorited";
	const std::string retweeted = "retweeted";
	const std::string user = "user";
	const std::string users = "users";
	const std::string status = "status";
	const std::string error = "error";
	const std::string direct_message = "direct_message";
	const std::string directmessages = "direct-messages";
	const std::string sender_id = "sender_id";
	const std::string recipient_id = "recipient_id";
	const std::string sender_screen_name = "sender_screen_name";
	const std::string recipient_screen_name = "recipient_screen_name";
	const std::string sender = "sender";
   	const std::string recipient = "recipient";
	const std::string profile_image_url = "profile_image_url";
};

//Class representing an embedded status object within other objects such as the User object.
//Note: Not possible to user Status due to circular dependency
class EmbeddedStatus
{
	std::string created_at;
	std::string ID;
	std::string text;
	bool truncated;
	std::string in_reply_to_status_id;
	std::string in_reply_to_user_id;
	std::string in_reply_to_screen_name;
	unsigned int retweet_count;
	bool favorited;
	bool retweeted;
	
	public:
	EmbeddedStatus():created_at(""),ID(""),text(""),truncated(false),in_reply_to_status_id(""),
	         in_reply_to_user_id(""),in_reply_to_screen_name(""),retweet_count(0),
	         favorited(false),retweeted(0){}
	
	std::string getCreationTime() {return created_at;}
	std::string getID() {return ID;}
	std::string getTweet() {return text;}
	bool isTruncated() {return truncated;}
	std::string getReplyToStatusID() {return in_reply_to_status_id;}
	std::string getReplyToUserID() {return in_reply_to_user_id;}
	std::string getReplyToScreenName() {return in_reply_to_screen_name;}
	unsigned int getRetweetCount() {return retweet_count;}
	bool isFavorited() {return favorited;}
	bool isRetweeted() {return retweeted;}
	
	void setCreationTime(std::string _created) {created_at = _created;}
	void setID(std::string _id) {ID = _id;}
	void setTweet(std::string _text) {text = _text;}
	void setTruncated(bool val) {truncated = val;}
	void setReplyToStatusID(std::string _id) {in_reply_to_status_id = _id;}
	void setReplyToUserID(std::string _id) {in_reply_to_user_id = _id;}
	void setReplyToScreenName(std::string _name) {in_reply_to_screen_name = _name;}
	void setRetweetCount(unsigned int rc) {retweet_count = rc;}
	void setFavorited(bool val) {favorited = val;}
	void setRetweeted(bool val) {retweeted = val;}
};

//Class holding user data
class User
{
	std::string ID;
	std::string name;
	std::string screen_name;
	std::string profile_image_url;
	unsigned int statuses_count;
	EmbeddedStatus last_status;

	public:
	User():ID(""),name(""),screen_name(""),statuses_count(0){}

	std::string getUserID() {return ID;}
	std::string getUserName() {return name;}
	std::string getScreenName() {return screen_name;}
	std::string getProfileImgURL() {return profile_image_url;}
	unsigned int getNumberOfTweets() {return statuses_count;}
	EmbeddedStatus getLastStatus() {return last_status;}
	
	
	void setUserID(std::string _id) {ID = _id;}
	void setUserName(std::string _name) {name = _name;}
	void setScreenName(std::string _screen) {screen_name = _screen;}
	void setProfileImgURL(std::string _url) {profile_image_url = _url;}
	void setNumberOfTweets(unsigned int sc) {statuses_count  = sc;}
	void setLastStatus(EmbeddedStatus _last_status) {last_status = _last_status;}
};


//Class representing a status (tweet)
class Status
{
	std::string created_at;
	std::string ID;
	std::string retweetID;	
	std::string text;
	bool truncated;
	std::string in_reply_to_status_id;
	std::string in_reply_to_user_id;
	std::string in_reply_to_screen_name;
	User user;
	unsigned int retweet_count;
	bool favorited;
	bool retweeted;

	public:
		Status():created_at(""),ID(""),retweetID(""),text(""),truncated(false),in_reply_to_status_id(""),
	         in_reply_to_user_id(""),in_reply_to_screen_name(""),user(User()),retweet_count(0),
	         favorited(false),retweeted(0){}
	
	std::string getCreationTime() {return created_at;}
	std::string getID() {return ID;}
	std::string getRetweetID() {return retweetID;}	
	std::string getTweet() {return text;}
	bool isTruncated() {return truncated;}
	std::string getReplyToStatusID() {return in_reply_to_status_id;}
	std::string getReplyToUserID() {return in_reply_to_user_id;}
	std::string getReplyToScreenName() {return in_reply_to_screen_name;}
	User getUserData() {return user;}
	unsigned int getRetweetCount() {return retweet_count;}
	bool isFavorited() {return favorited;}
	bool isRetweeted() {return retweeted;}
	
	void setCreationTime(std::string _created) {created_at = _created;}
	void setID(std::string _id) {ID = _id;}
	void setRetweetID(std::string _id) {retweetID = _id;}	
	void setTweet(std::string _text) {text = _text;}
	void setTruncated(bool val) {truncated = val;}
	void setReplyToStatusID(std::string _id) {in_reply_to_status_id = _id;}
	void setReplyToUserID(std::string _id) {in_reply_to_user_id = _id;}
	void setReplyToScreenName(std::string _name) {in_reply_to_screen_name = _name;}
	void setUserData(User u) {user = u;}
	void setRetweetCount(unsigned int rc) {retweet_count = rc;}
	void setFavorited(bool val) {favorited = val;}
	void setRetweeted(bool val) {retweeted = val;}
};

//Class representing a Direct Message
class DirectMessage
{
	std::string created_at;
	std::string ID;
	std::string text;
	std::string sender_id;
	std::string recipient_id;
	std::string sender_screen_name;
	std::string recipient_screen_name;
	User sender, recipient;

	public:
	DirectMessage():created_at(""),ID(""),text(""),sender_id(""),recipient_id(""),
			 sender_screen_name(""),recipient_screen_name(""),sender(User()),recipient(User()){}
	
	std::string getCreationTime() {return created_at;}
	std::string getID() {return ID;}
	std::string getMessage() {return text;}
	std::string getSenderID() {return sender_id;}
	std::string getRecipientID() {return recipient_id;}
	std::string getSenderScreenName() {return sender_screen_name;}
	std::string getRecipientScreenName() {return recipient_screen_name;}
	User getSenderData() {return sender;}
	User getRecipientData() {return recipient;}
	
	void setCreationTime(std::string _created) {created_at = _created;}
	void setID(std::string _id) {ID = _id;}
	void setMessage(std::string _text) {text = _text;}
	void setSenderID(std::string _id) {sender_id = _id;}
	void setRecipientID(std::string _id) {recipient_id = _id;}
	void setSenderScreenName(std::string _name) {sender_screen_name = _name;}
	void setRecipientScreenName(std::string _name) {recipient_screen_name = _name;}
	void setSenderData(User u) {sender = u;}
	void setRecipientData(User u) {recipient = u;}
};

class Error
{
	std::string code;
	std::string message;
	public:
	Error():code(""),message(""){}
	std::string getCode() {return code;}
	std::string getMessage() {return message;}
	bool isCurlError() { return code.empty(); }

	void setCode(std::string &_code) {code = _code;}
	void setMessage(std::string &_message) {message = _message;}
};

class UrlEntity 
{
	std::string url;
	std::string expanded_url;	
public:
	UrlEntity(std::string _url, std::string _expanded) 
	{ 
		url = _url;
		expanded_url = _expanded;
	}
	std::string getUrl() {return url;}
	std::string getExpandedUrl() {return expanded_url;}
	
};

std::vector<Status> getTimeline(std::string &xml);
std::vector<DirectMessage> getDirectMessages(std::string &xml);
std::vector<std::string> getIDs(std::string &xml);
std::vector<User> getUsers(std::string &xml);
User getUser(std::string &xml);
Error getErrorMessage(std::string &xml);

std::vector<UrlEntity> getUrlEntities(const Json::Value &element);
Status getStatus(const Json::Value &element);
DirectMessage getDirectMessage(const Json::Value &element);
User getUser(const Json::Value &element);
#endif