sidemash/
stream_square_service.rs

1/*
2   Copyright © 2020 Sidemash Cloud Services
3
4   Licensed under the Apache  License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless  required  by  applicable  law  or  agreed to in writing,
11   software  distributed  under  the  License  is distributed on an
12   "AS IS"  BASIS, WITHOUT  WARRANTIES  OR CONDITIONS OF  ANY KIND,
13   either  express  or  implied.  See the License for the  specific
14   language governing permissions and limitations under the License.
15*/
16
17
18use 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}