netlify_rust/apis/
x_internal_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreatePluginRunError {
22 DefaultResponse(crate::models::Error),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetLatestPluginRunsError {
30 DefaultResponse(crate::models::Error),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum UpdatePluginError {
38 DefaultResponse(crate::models::Error),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub 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
74pub 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
108pub 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