Skip to content

Commit

Permalink
Add options.urlencoded() for deepgram::manage::usage options types
Browse files Browse the repository at this point in the history
  • Loading branch information
jcdyer committed Jul 23, 2024
1 parent a8cde93 commit ec9060e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/manage/usage/get_fields_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, serde_urlencoded::ser::Error> {
serde_urlencoded::to_string(SerializableOptions::from(self))
}
}

impl OptionsBuilder {
Expand Down
19 changes: 19 additions & 0 deletions src/manage/usage/get_usage_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, serde_urlencoded::ser::Error> {
serde_urlencoded::to_string(SerializableOptions::from(self))
}

}

impl OptionsBuilder {
Expand Down
19 changes: 19 additions & 0 deletions src/manage/usage/list_requests_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, serde_urlencoded::ser::Error> {
serde_urlencoded::to_string(SerializableOptions::from(self))
}
}

impl OptionsBuilder {
Expand Down

0 comments on commit ec9060e

Please sign in to comment.