use reqwest::Method;
use crate::client::LichessClient;
use crate::config::Host;
use crate::error::Result;
use crate::http;
#[derive(Debug)]
pub struct MessagingApi<'a> {
client: &'a LichessClient,
}
impl<'a> MessagingApi<'a> {
pub(crate) fn new(client: &'a LichessClient) -> Self {
Self { client }
}
pub async fn send(&self, username: &str, text: &str) -> Result<()> {
let path = format!("/inbox/{}", http::segment(username));
let request = self
.client
.request(Method::POST, Host::Default, &path)
.form(&[("text", text)]);
http::ok(request).await
}
}
impl LichessClient {
#[must_use]
pub fn messaging(&self) -> MessagingApi<'_> {
MessagingApi::new(self)
}
}