diff --git a/src/manage/usage/get_fields_options.rs b/src/manage/usage/get_fields_options.rs index fd219bc7..3ca5c65e 100644 --- a/src/manage/usage/get_fields_options.rs +++ b/src/manage/usage/get_fields_options.rs @@ -37,6 +37,24 @@ impl Options { pub fn builder() -> OptionsBuilder { OptionsBuilder::new() } + + /// Return the Options in urlencoded format. If serialization would + /// fail, this will also return an error. + /// + /// This is intended primarily to help with debugging API requests. + /// + /// ``` + /// use deepgram::manage::usage::get_fields_options::Options; + /// let options = Options::builder() + /// .start("2024-04-10T00:00:00Z") + /// .end("2024-10-10") + /// .build(); + /// assert_eq!(&options.urlencoded().unwrap(), "start=2024-04-10T00%3A00%3A00Z&end=2024-10-10") + /// ``` + /// + pub fn urlencoded(&self) -> Result { + serde_urlencoded::to_string(SerializableOptions::from(self)) + } } impl OptionsBuilder { diff --git a/src/manage/usage/get_usage_options.rs b/src/manage/usage/get_usage_options.rs index 52fce37f..433c933e 100644 --- a/src/manage/usage/get_usage_options.rs +++ b/src/manage/usage/get_usage_options.rs @@ -61,6 +61,25 @@ impl Options { pub fn builder() -> OptionsBuilder { OptionsBuilder::new() } + + /// Return the Options in urlencoded format. If serialization would + /// fail, this will also return an error. + /// + /// This is intended primarily to help with debugging API requests. + /// + /// ``` + /// use deepgram::manage::usage::get_usage_options::{Options, Method}; + /// let options = Options::builder() + /// .method([Method::Sync, Method::Async]) + /// .ner(true) + /// .build(); + /// assert_eq!(&options.urlencoded().unwrap(), "method=sync&method=async&ner=true") + /// ``` + /// + pub fn urlencoded(&self) -> Result { + serde_urlencoded::to_string(SerializableOptions::from(self)) + } + } impl OptionsBuilder { diff --git a/src/manage/usage/list_requests_options.rs b/src/manage/usage/list_requests_options.rs index c2edf11c..fc940ace 100644 --- a/src/manage/usage/list_requests_options.rs +++ b/src/manage/usage/list_requests_options.rs @@ -56,6 +56,25 @@ impl Options { pub fn builder() -> OptionsBuilder { OptionsBuilder::new() } + + /// Return the Options in urlencoded format. If serialization would + /// fail, this will also return an error. + /// + /// This is intended primarily to help with debugging API requests. + /// + /// ``` + /// use deepgram::manage::usage::list_requests_options::Options; + /// let options = Options::builder() + /// .start("2024-04-10T00:00:00Z") + /// .end("2024-10-10") + /// .limit(100) + /// .build(); + /// assert_eq!(&options.urlencoded().unwrap(), "start=2024-04-10T00%3A00%3A00Z&end=2024-10-10&limit=100") + /// ``` + /// + pub fn urlencoded(&self) -> Result { + serde_urlencoded::to_string(SerializableOptions::from(self)) + } } impl OptionsBuilder {