netlify_rust/apis/
x_internal_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_plugin_run`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreatePluginRunError {
22    DefaultResponse(crate::models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method `get_latest_plugin_runs`
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetLatestPluginRunsError {
30    DefaultResponse(crate::models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `update_plugin`
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum UpdatePluginError {
38    DefaultResponse(crate::models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42
43/// This is an internal-only endpoint.
44pub async fn create_plugin_run(configuration: &configuration::Configuration, deploy_id: &str, plugin_run: Option<crate::models::PluginRunData>) -> Result<crate::models::PluginRun, Error<CreatePluginRunError>> {
45
46    let local_var_client = &configuration.client;
47
48    let local_var_uri_str = format!("{}/deploys/{deploy_id}/plugin_runs", configuration.base_path, deploy_id=crate::apis::urlencode(deploy_id));
49    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
50
51    if let Some(ref local_var_user_agent) = configuration.user_agent {
52        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
53    }
54    if let Some(ref local_var_token) = configuration.oauth_access_token {
55        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
56    };
57    local_var_req_builder = local_var_req_builder.json(&plugin_run);
58
59    let local_var_req = local_var_req_builder.build()?;
60    let local_var_resp = local_var_client.execute(local_var_req).await?;
61
62    let local_var_status = local_var_resp.status();
63    let local_var_content = local_var_resp.text().await?;
64
65    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
66        serde_json::from_str(&local_var_content).map_err(Error::from)
67    } else {
68        let local_var_entity: Option<CreatePluginRunError> = serde_json::from_str(&local_var_content).ok();
69        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
70        Err(Error::ResponseError(local_var_error))
71    }
72}
73
74/// This is an internal-only endpoint.
75pub async fn get_latest_plugin_runs(configuration: &configuration::Configuration, site_id: &str, packages: Vec<String>, state: Option<&str>) -> Result<Vec<crate::models::PluginRun>, Error<GetLatestPluginRunsError>> {
76
77    let local_var_client = &configuration.client;
78
79    let local_var_uri_str = format!("{}/sites/{site_id}/plugin_runs/latest", configuration.base_path, site_id=crate::apis::urlencode(site_id));
80    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
81
82    local_var_req_builder = local_var_req_builder.query(&[("packages", &packages.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]);
83    if let Some(ref local_var_str) = state {
84        local_var_req_builder = local_var_req_builder.query(&[("state", &local_var_str.to_string())]);
85    }
86    if let Some(ref local_var_user_agent) = configuration.user_agent {
87        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
88    }
89    if let Some(ref local_var_token) = configuration.oauth_access_token {
90        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
91    };
92
93    let local_var_req = local_var_req_builder.build()?;
94    let local_var_resp = local_var_client.execute(local_var_req).await?;
95
96    let local_var_status = local_var_resp.status();
97    let local_var_content = local_var_resp.text().await?;
98
99    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
100        serde_json::from_str(&local_var_content).map_err(Error::from)
101    } else {
102        let local_var_entity: Option<GetLatestPluginRunsError> = serde_json::from_str(&local_var_content).ok();
103        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
104        Err(Error::ResponseError(local_var_error))
105    }
106}
107
108/// This is an internal-only endpoint.
109pub async fn update_plugin(configuration: &configuration::Configuration, site_id: &str, package: &str, plugin_params: Option<crate::models::PluginParams>) -> Result<crate::models::Plugin, Error<UpdatePluginError>> {
110
111    let local_var_client = &configuration.client;
112
113    let local_var_uri_str = format!("{}/sites/{site_id}/plugins/{package}", configuration.base_path, site_id=crate::apis::urlencode(site_id), package=crate::apis::urlencode(package));
114    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
115
116    if let Some(ref local_var_user_agent) = configuration.user_agent {
117        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
118    }
119    if let Some(ref local_var_token) = configuration.oauth_access_token {
120        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
121    };
122    local_var_req_builder = local_var_req_builder.json(&plugin_params);
123
124    let local_var_req = local_var_req_builder.build()?;
125    let local_var_resp = local_var_client.execute(local_var_req).await?;
126
127    let local_var_status = local_var_resp.status();
128    let local_var_content = local_var_resp.text().await?;
129
130    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
131        serde_json::from_str(&local_var_content).map_err(Error::from)
132    } else {
133        let local_var_entity: Option<UpdatePluginError> = serde_json::from_str(&local_var_content).ok();
134        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
135        Err(Error::ResponseError(local_var_error))
136    }
137}
138