fishpi_sdk/client/
breezemoon.rs1use crate::client::FishPi;
4use crate::domain::breezemoon::Breezemoon;
5use crate::ids::UserName;
6use crate::utils::build_http_path;
7use crate::utils::error::Error;
8use crate::wire::breezemoon::WireBreezemoonList;
9
10pub struct BreezemoonApi(pub(crate) FishPi);
12
13impl FishPi {
14 pub fn breezemoon(&self) -> BreezemoonApi {
16 BreezemoonApi(self.clone())
17 }
18}
19
20impl BreezemoonApi {
21 pub async fn list(
27 &self,
28 page: u32,
29 size: u32,
30 user: Option<impl Into<UserName>>,
31 ) -> Result<Vec<Breezemoon>, Error> {
32 let base = if let Some(u) = user {
33 format!("user/{}/", u.into())
34 } else {
35 String::new()
36 };
37 let path = build_http_path(
38 &format!("api/{}breezemoons", base),
39 &[
40 ("p", page.to_string()),
41 ("size", size.to_string()),
42 ("apiKey", self.0.api_key().to_string()),
43 ],
44 );
45 let wire: WireBreezemoonList = self.0.get_data(&path).await?;
46 Ok(wire.breezemoons.into_iter().map(Breezemoon::from).collect())
47 }
48
49 pub async fn send(&self, content: impl Into<String>) -> Result<(), Error> {
51 let body = serde_json::json!({
52 "apiKey": self.0.api_key().as_str(),
53 "breezemoonContent": content.into(),
54 });
55 self.0.post_raw("breezemoon", &body).await?;
56 Ok(())
57 }
58}