netlify_rust/apis/
submission_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 `delete_submission`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteSubmissionError {
22    DefaultResponse(crate::models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method `list_form_submission`
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum ListFormSubmissionError {
30    DefaultResponse(crate::models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `list_form_submissions`
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ListFormSubmissionsError {
38    DefaultResponse(crate::models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method `list_site_submissions`
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ListSiteSubmissionsError {
46    DefaultResponse(crate::models::Error),
47    UnknownValue(serde_json::Value),
48}
49
50
51pub async fn delete_submission(configuration: &configuration::Configuration, submission_id: &str) -> Result<(), Error<DeleteSubmissionError>> {
52
53    let local_var_client = &configuration.client;
54
55    let local_var_uri_str = format!("{}/submissions/{submission_id}", configuration.base_path, submission_id=crate::apis::urlencode(submission_id));
56    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
57
58    if let Some(ref local_var_user_agent) = configuration.user_agent {
59        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
60    }
61    if let Some(ref local_var_token) = configuration.oauth_access_token {
62        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
63    };
64
65    let local_var_req = local_var_req_builder.build()?;
66    let local_var_resp = local_var_client.execute(local_var_req).await?;
67
68    let local_var_status = local_var_resp.status();
69    let local_var_content = local_var_resp.text().await?;
70
71    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
72        Ok(())
73    } else {
74        let local_var_entity: Option<DeleteSubmissionError> = serde_json::from_str(&local_var_content).ok();
75        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
76        Err(Error::ResponseError(local_var_error))
77    }
78}
79
80pub async fn list_form_submission(configuration: &configuration::Configuration, submission_id: &str, query: Option<&str>, page: Option<i32>, per_page: Option<i32>) -> Result<Vec<crate::models::Submission>, Error<ListFormSubmissionError>> {
81
82    let local_var_client = &configuration.client;
83
84    let local_var_uri_str = format!("{}/submissions/{submission_id}", configuration.base_path, submission_id=crate::apis::urlencode(submission_id));
85    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
86
87    if let Some(ref local_var_str) = query {
88        local_var_req_builder = local_var_req_builder.query(&[("query", &local_var_str.to_string())]);
89    }
90    if let Some(ref local_var_str) = page {
91        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
92    }
93    if let Some(ref local_var_str) = per_page {
94        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
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<ListFormSubmissionError> = 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 list_form_submissions(configuration: &configuration::Configuration, form_id: &str, page: Option<i32>, per_page: Option<i32>) -> Result<Vec<crate::models::Submission>, Error<ListFormSubmissionsError>> {
119
120    let local_var_client = &configuration.client;
121
122    let local_var_uri_str = format!("{}/forms/{form_id}/submissions", configuration.base_path, form_id=crate::apis::urlencode(form_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_str) = page {
126        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
127    }
128    if let Some(ref local_var_str) = per_page {
129        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
130    }
131    if let Some(ref local_var_user_agent) = configuration.user_agent {
132        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
133    }
134    if let Some(ref local_var_token) = configuration.oauth_access_token {
135        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
136    };
137
138    let local_var_req = local_var_req_builder.build()?;
139    let local_var_resp = local_var_client.execute(local_var_req).await?;
140
141    let local_var_status = local_var_resp.status();
142    let local_var_content = local_var_resp.text().await?;
143
144    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
145        serde_json::from_str(&local_var_content).map_err(Error::from)
146    } else {
147        let local_var_entity: Option<ListFormSubmissionsError> = serde_json::from_str(&local_var_content).ok();
148        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
149        Err(Error::ResponseError(local_var_error))
150    }
151}
152
153pub async fn list_site_submissions(configuration: &configuration::Configuration, site_id: &str, page: Option<i32>, per_page: Option<i32>) -> Result<Vec<crate::models::Submission>, Error<ListSiteSubmissionsError>> {
154
155    let local_var_client = &configuration.client;
156
157    let local_var_uri_str = format!("{}/sites/{site_id}/submissions", configuration.base_path, site_id=crate::apis::urlencode(site_id));
158    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
159
160    if let Some(ref local_var_str) = page {
161        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
162    }
163    if let Some(ref local_var_str) = per_page {
164        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
165    }
166    if let Some(ref local_var_user_agent) = configuration.user_agent {
167        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
168    }
169    if let Some(ref local_var_token) = configuration.oauth_access_token {
170        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
171    };
172
173    let local_var_req = local_var_req_builder.build()?;
174    let local_var_resp = local_var_client.execute(local_var_req).await?;
175
176    let local_var_status = local_var_resp.status();
177    let local_var_content = local_var_resp.text().await?;
178
179    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
180        serde_json::from_str(&local_var_content).map_err(Error::from)
181    } else {
182        let local_var_entity: Option<ListSiteSubmissionsError> = serde_json::from_str(&local_var_content).ok();
183        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
184        Err(Error::ResponseError(local_var_error))
185    }
186}
187