From 1e94c092e75c5d808a42ed83067eda92c6deab70 Mon Sep 17 00:00:00 2001 From: Carter Gividen Date: Mon, 13 Oct 2025 11:31:34 -0600 Subject: [PATCH 1/2] Add custom query option. --- smarty-rust-sdk/src/sdk/client.rs | 6 ++++++ smarty-rust-sdk/src/sdk/options.rs | 34 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/smarty-rust-sdk/src/sdk/client.rs b/smarty-rust-sdk/src/sdk/client.rs index 22b92be..7adcc83 100644 --- a/smarty-rust-sdk/src/sdk/client.rs +++ b/smarty-rust-sdk/src/sdk/client.rs @@ -68,6 +68,12 @@ impl Client { format!("smarty (sdk:rust@{})", VERSION), ); + if !self.options.custom_queries.is_none() { + for (key, value) in self.options.custom_queries.clone().unwrap() { + builder = builder.query(&[(key, value)]); + } + } + builder } } diff --git a/smarty-rust-sdk/src/sdk/options.rs b/smarty-rust-sdk/src/sdk/options.rs index 66b3a99..b823b20 100644 --- a/smarty-rust-sdk/src/sdk/options.rs +++ b/smarty-rust-sdk/src/sdk/options.rs @@ -1,3 +1,4 @@ +use std::{collections::HashMap}; use reqwest::Proxy; use url::Url; @@ -20,6 +21,7 @@ pub struct OptionsBuilder { logging_enabled: bool, headers: Vec<(String, String)>, authentication: Option>, + custom_queries: Option>, url: Option, @@ -37,6 +39,7 @@ impl OptionsBuilder { logging_enabled: false, headers: vec![], authentication, + custom_queries: None, url: None, @@ -53,6 +56,7 @@ impl OptionsBuilder { logging_enabled: self.logging_enabled, headers: self.headers, authentication: self.authentication, + custom_queries: self.custom_queries, url: self.url, @@ -95,6 +99,32 @@ impl OptionsBuilder { self.proxy = Some(proxy); self } + + /// Adds a custom query to the request. + pub fn with_custom_query(mut self, key: &str, value: &str) -> Self { + self.custom_queries.get_or_insert_with(HashMap::new).insert(key.to_string(), value.to_string()); + self + } + + /// Appends a custom set of values to the existing query parameter. + pub fn with_custom_comma_separated_query(mut self, key: &str, value: &str) -> Self { + self.custom_queries + .get_or_insert_with(HashMap::new) + .entry(key.to_string()) + .and_modify(|existing| { + if !existing.is_empty() { + existing.push(','); + } + existing.push_str(value); + }) + .or_insert_with(|| value.to_string()); + self + } + + /// Adds component analysis feature to the request. + pub fn with_component_analysis(self) -> Self { + self.with_custom_comma_separated_query("features", "component-analysis") + } } /// Options that can be passed into a new client @@ -117,6 +147,9 @@ pub struct Options { // Authentication pub(crate) authentication: Option>, + // Custom Queries + pub(crate) custom_queries: Option>, + // Url pub(crate) url: Option, @@ -132,6 +165,7 @@ impl Clone for Options { logging_enabled: self.logging_enabled, headers: self.headers.clone(), authentication: self.authentication.as_ref().map(|x| x.clone_box()), + custom_queries: self.custom_queries.clone(), url: self.url.clone(), proxy: self.proxy.clone(), } From bdfb47d0e3f15f36fc39676551454a6b93bf4400 Mon Sep 17 00:00:00 2001 From: Carter Gividen Date: Fri, 17 Oct 2025 13:31:48 -0600 Subject: [PATCH 2/2] Follow best practices. --- smarty-rust-sdk/src/sdk/client.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smarty-rust-sdk/src/sdk/client.rs b/smarty-rust-sdk/src/sdk/client.rs index 7adcc83..05b7319 100644 --- a/smarty-rust-sdk/src/sdk/client.rs +++ b/smarty-rust-sdk/src/sdk/client.rs @@ -68,8 +68,8 @@ impl Client { format!("smarty (sdk:rust@{})", VERSION), ); - if !self.options.custom_queries.is_none() { - for (key, value) in self.options.custom_queries.clone().unwrap() { + if let Some(queries) = self.options.custom_queries.clone() { + for (key, value) in queries { builder = builder.query(&[(key, value)]); } }