1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Rules {
6 pub client: Client,
7}
8
9impl Rules {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "List rule\n\nList the rules of the company.\n\n```rust,no_run\nasync fn \
16 example_rules_list() -> anyhow::Result<()> {\n let client = \
17 front_api::Client::new_from_env();\n let result: \
18 front_api::types::ListRulesResponse = client.rules().list().await?;\n \
19 println!(\"{:?}\", result);\n Ok(())\n}\n```"]
20 #[tracing::instrument]
21 pub async fn list<'a>(
22 &'a self,
23 ) -> Result<crate::types::ListRulesResponse, crate::types::error::Error> {
24 let mut req = self.client.client.request(
25 http::Method::GET,
26 &format!("{}/{}", self.client.base_url, "rules"),
27 );
28 req = req.bearer_auth(&self.client.token);
29 let resp = req.send().await?;
30 let status = resp.status();
31 if status.is_success() {
32 let text = resp.text().await.unwrap_or_default();
33 serde_json::from_str(&text).map_err(|err| {
34 crate::types::error::Error::from_serde_error(
35 format_serde_error::SerdeError::new(text.to_string(), err),
36 status,
37 )
38 })
39 } else {
40 Err(crate::types::error::Error::UnexpectedResponse(resp))
41 }
42 }
43
44 #[doc = "List team rules\n\nList the rules of a team.\n\n**Parameters:**\n\n- `team_id: &'astr`: The team ID (required)\n\n```rust,no_run\nasync fn example_rules_list_team() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::ListTeamRulesResponse =\n client.rules().list_team(\"some-string\").await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
45 #[tracing::instrument]
46 pub async fn list_team<'a>(
47 &'a self,
48 team_id: &'a str,
49 ) -> Result<crate::types::ListTeamRulesResponse, crate::types::error::Error> {
50 let mut req = self.client.client.request(
51 http::Method::GET,
52 &format!(
53 "{}/{}",
54 self.client.base_url,
55 "teams/{team_id}/rules".replace("{team_id}", team_id)
56 ),
57 );
58 req = req.bearer_auth(&self.client.token);
59 let resp = req.send().await?;
60 let status = resp.status();
61 if status.is_success() {
62 let text = resp.text().await.unwrap_or_default();
63 serde_json::from_str(&text).map_err(|err| {
64 crate::types::error::Error::from_serde_error(
65 format_serde_error::SerdeError::new(text.to_string(), err),
66 status,
67 )
68 })
69 } else {
70 Err(crate::types::error::Error::UnexpectedResponse(resp))
71 }
72 }
73
74 #[doc = "List teammate rule\n\nList the rules of a teammate.\n\n**Parameters:**\n\n- \
75 `teammate_id: &'astr`: The teammate ID (required)\n\n```rust,no_run\nasync fn \
76 example_rules_list_teammate() -> anyhow::Result<()> {\n let client = \
77 front_api::Client::new_from_env();\n let result: \
78 front_api::types::ListTeammateRulesResponse =\n \
79 client.rules().list_teammate(\"some-string\").await?;\n println!(\"{:?}\", \
80 result);\n Ok(())\n}\n```"]
81 #[tracing::instrument]
82 pub async fn list_teammate<'a>(
83 &'a self,
84 teammate_id: &'a str,
85 ) -> Result<crate::types::ListTeammateRulesResponse, crate::types::error::Error> {
86 let mut req = self.client.client.request(
87 http::Method::GET,
88 &format!(
89 "{}/{}",
90 self.client.base_url,
91 "teammates/{teammate_id}/rules".replace("{teammate_id}", teammate_id)
92 ),
93 );
94 req = req.bearer_auth(&self.client.token);
95 let resp = req.send().await?;
96 let status = resp.status();
97 if status.is_success() {
98 let text = resp.text().await.unwrap_or_default();
99 serde_json::from_str(&text).map_err(|err| {
100 crate::types::error::Error::from_serde_error(
101 format_serde_error::SerdeError::new(text.to_string(), err),
102 status,
103 )
104 })
105 } else {
106 Err(crate::types::error::Error::UnexpectedResponse(resp))
107 }
108 }
109
110 #[doc = "Get rule\n\nFetche a rule.\n\n**Parameters:**\n\n- `rule_id: &'astr`: The Rule ID (required)\n\n```rust,no_run\nasync fn example_rules_get() -> anyhow::Result<()> {\n let client = front_api::Client::new_from_env();\n let result: front_api::types::RuleResponse = client.rules().get(\"some-string\").await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
111 #[tracing::instrument]
112 pub async fn get<'a>(
113 &'a self,
114 rule_id: &'a str,
115 ) -> Result<crate::types::RuleResponse, crate::types::error::Error> {
116 let mut req = self.client.client.request(
117 http::Method::GET,
118 &format!(
119 "{}/{}",
120 self.client.base_url,
121 "rules/{rule_id}".replace("{rule_id}", rule_id)
122 ),
123 );
124 req = req.bearer_auth(&self.client.token);
125 let resp = req.send().await?;
126 let status = resp.status();
127 if status.is_success() {
128 let text = resp.text().await.unwrap_or_default();
129 serde_json::from_str(&text).map_err(|err| {
130 crate::types::error::Error::from_serde_error(
131 format_serde_error::SerdeError::new(text.to_string(), err),
132 status,
133 )
134 })
135 } else {
136 Err(crate::types::error::Error::UnexpectedResponse(resp))
137 }
138 }
139}