pinboard_rs/api/v1/notes/
note.rs1use crate::api::endpoint_prelude::*;
8use crate::api::v1::Limit;
9use derive_builder::Builder;
10
11#[derive(Debug, Clone, Builder)]
28pub struct Note<'a> {
29 #[builder(setter(into))]
31 id: Cow<'a, str>,
32}
33
34impl<'a> Note<'a> {
35 pub fn builder() -> NoteBuilder<'a> {
37 NoteBuilder::default()
38 }
39}
40
41impl<'a> Endpoint for Note<'a> {
42 fn method(&self) -> Method {
43 Method::GET
44 }
45
46 fn endpoint(&self) -> Cow<'static, str> {
47 format!("v1/notes/{}/", self.id).into()
48 }
49}
50
51impl<'a> Limit for Note<'a> {}
52
53#[cfg(test)]
54mod tests {
55 use crate::api::v1::notes::Note;
56 use crate::api::v1::Limit;
57 use crate::api::{self, Query};
58 use crate::test::client::{ExpectedUrl, SingleTestClient};
59
60 #[test]
61 fn id_is_required() {
62 let err = Note::builder().build().unwrap_err();
63 assert_eq!(&err.to_string(), "`id` must be initialized")
64 }
65
66 #[test]
67 fn endpoint() {
68 let endpoint = ExpectedUrl::builder()
69 .endpoint("v1/notes/IDHERE/")
70 .build()
71 .unwrap();
72 let client = SingleTestClient::new_raw(endpoint, "");
73
74 let endpoint = Note::builder().id("IDHERE").build().unwrap();
75 api::ignore(endpoint).query(&client).unwrap();
76 }
77
78 #[test]
79 fn limit() {
80 assert_eq!(Note::secs_between_calls(), 3)
81 }
82}