floopy/resources/
constraints.rs1use std::sync::Arc;
2
3use reqwest::Method;
4
5use crate::constants::ENDPOINT_CONSTRAINTS;
6use crate::error::Result;
7use crate::http::HttpTransport;
8use crate::options::RequestOptions;
9use crate::types::OrgConstraints;
10
11use super::require;
12
13pub struct Constraints {
15 t: Arc<HttpTransport>,
16}
17
18impl Constraints {
19 pub(crate) fn new(t: Arc<HttpTransport>) -> Self {
20 Self { t }
21 }
22
23 pub async fn get(&self, req: impl Into<Option<RequestOptions>>) -> Result<OrgConstraints> {
29 let (data, _) = self
30 .t
31 .request(
32 Method::GET,
33 ENDPOINT_CONSTRAINTS,
34 None,
35 &[],
36 req.into().as_ref(),
37 )
38 .await?;
39 require(data)
40 }
41
42 pub async fn put(
49 &self,
50 constraints: &OrgConstraints,
51 req: impl Into<Option<RequestOptions>>,
52 ) -> Result<OrgConstraints> {
53 let body =
54 serde_json::to_value(constraints).map_err(|e| crate::Error::Decode(e.to_string()))?;
55 let (data, _) = self
56 .t
57 .request(
58 Method::PUT,
59 ENDPOINT_CONSTRAINTS,
60 Some(&body),
61 &[],
62 req.into().as_ref(),
63 )
64 .await?;
65 require(data)
66 }
67}