From 46911f17ad33bacd285dd8d374b609eb499db8ce 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] Only add params if user adds params --- src/client.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client.rs b/src/client.rs index be4f174..af44784 100644 --- a/src/client.rs +++ b/src/client.rs @@ -41,15 +41,15 @@ impl<'a> Client<'a> { pub async fn list_posts(&mut self, limit: Option, tags: Option>, page: Option) -> Result> { let mut url = url::Url::parse(format!("{}/posts.json", self.host).as_str())?; - let limit = limit.unwrap_or(320); - let page = page.unwrap_or(0); - let mut query_params = String::new(); - query_params.push_str("limit="); - query_params.push_str(limit.to_string().as_str()); + let mut query_params = Vec::new(); + if let Some(limit) = limit { + query_params.push(format!("limit={limit}")); + } - query_params.push_str("page="); - query_params.push_str(page.to_string().as_str()); + if let Some(page) = page { + query_params.push(format!("page={page}")); + } if let Some(tags) = tags { if tags.len() > 0 {