From 1ea7097db5a00a058c5455e210b70517b912331a Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 23 Dec 2023 10:02:10 +0000 Subject: [PATCH] PoC of retrieving and unpacking a struct. --- Cargo.toml | 3 ++- src/main.rs | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a5bc48a..5f07ea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] crossterm = "0.27.0" html2text = "0.9.0" -reqwest = "0.11.23" +reqwest = { version = "0.11.23", features = ["blocking"] } +serde = { version = "1.0.193", features = ["derive"] } serde_json = "1.0.108" unicode-width = "0.1.5" diff --git a/src/main.rs b/src/main.rs index e7a11a9..2304bb4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,39 @@ +use serde::{Deserialize, Serialize}; +use serde_json::Result; + +#[derive(Serialize, Deserialize, Debug)] +struct Account { + id: String, + username: String, + acct: String, + url: String, + display_name: String, + note: String, + avatar: String, + avatar_static: String, + header: String, + header_static: String, + locked: bool, + // fields: Vec, + // emojis: Vec, + bot: bool, + group: bool, + // discoverable: optional bool, + // noindex: optional bool, + // moved: optional Account (!), + // suspended: optional bool, + // limited: optional bool, + created_at: String, // FIXME: sort out dates! + last_status_at: String, + statuses_count: u64, + followers_count: u64, + following_count: u64, +} + fn main() { - println!("Hello, world!"); + let body = reqwest::blocking::get( + "https://hachyderm.io/api/v1/accounts/111096602447828617") + .unwrap().text().unwrap(); + let acc: Account = serde_json::from_str(&body).unwrap(); + dbg!(acc); } -- 2.30.2