#![allow(clippy::too_many_arguments)]
use crate::client::Client;
use crate::error::Error;
use crate::generated::routes;
use crate::generated::types::*;
use crate::pagination::Page;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListDraftsParams {
pub page: Option<String>,
}
pub struct Entries<'a> {
client: &'a Client,
}
impl<'a> Entries<'a> {
pub(crate) fn new(client: &'a Client) -> Self {
Self { client }
}
pub fn client(&self) -> &'a Client {
self.client
}
pub async fn create_reply(
&self,
entry_id: i64,
body: &CreateReplyRequestContent,
) -> Result<(), Error> {
let mut operation = self.client.operation(&routes::CREATE_REPLY, &[&entry_id]);
operation.resource_id(entry_id);
operation.json(body)?;
self.client.send_unit(operation).await
}
pub async fn delete_draft(&self, entry_id: i64) -> Result<(), Error> {
let mut operation = self.client.operation(&routes::DELETE_DRAFT, &[&entry_id]);
operation.resource_id(entry_id);
self.client.send_unit(operation).await
}
pub async fn list_drafts(
&self,
params: &ListDraftsParams,
) -> Result<Page<ListDraftsResponseContent>, Error> {
let mut operation = self.client.operation(&routes::LIST_DRAFTS, &[]);
operation.query_optional("page", params.page.as_ref());
self.client.send_page(operation).await
}
pub async fn mark_spam(&self, entry_id: i64) -> Result<(), Error> {
let mut operation = self
.client
.operation(&routes::MARK_ENTRY_SPAM, &[&entry_id]);
operation.resource_id(entry_id);
self.client.send_unit(operation).await
}
pub async fn new_forward(
&self,
entry_id: i64,
) -> Result<NewEntryForwardResponseContent, Error> {
let mut operation = self
.client
.operation(&routes::NEW_ENTRY_FORWARD, &[&entry_id]);
operation.resource_id(entry_id);
self.client.send(operation).await
}
pub async fn new_reply(&self, entry_id: i64) -> Result<NewEntryReplyResponseContent, Error> {
let mut operation = self
.client
.operation(&routes::NEW_ENTRY_REPLY, &[&entry_id]);
operation.resource_id(entry_id);
self.client.send(operation).await
}
}