netlify_rust/apis/
hook_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateHookBySiteIdError {
22 DefaultResponse(crate::models::Error),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteHookError {
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum EnableHookError {
37 DefaultResponse(crate::models::Error),
38 UnknownValue(serde_json::Value),
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum GetHookError {
45 DefaultResponse(crate::models::Error),
46 UnknownValue(serde_json::Value),
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum ListHooksBySiteIdError {
53 DefaultResponse(crate::models::Error),
54 UnknownValue(serde_json::Value),
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum UpdateHookError {
61 DefaultResponse(crate::models::Error),
62 UnknownValue(serde_json::Value),
63}
64
65
66pub async fn create_hook_by_site_id(configuration: &configuration::Configuration, site_id: &str, hook: crate::models::Hook) -> Result<crate::models::Hook, Error<CreateHookBySiteIdError>> {
67
68 let local_var_client = &configuration.client;
69
70 let local_var_uri_str = format!("{}/hooks", configuration.base_path);
71 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
72
73 local_var_req_builder = local_var_req_builder.query(&[("site_id", &site_id.to_string())]);
74 if let Some(ref local_var_user_agent) = configuration.user_agent {
75 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
76 }
77 if let Some(ref local_var_token) = configuration.oauth_access_token {
78 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
79 };
80 local_var_req_builder = local_var_req_builder.json(&hook);
81
82 let local_var_req = local_var_req_builder.build()?;
83 let local_var_resp = local_var_client.execute(local_var_req).await?;
84
85 let local_var_status = local_var_resp.status();
86 let local_var_content = local_var_resp.text().await?;
87
88 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
89 serde_json::from_str(&local_var_content).map_err(Error::from)
90 } else {
91 let local_var_entity: Option<CreateHookBySiteIdError> = serde_json::from_str(&local_var_content).ok();
92 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
93 Err(Error::ResponseError(local_var_error))
94 }
95}
96
97pub async fn delete_hook(configuration: &configuration::Configuration, hook_id: &str) -> Result<(), Error<DeleteHookError>> {
98
99 let local_var_client = &configuration.client;
100
101 let local_var_uri_str = format!("{}/hooks/{hook_id}", configuration.base_path, hook_id=crate::apis::urlencode(hook_id));
102 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
103
104 if let Some(ref local_var_user_agent) = configuration.user_agent {
105 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
106 }
107 if let Some(ref local_var_token) = configuration.oauth_access_token {
108 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
109 };
110
111 let local_var_req = local_var_req_builder.build()?;
112 let local_var_resp = local_var_client.execute(local_var_req).await?;
113
114 let local_var_status = local_var_resp.status();
115 let local_var_content = local_var_resp.text().await?;
116
117 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
118 Ok(())
119 } else {
120 let local_var_entity: Option<DeleteHookError> = serde_json::from_str(&local_var_content).ok();
121 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
122 Err(Error::ResponseError(local_var_error))
123 }
124}
125
126pub async fn enable_hook(configuration: &configuration::Configuration, hook_id: &str) -> Result<crate::models::Hook, Error<EnableHookError>> {
127
128 let local_var_client = &configuration.client;
129
130 let local_var_uri_str = format!("{}/hooks/{hook_id}/enable", configuration.base_path, hook_id=crate::apis::urlencode(hook_id));
131 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
132
133 if let Some(ref local_var_user_agent) = configuration.user_agent {
134 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
135 }
136 if let Some(ref local_var_token) = configuration.oauth_access_token {
137 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
138 };
139
140 let local_var_req = local_var_req_builder.build()?;
141 let local_var_resp = local_var_client.execute(local_var_req).await?;
142
143 let local_var_status = local_var_resp.status();
144 let local_var_content = local_var_resp.text().await?;
145
146 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
147 serde_json::from_str(&local_var_content).map_err(Error::from)
148 } else {
149 let local_var_entity: Option<EnableHookError> = serde_json::from_str(&local_var_content).ok();
150 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
151 Err(Error::ResponseError(local_var_error))
152 }
153}
154
155pub async fn get_hook(configuration: &configuration::Configuration, hook_id: &str) -> Result<crate::models::Hook, Error<GetHookError>> {
156
157 let local_var_client = &configuration.client;
158
159 let local_var_uri_str = format!("{}/hooks/{hook_id}", configuration.base_path, hook_id=crate::apis::urlencode(hook_id));
160 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
161
162 if let Some(ref local_var_user_agent) = configuration.user_agent {
163 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
164 }
165 if let Some(ref local_var_token) = configuration.oauth_access_token {
166 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
167 };
168
169 let local_var_req = local_var_req_builder.build()?;
170 let local_var_resp = local_var_client.execute(local_var_req).await?;
171
172 let local_var_status = local_var_resp.status();
173 let local_var_content = local_var_resp.text().await?;
174
175 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
176 serde_json::from_str(&local_var_content).map_err(Error::from)
177 } else {
178 let local_var_entity: Option<GetHookError> = serde_json::from_str(&local_var_content).ok();
179 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
180 Err(Error::ResponseError(local_var_error))
181 }
182}
183
184pub async fn list_hooks_by_site_id(configuration: &configuration::Configuration, site_id: &str) -> Result<Vec<crate::models::Hook>, Error<ListHooksBySiteIdError>> {
185
186 let local_var_client = &configuration.client;
187
188 let local_var_uri_str = format!("{}/hooks", configuration.base_path);
189 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
190
191 local_var_req_builder = local_var_req_builder.query(&[("site_id", &site_id.to_string())]);
192 if let Some(ref local_var_user_agent) = configuration.user_agent {
193 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
194 }
195 if let Some(ref local_var_token) = configuration.oauth_access_token {
196 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
197 };
198
199 let local_var_req = local_var_req_builder.build()?;
200 let local_var_resp = local_var_client.execute(local_var_req).await?;
201
202 let local_var_status = local_var_resp.status();
203 let local_var_content = local_var_resp.text().await?;
204
205 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
206 serde_json::from_str(&local_var_content).map_err(Error::from)
207 } else {
208 let local_var_entity: Option<ListHooksBySiteIdError> = serde_json::from_str(&local_var_content).ok();
209 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
210 Err(Error::ResponseError(local_var_error))
211 }
212}
213
214pub async fn update_hook(configuration: &configuration::Configuration, hook_id: &str, hook: crate::models::Hook) -> Result<crate::models::Hook, Error<UpdateHookError>> {
215
216 let local_var_client = &configuration.client;
217
218 let local_var_uri_str = format!("{}/hooks/{hook_id}", configuration.base_path, hook_id=crate::apis::urlencode(hook_id));
219 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
220
221 if let Some(ref local_var_user_agent) = configuration.user_agent {
222 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
223 }
224 if let Some(ref local_var_token) = configuration.oauth_access_token {
225 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
226 };
227 local_var_req_builder = local_var_req_builder.json(&hook);
228
229 let local_var_req = local_var_req_builder.build()?;
230 let local_var_resp = local_var_client.execute(local_var_req).await?;
231
232 let local_var_status = local_var_resp.status();
233 let local_var_content = local_var_resp.text().await?;
234
235 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
236 serde_json::from_str(&local_var_content).map_err(Error::from)
237 } else {
238 let local_var_entity: Option<UpdateHookError> = serde_json::from_str(&local_var_content).ok();
239 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
240 Err(Error::ResponseError(local_var_error))
241 }
242}
243