netlify_rust/apis/
build_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`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateSiteBuildError {
22    DefaultResponse(crate::models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method `get_account_build_status`
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetAccountBuildStatusError {
30    DefaultResponse(crate::models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `get_site_build`
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetSiteBuildError {
38    DefaultResponse(crate::models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method `list_site_builds`
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ListSiteBuildsError {
46    DefaultResponse(crate::models::Error),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method `notify_build_start`
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum NotifyBuildStartError {
54    DefaultResponse(crate::models::Error),
55    UnknownValue(serde_json::Value),
56}
57
58
59pub async fn create_site_build(configuration: &configuration::Configuration, site_id: &str, build: Option<crate::models::BuildSetup>) -> Result<crate::models::Build, Error<CreateSiteBuildError>> {
60
61    let local_var_client = &configuration.client;
62
63    let local_var_uri_str = format!("{}/sites/{site_id}/builds", 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);
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<CreateSiteBuildError> = 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 get_account_build_status(configuration: &configuration::Configuration, account_id: &str) -> Result<Vec<crate::models::BuildStatus>, Error<GetAccountBuildStatusError>> {
90
91    let local_var_client = &configuration.client;
92
93    let local_var_uri_str = format!("{}/{account_id}/builds/status", configuration.base_path, account_id=crate::apis::urlencode(account_id));
94    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, 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        serde_json::from_str(&local_var_content).map_err(Error::from)
111    } else {
112        let local_var_entity: Option<GetAccountBuildStatusError> = 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(configuration: &configuration::Configuration, build_id: &str) -> Result<crate::models::Build, Error<GetSiteBuildError>> {
119
120    let local_var_client = &configuration.client;
121
122    let local_var_uri_str = format!("{}/builds/{build_id}", configuration.base_path, build_id=crate::apis::urlencode(build_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<GetSiteBuildError> = 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_builds(configuration: &configuration::Configuration, site_id: &str, page: Option<i32>, per_page: Option<i32>) -> Result<Vec<crate::models::Build>, Error<ListSiteBuildsError>> {
148
149    let local_var_client = &configuration.client;
150
151    let local_var_uri_str = format!("{}/sites/{site_id}/builds", 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_str) = page {
155        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
156    }
157    if let Some(ref local_var_str) = per_page {
158        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
159    }
160    if let Some(ref local_var_user_agent) = configuration.user_agent {
161        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
162    }
163    if let Some(ref local_var_token) = configuration.oauth_access_token {
164        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
165    };
166
167    let local_var_req = local_var_req_builder.build()?;
168    let local_var_resp = local_var_client.execute(local_var_req).await?;
169
170    let local_var_status = local_var_resp.status();
171    let local_var_content = local_var_resp.text().await?;
172
173    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
174        serde_json::from_str(&local_var_content).map_err(Error::from)
175    } else {
176        let local_var_entity: Option<ListSiteBuildsError> = serde_json::from_str(&local_var_content).ok();
177        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
178        Err(Error::ResponseError(local_var_error))
179    }
180}
181
182pub async fn notify_build_start(configuration: &configuration::Configuration, build_id: &str) -> Result<(), Error<NotifyBuildStartError>> {
183
184    let local_var_client = &configuration.client;
185
186    let local_var_uri_str = format!("{}/builds/{build_id}/start", configuration.base_path, build_id=crate::apis::urlencode(build_id));
187    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
188
189    if let Some(ref local_var_user_agent) = configuration.user_agent {
190        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
191    }
192    if let Some(ref local_var_token) = configuration.oauth_access_token {
193        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
194    };
195
196    let local_var_req = local_var_req_builder.build()?;
197    let local_var_resp = local_var_client.execute(local_var_req).await?;
198
199    let local_var_status = local_var_resp.status();
200    let local_var_content = local_var_resp.text().await?;
201
202    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
203        Ok(())
204    } else {
205        let local_var_entity: Option<NotifyBuildStartError> = serde_json::from_str(&local_var_content).ok();
206        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
207        Err(Error::ResponseError(local_var_error))
208    }
209}
210