sidemash/
stream_square_service.rs1use crate::auth::Auth;
19use crate::create_stream_square_form::CreateStreamSquareForm;
20use crate::http::*;
21use crate::http;
22use crate::list_form::ListForm;
23use crate::rest_collection::RestCollection;
24use crate::stream_square::StreamSquare;
25use crate::update_stream_square_form::UpdateStreamSquareForm;
26use serde::{Serialize, Deserialize};
27
28
29type Error = Box<dyn std::error::Error>;
30type Result<T, E = Error> = std::result::Result<T, E>;
31
32#[derive(Serialize, Hash, Eq, PartialEq, Debug)]
33#[serde(rename_all = "camelCase")]
34pub struct StreamSquareService<'a> {
35 pub auth : &'a Auth
36}
37
38impl StreamSquareService<'_> {
39 pub fn new(auth: &Auth) -> StreamSquareService {
40 StreamSquareService{auth}
41 }
42
43 pub async fn create(&self, form: &CreateStreamSquareForm) -> Result<StreamSquare> {
44 post(&*("/".to_owned() + VERSION + "/stream-squares"), &vec![], &vec![], Some(form.to_json()), self.auth).await
45 }
46
47 pub async fn get(&self, id: &String) -> Result<StreamSquare> {
48 get(&*("/".to_owned() + VERSION + "/stream-squares/" + id), &vec![], &vec![], self.auth).await
49 }
50
51 pub async fn list(&self) -> Result<RestCollection<StreamSquare>> {
52 http::list(&*("/".to_owned() + VERSION + "/stream-squares"), &vec![], &vec![], self.auth).await
53 }
54
55 pub async fn list_with(&self, form: &ListForm<'_>) -> Result<RestCollection<StreamSquare>> {
56 http::list(&*("/".to_owned() + VERSION + "/stream-squares"), &vec![], &form.to_query_string(), self.auth).await
57 }
58
59 pub async fn update(&self, form: &UpdateStreamSquareForm) -> Result<StreamSquare> {
60 patch(&*("/".to_owned() + VERSION + "/stream-squares/" + form.id.as_str()), &vec![], &vec![], Some(form.to_json()), self.auth).await
61 }
62
63 pub async fn delete(&self, id: &String) -> Result<()> {
64 delete(&*("/".to_owned() + VERSION + "/stream-squares/" + id), &vec![], &vec![], None, self.auth).await
65 }
66}