Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support options debug #78

Merged
merged 6 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/common/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,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::common::options::{DetectLanguage, Model, Options};
/// let options = Options::builder()
/// .model(Model::Nova2)
/// .detect_language(DetectLanguage::Enabled)
/// .build();
/// assert_eq!(&options.urlencoded().unwrap(), "model=nova-2&detect_language=true")
/// ```
///
pub fn urlencoded(&self) -> Result<String, serde_urlencoded::ser::Error> {
serde_urlencoded::to_string(SerializableOptions(self))
}
}

impl OptionsBuilder {
Expand Down
21 changes: 20 additions & 1 deletion src/manage/keys/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ impl Options {
) -> OptionsBuilder {
OptionsBuilder::new(comment, scopes)
}

/// Return the Options in json format. If serialization would
/// fail, this will also return an error.
///
/// This is intended primarily to help with debugging API requests.
///
/// ```
/// use deepgram::manage::keys::options::Options;
/// let options = Options::builder("API Key", ["member"])
/// .tag(["my-tag", "another-tag"])
/// .build();
/// assert_eq!(
/// &options.json().unwrap(),
/// r#"{"comment":"API Key","tags":["my-tag","another-tag"],"scopes":["member"]}"#)
/// ```
///
pub fn json(&self) -> Result<String, serde_json::Error> {
serde_json::to_string(&SerializableOptions::from(self))
}
}

impl OptionsBuilder {
Expand Down Expand Up @@ -110,7 +129,7 @@ impl OptionsBuilder {
/// #
/// let options1 = Options::builder("New Key", ["member"])
/// .tag(["Tag 1"])
/// .tag(["Tag 2"])
/// .tag(vec!["Tag 2"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to document that this function can take different kinds of iterables.

/// .build();
///
/// let options2 = Options::builder("New Key", ["member"])
Expand Down
6 changes: 3 additions & 3 deletions src/manage/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Projects<'_> {
/// ```no_run
/// # use std::env;
/// #
/// # use deepgram::{manage::projects::options::Options, Deepgram, DeepgramError};
/// # use deepgram::{Deepgram, DeepgramError};
/// #
/// # #[tokio::main]
/// # async fn main() -> Result<(), DeepgramError> {
Expand Down Expand Up @@ -86,7 +86,7 @@ impl Projects<'_> {
/// ```no_run
/// # use std::env;
/// #
/// # use deepgram::{manage::projects::options::Options, Deepgram, DeepgramError};
/// # use deepgram::{Deepgram, DeepgramError};
/// #
/// # #[tokio::main]
/// # async fn main() -> Result<(), DeepgramError> {
Expand Down Expand Up @@ -170,7 +170,7 @@ impl Projects<'_> {
/// ```no_run
/// # use std::env;
/// #
/// # use deepgram::{manage::projects::options::Options, Deepgram, DeepgramError};
/// # use deepgram::{Deepgram, DeepgramError};
/// #
/// # #[tokio::main]
/// # async fn main() -> Result<(), DeepgramError> {
Expand Down
20 changes: 20 additions & 0 deletions src/manage/projects/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ impl Options {
pub fn builder() -> OptionsBuilder {
OptionsBuilder::new()
}

/// Return the Options in json format. If serialization would
/// fail, this will also return an error.
///
/// This is intended primarily to help with debugging API requests.
///
/// ```
/// use deepgram::manage::projects::options::Options;
/// let options = Options::builder()
/// .company("Deepgram")
/// .name("DG Project")
/// .build();
/// assert_eq!(
/// &options.json().unwrap(),
/// r#"{"name":"DG Project","company":"Deepgram"}"#)
/// ```
///
pub fn json(&self) -> Result<String, serde_json::Error> {
serde_json::to_string(&SerializableOptions::from(self))
}
}

impl OptionsBuilder {
Expand Down
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
18 changes: 18 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,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_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
18 changes: 18 additions & 0 deletions src/speak/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,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::speak::options::{Encoding, Model, Options};
/// let options = Options::builder()
/// .model(Model::AuraArcasEn)
/// .encoding(Encoding::Flac)
/// .build();
/// assert_eq!(&options.urlencoded().unwrap(), "model=aura-arcas-en&encoding=flac")
/// ```
///
pub fn urlencoded(&self) -> Result<String, serde_urlencoded::ser::Error> {
serde_urlencoded::to_string(SerializableOptions(self))
}
}

impl OptionsBuilder {
Expand Down
Loading