2022-11-02 21:12:16 +01:00
|
|
|
#[derive(Debug, serde::Deserialize)]
|
|
|
|
pub struct Account {
|
|
|
|
pub username: String,
|
|
|
|
pub display_name: String,
|
|
|
|
pub url: String,
|
|
|
|
pub bot: bool,
|
|
|
|
pub avatar: String,
|
|
|
|
pub header: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Account {
|
|
|
|
pub fn host(&self) -> Option<String> {
|
|
|
|
reqwest::Url::parse(&self.url)
|
|
|
|
.ok()
|
|
|
|
.and_then(|url| url.domain()
|
|
|
|
.map(|s| s.to_owned())
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, serde::Deserialize)]
|
|
|
|
pub struct Tag {
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, serde::Deserialize)]
|
|
|
|
pub struct Application {
|
|
|
|
pub name: String,
|
2022-11-02 22:42:20 +01:00
|
|
|
pub website: Option<String>,
|
2022-11-02 21:12:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, serde::Deserialize)]
|
|
|
|
pub struct Post {
|
|
|
|
pub created_at: String,
|
|
|
|
pub url: String,
|
|
|
|
pub content: String,
|
|
|
|
pub account: Account,
|
|
|
|
pub tags: Vec<Tag>,
|
|
|
|
pub application: Option<Application>,
|
|
|
|
pub sensitive: Option<bool>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Post {
|
|
|
|
// fn time
|
|
|
|
// fn text_content
|
2022-11-02 21:49:37 +01:00
|
|
|
pub fn url_host(&self) -> Option<String> {
|
|
|
|
reqwest::Url::parse(&self.url)
|
|
|
|
.ok()
|
|
|
|
.and_then(|url| url.domain()
|
|
|
|
.map(|s| s.to_owned()))
|
|
|
|
}
|
2022-11-02 21:12:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Feed {
|
|
|
|
pub posts: Vec<Post>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Feed {
|
|
|
|
pub async fn fetch(client: &reqwest::Client, url: &str) -> Result<Self, reqwest::Error> {
|
|
|
|
println!("GET {}", url);
|
|
|
|
let posts: Vec<Post> = client.get(url)
|
|
|
|
.send()
|
|
|
|
.await?
|
|
|
|
.json()
|
|
|
|
.await?;
|
|
|
|
println!("{}: {} posts", url, posts.len());
|
|
|
|
Ok(Feed { posts })
|
|
|
|
}
|
|
|
|
}
|