From edd335de79e372863ce5d1d336f6f4028dc302cd Mon Sep 17 00:00:00 2001 From: Joseph Holtkamp Date: Sat, 11 Mar 2023 08:58:17 -0600 Subject: [PATCH] Parses response into json, not yet usable --- Cargo.lock | 85 ++++++++++------------------------------------------- Cargo.toml | 3 +- src/main.rs | 18 +++++++----- 3 files changed, 29 insertions(+), 77 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab397e4..5224203 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -398,16 +398,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" -[[package]] -name = "lock_api" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.17" @@ -529,29 +519,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-sys 0.45.0", -] - [[package]] name = "percent-encoding" version = "2.2.0" @@ -671,12 +638,6 @@ dependencies = [ "windows-sys 0.42.0", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "security-framework" version = "2.8.2" @@ -705,6 +666,20 @@ name = "serde" version = "1.0.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a382c72b4ba118526e187430bb4963cd6d55051ebf13d9b25574d379cc98d20" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ef476a5790f0f6decbc66726b6e5d63680ed518283e64c7df415989d880954f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "serde_json" @@ -729,15 +704,6 @@ dependencies = [ "serde", ] -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.8" @@ -747,12 +713,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - [[package]] name = "socket2" version = "0.4.9" @@ -814,25 +774,11 @@ dependencies = [ "memchr", "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", "socket2", - "tokio-macros", "windows-sys 0.45.0", ] -[[package]] -name = "tokio-macros" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tokio-native-tls" version = "0.3.1" @@ -1136,5 +1082,6 @@ name = "word_of_the_day" version = "0.1.0" dependencies = [ "reqwest", - "tokio", + "serde", + "serde_json", ] diff --git a/Cargo.toml b/Cargo.toml index 4107b4e..9b4ba8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,5 @@ edition = "2021" [dependencies] reqwest = { version = "0.11", features = ["blocking", "json", "gzip"] } -tokio = { version = "1.15", features = ["full"] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" diff --git a/src/main.rs b/src/main.rs index 6e051f4..7fd590b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,15 @@ -use reqwest::Result; +#![allow(unused)] -#[tokio::main] -async fn main() -> Result<()> { +struct WordOfTheDay { + word: String, + category: String, +} + +fn main() -> Result<(), Box> { let api_key = std::env::var("WORDNIK_API_KEY").unwrap(); - let url = "https://api.wordnik.com/v4/words.json/randomWord?api_key=".to_owned() + &api_key; - let response = reqwest::get(url).await?; - let body = response.text().await?; - println!("{}", body); + let url = "https://api.wordnik.com/v4/words.json/wordOfTheDay?api_key=".to_owned() + &api_key; + let response = reqwest::blocking::get(url)?.text()?; + let json: serde_json::Value = serde_json::from_str(&response)?; + println!("{:#?}", json); Ok(()) }