Skip to main content

twapi_v2/responses/
jobs.rs

1use chrono::prelude::*;
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
5pub struct Jobs {
6    #[serde(skip_serializing_if = "Option::is_none")]
7    pub id: Option<String>,
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub created_at: Option<DateTime<Utc>>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub r#type: Option<Type>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub name: Option<String>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub upload_url: Option<String>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub upload_expires_at: Option<DateTime<Utc>>,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub download_url: Option<String>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub download_expires_at: Option<DateTime<Utc>>,
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub url: Option<String>,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub status: Option<Status>,
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub error: Option<String>,
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub resumable: Option<bool>,
30    #[serde(flatten)]
31    pub extra: std::collections::HashMap<String, serde_json::Value>,
32}
33
34impl Jobs {
35    pub fn is_empty_extra(&self) -> bool {
36        let res = self.extra.is_empty();
37        if !res {
38            println!("Jobs {:?}", self.extra);
39        }
40        res
41    }
42}
43
44#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
45pub enum Type {
46    #[serde(rename = "tweets")]
47    #[default]
48    Tweets,
49    #[serde(rename = "users")]
50    Users,
51}
52
53impl std::fmt::Display for Type {
54    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
55        match self {
56            Self::Tweets => write!(f, "tweets"),
57            Self::Users => write!(f, "users"),
58        }
59    }
60}
61
62#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
63pub enum Status {
64    #[serde(rename = "created")]
65    #[default]
66    Created,
67    #[serde(rename = "in_progress")]
68    InProgress,
69    #[serde(rename = "failed")]
70    Failed,
71    #[serde(rename = "complete")]
72    Complete,
73}
74
75impl std::fmt::Display for Status {
76    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
77        match self {
78            Self::Created => write!(f, "created"),
79            Self::InProgress => write!(f, "in_progress"),
80            Self::Failed => write!(f, "failed"),
81            Self::Complete => write!(f, "complete"),
82        }
83    }
84}