twitter_tool/twitter_client/
api.rs1use chrono::{DateTime, Local, Utc};
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug, Serialize, Deserialize)]
5pub struct Response<Data, Includes> {
6 pub data: Data,
7 pub includes: Option<Includes>,
8 pub meta: Option<Meta>,
9}
10
11#[derive(Clone, Debug, Serialize, Deserialize)]
12pub struct Meta {
13 pub next_token: Option<String>,
14 pub result_count: i64,
15 pub newest_id: Option<String>,
16 pub oldest_id: Option<String>,
17}
18
19#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
20pub struct User {
21 pub id: String,
22 pub name: String,
23 pub username: String,
24}
25
26#[derive(Clone, Debug, Serialize, Deserialize)]
27pub struct Tweet {
28 pub id: String,
29 pub text: String,
30 pub created_at: DateTime<Local>,
31 pub author_id: String,
32 pub author_username: Option<String>,
33 pub author_name: Option<String>,
34 pub conversation_id: Option<String>,
35 pub referenced_tweets: Option<Vec<TweetReference>>,
36 pub attachments: Option<Attachments>,
37 pub public_metrics: Option<PublicMetrics>,
38}
39
40impl Tweet {
41 pub fn author(&self, fill_unknown_with: &str) -> User {
42 User {
43 id: self.author_id.clone(),
44 name: self
45 .author_name
46 .clone()
47 .unwrap_or(fill_unknown_with.to_string()),
48 username: self
49 .author_username
50 .clone()
51 .unwrap_or(fill_unknown_with.to_string()),
52 }
53 }
54}
55
56#[derive(Clone, Debug, Serialize, Deserialize)]
57pub struct TweetReference {
58 pub r#type: String,
59 pub id: String,
60}
61
62#[derive(Clone, Debug, Serialize, Deserialize)]
63pub struct Attachments {
64 pub poll_ids: Option<Vec<String>>,
65 pub media_keys: Option<Vec<String>>,
66}
67
68#[derive(Clone, Debug, Serialize, Deserialize)]
69pub struct PublicMetrics {
70 pub retweet_count: i32,
71 pub reply_count: i32,
72 pub like_count: i32,
73 pub quote_count: i32,
74}