From 74338fe59de7e3f4a8fdc8f884ebf2957ce825bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Gr=C3=BCnewald?= Date: Mon, 1 Jan 2024 21:50:57 +0100 Subject: [PATCH] Add debug feature to dump requests --- Cargo.toml | 2 ++ src/client.rs | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6cbd57e..eda8684 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,5 @@ serde_json = "1.0.108" thiserror = "1.0.52" url = "2.5.0" +[features] +dump = [] \ No newline at end of file diff --git a/src/client.rs b/src/client.rs index c423b17..0fce8c9 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,3 +1,4 @@ +use std::io::Write; use crate::post::{Post, Posts}; use anyhow::Result; use base64::{engine::GeneralPurpose, Engine}; @@ -75,13 +76,13 @@ impl<'a> Client<'a> { let res = self.list_posts_raw(limit, tags, page).await?; let text = res.text().await?; - /* - let mut debug_file = std::fs::OpenOptions::new() - .write(true) - .create(true) - .open("./debug.json")?; - debug_file.write_all(text.as_bytes())?; - */ + if cfg!(debug) { + let mut debug_file = std::fs::OpenOptions::new() + .write(true) + .create(true) + .open("/tmp/debug.json")?; + debug_file.write_all(text.as_bytes())?; + } Ok(serde_json::from_str::(text.as_str())?.into()) }