use std::collections::HashMap;
#[derive(Debug, Default)]
pub struct RequestBuilder {
args: HashMap<String, String>,
}
impl RequestBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn add_arg(&mut self, key: impl ToString, value: impl ToString) {
self.args.insert(key.to_string(), value.to_string());
}
pub fn add_arg_opt(&mut self, key: impl ToString, value: Option<impl ToString>) {
if let Some(value) = value {
self.add_arg(key, value)
}
}
pub fn build_request(self) -> String {
let args = self.args.into_iter().collect::<Vec<(_, _)>>();
let args = serde_urlencoded::to_string(&args).expect("encode args should never fail");
args
}
}