netlify_rust/apis/
site_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`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateSiteError {
22    DefaultResponse(crate::models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method `create_site_in_team`
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum CreateSiteInTeamError {
30    DefaultResponse(crate::models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `delete_site`
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum DeleteSiteError {
38    DefaultResponse(crate::models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method `get_site`
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetSiteError {
46    DefaultResponse(crate::models::Error),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method `list_sites`
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum ListSitesError {
54    DefaultResponse(crate::models::Error),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method `list_sites_for_account`
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum ListSitesForAccountError {
62    DefaultResponse(crate::models::Error),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method `unlink_site_repo`
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum UnlinkSiteRepoError {
70    Status404(),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method `update_site`
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum UpdateSiteError {
78    DefaultResponse(crate::models::Error),
79    UnknownValue(serde_json::Value),
80}
81
82
83pub async fn create_site(configuration: &configuration::Configuration, site: crate::models::SiteSetup, configure_dns: Option<bool>) -> Result<crate::models::Site, Error<CreateSiteError>> {
84
85    let local_var_client = &configuration.client;
86
87    let local_var_uri_str = format!("{}/sites", configuration.base_path);
88    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
89
90    if let Some(ref local_var_str) = configure_dns {
91        local_var_req_builder = local_var_req_builder.query(&[("configure_dns", &local_var_str.to_string())]);
92    }
93    if let Some(ref local_var_user_agent) = configuration.user_agent {
94        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
95    }
96    if let Some(ref local_var_token) = configuration.oauth_access_token {
97        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
98    };
99    local_var_req_builder = local_var_req_builder.json(&site);
100
101    let local_var_req = local_var_req_builder.build()?;
102    let local_var_resp = local_var_client.execute(local_var_req).await?;
103
104    let local_var_status = local_var_resp.status();
105    let local_var_content = local_var_resp.text().await?;
106
107    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
108        serde_json::from_str(&local_var_content).map_err(Error::from)
109    } else {
110        let local_var_entity: Option<CreateSiteError> = serde_json::from_str(&local_var_content).ok();
111        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
112        Err(Error::ResponseError(local_var_error))
113    }
114}
115
116pub async fn create_site_in_team(configuration: &configuration::Configuration, account_slug: &str, configure_dns: Option<bool>, site: Option<crate::models::SiteSetup>) -> Result<crate::models::Site, Error<CreateSiteInTeamError>> {
117
118    let local_var_client = &configuration.client;
119
120    let local_var_uri_str = format!("{}/{account_slug}/sites", configuration.base_path, account_slug=crate::apis::urlencode(account_slug));
121    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
122
123    if let Some(ref local_var_str) = configure_dns {
124        local_var_req_builder = local_var_req_builder.query(&[("configure_dns", &local_var_str.to_string())]);
125    }
126    if let Some(ref local_var_user_agent) = configuration.user_agent {
127        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
128    }
129    if let Some(ref local_var_token) = configuration.oauth_access_token {
130        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
131    };
132    local_var_req_builder = local_var_req_builder.json(&site);
133
134    let local_var_req = local_var_req_builder.build()?;
135    let local_var_resp = local_var_client.execute(local_var_req).await?;
136
137    let local_var_status = local_var_resp.status();
138    let local_var_content = local_var_resp.text().await?;
139
140    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
141        serde_json::from_str(&local_var_content).map_err(Error::from)
142    } else {
143        let local_var_entity: Option<CreateSiteInTeamError> = serde_json::from_str(&local_var_content).ok();
144        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
145        Err(Error::ResponseError(local_var_error))
146    }
147}
148
149pub async fn delete_site(configuration: &configuration::Configuration, site_id: &str) -> Result<(), Error<DeleteSiteError>> {
150
151    let local_var_client = &configuration.client;
152
153    let local_var_uri_str = format!("{}/sites/{site_id}", configuration.base_path, site_id=crate::apis::urlencode(site_id));
154    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
155
156    if let Some(ref local_var_user_agent) = configuration.user_agent {
157        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
158    }
159    if let Some(ref local_var_token) = configuration.oauth_access_token {
160        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
161    };
162
163    let local_var_req = local_var_req_builder.build()?;
164    let local_var_resp = local_var_client.execute(local_var_req).await?;
165
166    let local_var_status = local_var_resp.status();
167    let local_var_content = local_var_resp.text().await?;
168
169    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
170        Ok(())
171    } else {
172        let local_var_entity: Option<DeleteSiteError> = serde_json::from_str(&local_var_content).ok();
173        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
174        Err(Error::ResponseError(local_var_error))
175    }
176}
177
178pub async fn get_site(configuration: &configuration::Configuration, site_id: &str) -> Result<crate::models::Site, Error<GetSiteError>> {
179
180    let local_var_client = &configuration.client;
181
182    let local_var_uri_str = format!("{}/sites/{site_id}", configuration.base_path, site_id=crate::apis::urlencode(site_id));
183    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
184
185    if let Some(ref local_var_user_agent) = configuration.user_agent {
186        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
187    }
188    if let Some(ref local_var_token) = configuration.oauth_access_token {
189        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
190    };
191
192    let local_var_req = local_var_req_builder.build()?;
193    let local_var_resp = local_var_client.execute(local_var_req).await?;
194
195    let local_var_status = local_var_resp.status();
196    let local_var_content = local_var_resp.text().await?;
197
198    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
199        serde_json::from_str(&local_var_content).map_err(Error::from)
200    } else {
201        let local_var_entity: Option<GetSiteError> = serde_json::from_str(&local_var_content).ok();
202        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
203        Err(Error::ResponseError(local_var_error))
204    }
205}
206
207pub async fn list_sites(configuration: &configuration::Configuration, name: Option<&str>, filter: Option<&str>, page: Option<i32>, per_page: Option<i32>) -> Result<Vec<crate::models::Site>, Error<ListSitesError>> {
208
209    let local_var_client = &configuration.client;
210
211    let local_var_uri_str = format!("{}/sites", configuration.base_path);
212    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
213
214    if let Some(ref local_var_str) = name {
215        local_var_req_builder = local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
216    }
217    if let Some(ref local_var_str) = filter {
218        local_var_req_builder = local_var_req_builder.query(&[("filter", &local_var_str.to_string())]);
219    }
220    if let Some(ref local_var_str) = page {
221        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
222    }
223    if let Some(ref local_var_str) = per_page {
224        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
225    }
226    if let Some(ref local_var_user_agent) = configuration.user_agent {
227        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
228    }
229    if let Some(ref local_var_token) = configuration.oauth_access_token {
230        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
231    };
232
233    let local_var_req = local_var_req_builder.build()?;
234    let local_var_resp = local_var_client.execute(local_var_req).await?;
235
236    let local_var_status = local_var_resp.status();
237    let local_var_content = local_var_resp.text().await?;
238
239    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
240        serde_json::from_str(&local_var_content).map_err(Error::from)
241    } else {
242        let local_var_entity: Option<ListSitesError> = serde_json::from_str(&local_var_content).ok();
243        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
244        Err(Error::ResponseError(local_var_error))
245    }
246}
247
248pub async fn list_sites_for_account(configuration: &configuration::Configuration, account_slug: &str, name: Option<&str>, page: Option<i32>, per_page: Option<i32>) -> Result<Vec<crate::models::Site>, Error<ListSitesForAccountError>> {
249
250    let local_var_client = &configuration.client;
251
252    let local_var_uri_str = format!("{}/{account_slug}/sites", configuration.base_path, account_slug=crate::apis::urlencode(account_slug));
253    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
254
255    if let Some(ref local_var_str) = name {
256        local_var_req_builder = local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
257    }
258    if let Some(ref local_var_str) = page {
259        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
260    }
261    if let Some(ref local_var_str) = per_page {
262        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
263    }
264    if let Some(ref local_var_user_agent) = configuration.user_agent {
265        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
266    }
267    if let Some(ref local_var_token) = configuration.oauth_access_token {
268        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
269    };
270
271    let local_var_req = local_var_req_builder.build()?;
272    let local_var_resp = local_var_client.execute(local_var_req).await?;
273
274    let local_var_status = local_var_resp.status();
275    let local_var_content = local_var_resp.text().await?;
276
277    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
278        serde_json::from_str(&local_var_content).map_err(Error::from)
279    } else {
280        let local_var_entity: Option<ListSitesForAccountError> = serde_json::from_str(&local_var_content).ok();
281        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
282        Err(Error::ResponseError(local_var_error))
283    }
284}
285
286/// [Beta] Unlinks the repo from the site.  This action will also: - Delete associated deploy keys - Delete outgoing webhooks for the repo - Delete the site's build hooks
287pub async fn unlink_site_repo(configuration: &configuration::Configuration, site_id: &str) -> Result<crate::models::Site, Error<UnlinkSiteRepoError>> {
288
289    let local_var_client = &configuration.client;
290
291    let local_var_uri_str = format!("{}/sites/{site_id}/unlink_repo", configuration.base_path, site_id=crate::apis::urlencode(site_id));
292    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
293
294    if let Some(ref local_var_user_agent) = configuration.user_agent {
295        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
296    }
297    if let Some(ref local_var_token) = configuration.oauth_access_token {
298        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
299    };
300
301    let local_var_req = local_var_req_builder.build()?;
302    let local_var_resp = local_var_client.execute(local_var_req).await?;
303
304    let local_var_status = local_var_resp.status();
305    let local_var_content = local_var_resp.text().await?;
306
307    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
308        serde_json::from_str(&local_var_content).map_err(Error::from)
309    } else {
310        let local_var_entity: Option<UnlinkSiteRepoError> = serde_json::from_str(&local_var_content).ok();
311        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
312        Err(Error::ResponseError(local_var_error))
313    }
314}
315
316pub async fn update_site(configuration: &configuration::Configuration, site_id: &str, site: crate::models::SiteSetup) -> Result<crate::models::Site, Error<UpdateSiteError>> {
317
318    let local_var_client = &configuration.client;
319
320    let local_var_uri_str = format!("{}/sites/{site_id}", configuration.base_path, site_id=crate::apis::urlencode(site_id));
321    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
322
323    if let Some(ref local_var_user_agent) = configuration.user_agent {
324        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
325    }
326    if let Some(ref local_var_token) = configuration.oauth_access_token {
327        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
328    };
329    local_var_req_builder = local_var_req_builder.json(&site);
330
331    let local_var_req = local_var_req_builder.build()?;
332    let local_var_resp = local_var_client.execute(local_var_req).await?;
333
334    let local_var_status = local_var_resp.status();
335    let local_var_content = local_var_resp.text().await?;
336
337    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
338        serde_json::from_str(&local_var_content).map_err(Error::from)
339    } else {
340        let local_var_entity: Option<UpdateSiteError> = serde_json::from_str(&local_var_content).ok();
341        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
342        Err(Error::ResponseError(local_var_error))
343    }
344}
345