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
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct Tweet {
id: i64,
id_str: String,
text: String,
truncated: bool,
in_reply_to_status_id: Option<i64>,
in_reply_to_status_id_str: Option<String>,
in_reply_to_user_id: Option<i64>,
in_reply_to_user_id_str: Option<String>,
in_reply_to_screen_name: Option<String>,
user: User,
is_quote_status: bool,
retweet_count: i64,
favorite_count: i64,
favorited: bool,
retweeted: bool,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct User {
id: i64,
id_str: String,
name: String,
screen_name: String,
location: Option<String>,
description: Option<String>,
url: Option<String>,
followers_count: i64,
friends_count: i64,
listed_count: i64,
favourites_count: i64,
statuses_count: i64,
following: Option<bool>,
follow_request_sent: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SearchResponse {
pub statuses: Vec<Tweet>,
search_metadata: SearchMetadata,
}
#[derive(Debug, Serialize, Deserialize)]
struct SearchMetadata {
completed_in: f64,
max_id: i64,
max_id_str: String,
query: String,
refresh_url: String,
count: i64,
since_id: i64,
since_id_str: String,
}
impl Tweet {
pub fn id(&self) -> i64 {
self.id
}
pub fn reply_to(&self) -> Option<i64> {
self.in_reply_to_status_id
}
pub fn user(&self) -> &User {
&self.user
}
pub fn content(&self) -> &str {
&self.text
}
}
impl User {
pub fn id(&self) -> &str {
&self.id_str
}
pub fn name(&self) -> &str {
&self.screen_name
}
}
#[derive(Serialize, Deserialize)]
pub struct Media {
pub media_id: u64,
}
#[derive(Serialize, Deserialize)]
struct Errors {
code: i64,
message: String,
}
#[derive(Serialize, Deserialize)]
pub struct TwitterError {
errors: Vec<Errors>,
}
impl TwitterError {
pub fn message(&self) -> &str {
&self.errors[0].message
}
}