use elicitation::elicit_newtype;
use elicitation_derive::reflect_methods;
use crate::{Error, Response};
elicit_newtype!(reqwest::RequestBuilder, as RequestBuilder);
#[reflect_methods]
impl RequestBuilder {
pub fn timeout(self, timeout: std::time::Duration) -> Self {
let inner = std::sync::Arc::try_unwrap(self.0)
.expect("Consuming method requires exclusive ownership");
inner.timeout(timeout).into()
}
pub fn bearer_auth(self, token: String) -> Self {
let inner = std::sync::Arc::try_unwrap(self.0)
.expect("Consuming method requires exclusive ownership");
inner.bearer_auth(token).into()
}
pub fn basic_auth(self, username: String, password: Option<String>) -> Self {
let inner = std::sync::Arc::try_unwrap(self.0)
.expect("Consuming method requires exclusive ownership");
inner.basic_auth(username, password).into()
}
pub fn header(self, key: String, value: String) -> Self {
let inner = std::sync::Arc::try_unwrap(self.0)
.expect("Consuming method requires exclusive ownership");
inner.header(key, value).into()
}
pub fn json<T>(self, value: &T) -> Self
where
T: elicitation::Elicitation + schemars::JsonSchema + serde::Serialize,
{
let inner = std::sync::Arc::try_unwrap(self.0)
.expect("Consuming method requires exclusive ownership");
inner.json(value).into()
}
pub async fn send(self) -> Result<Response, Error> {
let inner = std::sync::Arc::try_unwrap(self.0)
.expect("Consuming method requires exclusive ownership");
inner.send().await.map(Response::from).map_err(Error::from)
}
}