rule34/client/
note_list_query_builder.rs1use crate::{
2 Client,
3 Error,
4 NoteList,
5};
6use std::num::NonZeroU64;
7use url::Url;
8
9#[derive(Debug)]
13pub struct NotesListQueryBuilder<'a> {
14 pub post_id: Option<NonZeroU64>,
18
19 client: &'a Client,
21}
22
23impl<'a> NotesListQueryBuilder<'a> {
24 pub fn new(client: &'a Client) -> Self {
26 Self {
27 post_id: None,
28
29 client,
30 }
31 }
32
33 pub fn post_id(&mut self, post_id: Option<NonZeroU64>) -> &mut Self {
37 self.post_id = post_id;
38 self
39 }
40
41 pub fn get_url(&self) -> Result<Url, Error> {
43 let mut url = Url::parse_with_params(
44 crate::API_BASE_URL,
45 &[("page", "dapi"), ("s", "note"), ("q", "index")],
46 )?;
47
48 {
49 let mut query_pairs_mut = url.query_pairs_mut();
50
51 let auth = self.client.get_auth();
52 let auth = auth.as_ref().ok_or(Error::MissingAuth)?;
53 query_pairs_mut.append_pair("user_id", itoa::Buffer::new().format(auth.user_id));
54 query_pairs_mut.append_pair("api_key", &auth.api_key);
55
56 if let Some(post_id) = self.post_id {
57 let mut buffer = itoa::Buffer::new();
58 query_pairs_mut.append_pair("post_id", buffer.format(post_id.get()));
59 }
60 }
61
62 Ok(url)
63 }
64
65 pub async fn execute(&self) -> Result<NoteList, Error> {
67 let url = self.get_url()?;
68
69 self.client.get_xml(url.as_str()).await
70 }
71}