netlify_rust/apis/
build_hook_api.rs

1/*
2 * Netlify's API documentation
3 *
4 * Netlify is a hosting service for the programmable web. It understands your documents and provides an API to handle atomic deploys of websites, manage form submissions, inject JavaScript snippets, and much more. This is a REST-style API that uses JSON for serialization and OAuth 2 for authentication.  This document is an OpenAPI reference for the Netlify API that you can explore. For more detailed instructions for common uses, please visit the [online documentation](https://www.netlify.com/docs/api/). Visit our Community forum to join the conversation about [understanding and using Netlify’s API](https://community.netlify.com/t/common-issue-understanding-and-using-netlifys-api/160).  Additionally, we have two API clients for your convenience: - [Go Client](https://github.com/netlify/open-api#go-client) - [JS Client](https://github.com/netlify/js-client)
5 *
6 * The version of the OpenAPI document: 2.5.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method `create_site_build_hook`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateSiteBuildHookError {
22    DefaultResponse(crate::models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method `delete_site_build_hook`
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteSiteBuildHookError {
30    DefaultResponse(crate::models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `get_site_build_hook`
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetSiteBuildHookError {
38    DefaultResponse(crate::models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method `list_site_build_hooks`
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ListSiteBuildHooksError {
46    DefaultResponse(crate::models::Error),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method `update_site_build_hook`
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum UpdateSiteBuildHookError {
54    DefaultResponse(crate::models::Error),
55    UnknownValue(serde_json::Value),
56}
57
58
59pub async fn create_site_build_hook(configuration: &configuration::Configuration, site_id: &str, build_hook: crate::models::BuildHookSetup) -> Result<crate::models::BuildHook, Error<CreateSiteBuildHookError>> {
60
61    let local_var_client = &configuration.client;
62
63    let local_var_uri_str = format!("{}/sites/{site_id}/build_hooks", configuration.base_path, site_id=crate::apis::urlencode(site_id));
64    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
65
66    if let Some(ref local_var_user_agent) = configuration.user_agent {
67        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
68    }
69    if let Some(ref local_var_token) = configuration.oauth_access_token {
70        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
71    };
72    local_var_req_builder = local_var_req_builder.json(&build_hook);
73
74    let local_var_req = local_var_req_builder.build()?;
75    let local_var_resp = local_var_client.execute(local_var_req).await?;
76
77    let local_var_status = local_var_resp.status();
78    let local_var_content = local_var_resp.text().await?;
79
80    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
81        serde_json::from_str(&local_var_content).map_err(Error::from)
82    } else {
83        let local_var_entity: Option<CreateSiteBuildHookError> = serde_json::from_str(&local_var_content).ok();
84        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
85        Err(Error::ResponseError(local_var_error))
86    }
87}
88
89pub async fn delete_site_build_hook(configuration: &configuration::Configuration, site_id: &str, id: &str) -> Result<(), Error<DeleteSiteBuildHookError>> {
90
91    let local_var_client = &configuration.client;
92
93    let local_var_uri_str = format!("{}/sites/{site_id}/build_hooks/{id}", configuration.base_path, site_id=crate::apis::urlencode(site_id), id=crate::apis::urlencode(id));
94    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
95
96    if let Some(ref local_var_user_agent) = configuration.user_agent {
97        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
98    }
99    if let Some(ref local_var_token) = configuration.oauth_access_token {
100        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
101    };
102
103    let local_var_req = local_var_req_builder.build()?;
104    let local_var_resp = local_var_client.execute(local_var_req).await?;
105
106    let local_var_status = local_var_resp.status();
107    let local_var_content = local_var_resp.text().await?;
108
109    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
110        Ok(())
111    } else {
112        let local_var_entity: Option<DeleteSiteBuildHookError> = serde_json::from_str(&local_var_content).ok();
113        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
114        Err(Error::ResponseError(local_var_error))
115    }
116}
117
118pub async fn get_site_build_hook(configuration: &configuration::Configuration, site_id: &str, id: &str) -> Result<crate::models::BuildHook, Error<GetSiteBuildHookError>> {
119
120    let local_var_client = &configuration.client;
121
122    let local_var_uri_str = format!("{}/sites/{site_id}/build_hooks/{id}", configuration.base_path, site_id=crate::apis::urlencode(site_id), id=crate::apis::urlencode(id));
123    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
124
125    if let Some(ref local_var_user_agent) = configuration.user_agent {
126        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
127    }
128    if let Some(ref local_var_token) = configuration.oauth_access_token {
129        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
130    };
131
132    let local_var_req = local_var_req_builder.build()?;
133    let local_var_resp = local_var_client.execute(local_var_req).await?;
134
135    let local_var_status = local_var_resp.status();
136    let local_var_content = local_var_resp.text().await?;
137
138    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
139        serde_json::from_str(&local_var_content).map_err(Error::from)
140    } else {
141        let local_var_entity: Option<GetSiteBuildHookError> = serde_json::from_str(&local_var_content).ok();
142        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
143        Err(Error::ResponseError(local_var_error))
144    }
145}
146
147pub async fn list_site_build_hooks(configuration: &configuration::Configuration, site_id: &str) -> Result<Vec<crate::models::BuildHook>, Error<ListSiteBuildHooksError>> {
148
149    let local_var_client = &configuration.client;
150
151    let local_var_uri_str = format!("{}/sites/{site_id}/build_hooks", configuration.base_path, site_id=crate::apis::urlencode(site_id));
152    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
153
154    if let Some(ref local_var_user_agent) = configuration.user_agent {
155        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
156    }
157    if let Some(ref local_var_token) = configuration.oauth_access_token {
158        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
159    };
160
161    let local_var_req = local_var_req_builder.build()?;
162    let local_var_resp = local_var_client.execute(local_var_req).await?;
163
164    let local_var_status = local_var_resp.status();
165    let local_var_content = local_var_resp.text().await?;
166
167    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
168        serde_json::from_str(&local_var_content).map_err(Error::from)
169    } else {
170        let local_var_entity: Option<ListSiteBuildHooksError> = serde_json::from_str(&local_var_content).ok();
171        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
172        Err(Error::ResponseError(local_var_error))
173    }
174}
175
176pub async fn update_site_build_hook(configuration: &configuration::Configuration, site_id: &str, id: &str, build_hook: crate::models::BuildHookSetup) -> Result<(), Error<UpdateSiteBuildHookError>> {
177
178    let local_var_client = &configuration.client;
179
180    let local_var_uri_str = format!("{}/sites/{site_id}/build_hooks/{id}", configuration.base_path, site_id=crate::apis::urlencode(site_id), id=crate::apis::urlencode(id));
181    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
182
183    if let Some(ref local_var_user_agent) = configuration.user_agent {
184        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
185    }
186    if let Some(ref local_var_token) = configuration.oauth_access_token {
187        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
188    };
189    local_var_req_builder = local_var_req_builder.json(&build_hook);
190
191    let local_var_req = local_var_req_builder.build()?;
192    let local_var_resp = local_var_client.execute(local_var_req).await?;
193
194    let local_var_status = local_var_resp.status();
195    let local_var_content = local_var_resp.text().await?;
196
197    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
198        Ok(())
199    } else {
200        let local_var_entity: Option<UpdateSiteBuildHookError> = serde_json::from_str(&local_var_content).ok();
201        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
202        Err(Error::ResponseError(local_var_error))
203    }
204}
205