use crate::{
Client,
Error,
NoteList,
};
use std::num::NonZeroU64;
use url::Url;
#[derive(Debug)]
pub struct NotesListQueryBuilder<'a> {
pub post_id: Option<NonZeroU64>,
client: &'a Client,
}
impl<'a> NotesListQueryBuilder<'a> {
pub fn new(client: &'a Client) -> Self {
Self {
post_id: None,
client,
}
}
pub fn post_id(&mut self, post_id: Option<NonZeroU64>) -> &mut Self {
self.post_id = post_id;
self
}
pub fn get_url(&self) -> Result<Url, Error> {
let mut url = Url::parse_with_params(
crate::API_BASE_URL,
&[("page", "dapi"), ("s", "note"), ("q", "index")],
)?;
{
let mut query_pairs = url.query_pairs_mut();
if let Some(post_id) = self.post_id {
let mut buffer = itoa::Buffer::new();
query_pairs.append_pair("post_id", buffer.format(post_id.get()));
}
}
Ok(url)
}
pub async fn execute(&self) -> Result<NoteList, Error> {
let url = self.get_url()?;
self.client.get_xml(url.as_str()).await
}
}