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
extern crate reqwest;
extern crate serde;
extern crate serde_json;
use reqwest::Client;
use serde::Deserialize;
#[derive(Deserialize,Debug,Clone)]
pub struct News {
pub title: String,
pub postId: u16,
pub author: String,
pub body: Option<String>,
pub date: String,
pub image: String,
}
#[derive(Deserialize,Debug)]
pub struct NewsList(Vec<News>);
impl News {
#[tokio::main]
pub async fn new_latest(client:Client) -> Result<Self,Box<dyn std::error::Error>> {
let resp = client.get("https://www.toontownrewritten.com/api/news").send().await?
.json::<Self>()
.await?;
Ok(resp)
}
#[tokio::main]
pub async fn new_id(client:Client,id:u16) -> Result<Self,Box<dyn std::error::Error>> {
let resp = client.get(format!("https://www.toontownrewritten.com/api/news/{}",id)).send().await?
.json::<Self>()
.await?;
Ok(resp)
}
pub fn get_link(&self) -> String {
format!("https://www.toontownrewritten.com/news/item/{}",self.postId)
}
}
impl NewsList {
#[tokio::main]
pub async fn new(client:Client) -> Result<Self,Box<dyn std::error::Error>> {
let resp = client.get("https://www.toontownrewritten.com/api/news/list").send().await?
.json::<Self>()
.await?;
Ok(resp)
}
pub fn get_index(&self,index:usize) -> News {
self.0[index].clone()
}
}