chiark / gitweb /
PoC of retrieving and unpacking a struct.
authorSimon Tatham <anakin@pobox.com>
Sat, 23 Dec 2023 10:02:10 +0000 (10:02 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 23 Dec 2023 10:02:10 +0000 (10:02 +0000)
Cargo.toml
src/main.rs

index a5bc48a1744a93e6c63aa38895f417acfd9bef01..5f07ea3229c2b88a8435361dd38a3ff4401f14e5 100644 (file)
@@ -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"
index e7a11a969c037e00a796aafeff6258501ec15e9a..2304bb4ad13d149f1bd7704a04dd01fc1ba7e699 100644 (file)
@@ -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<AccountField>,
+    // emojis: Vec<Emoji>,
+    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);
 }