netlify_rust/apis/
service_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 GetServicesError {
22 DefaultResponse(crate::models::Error),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum ShowServiceError {
30 DefaultResponse(crate::models::Error),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ShowServiceManifestError {
38 DefaultResponse(crate::models::Error),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn get_services(configuration: &configuration::Configuration, search: Option<&str>) -> Result<Vec<crate::models::Service>, Error<GetServicesError>> {
44
45 let local_var_client = &configuration.client;
46
47 let local_var_uri_str = format!("{}/services/", configuration.base_path);
48 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
49
50 if let Some(ref local_var_str) = search {
51 local_var_req_builder = local_var_req_builder.query(&[("search", &local_var_str.to_string())]);
52 }
53 if let Some(ref local_var_user_agent) = configuration.user_agent {
54 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
55 }
56 if let Some(ref local_var_token) = configuration.oauth_access_token {
57 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
58 };
59
60 let local_var_req = local_var_req_builder.build()?;
61 let local_var_resp = local_var_client.execute(local_var_req).await?;
62
63 let local_var_status = local_var_resp.status();
64 let local_var_content = local_var_resp.text().await?;
65
66 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
67 serde_json::from_str(&local_var_content).map_err(Error::from)
68 } else {
69 let local_var_entity: Option<GetServicesError> = serde_json::from_str(&local_var_content).ok();
70 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
71 Err(Error::ResponseError(local_var_error))
72 }
73}
74
75pub async fn show_service(configuration: &configuration::Configuration, addon_name: &str) -> Result<crate::models::Service, Error<ShowServiceError>> {
76
77 let local_var_client = &configuration.client;
78
79 let local_var_uri_str = format!("{}/services/{addonName}", configuration.base_path, addonName=crate::apis::urlencode(addon_name));
80 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
81
82 if let Some(ref local_var_user_agent) = configuration.user_agent {
83 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
84 }
85 if let Some(ref local_var_token) = configuration.oauth_access_token {
86 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
87 };
88
89 let local_var_req = local_var_req_builder.build()?;
90 let local_var_resp = local_var_client.execute(local_var_req).await?;
91
92 let local_var_status = local_var_resp.status();
93 let local_var_content = local_var_resp.text().await?;
94
95 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
96 serde_json::from_str(&local_var_content).map_err(Error::from)
97 } else {
98 let local_var_entity: Option<ShowServiceError> = serde_json::from_str(&local_var_content).ok();
99 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
100 Err(Error::ResponseError(local_var_error))
101 }
102}
103
104pub async fn show_service_manifest(configuration: &configuration::Configuration, addon_name: &str) -> Result<serde_json::Value, Error<ShowServiceManifestError>> {
105
106 let local_var_client = &configuration.client;
107
108 let local_var_uri_str = format!("{}/services/{addonName}/manifest", configuration.base_path, addonName=crate::apis::urlencode(addon_name));
109 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
110
111 if let Some(ref local_var_user_agent) = configuration.user_agent {
112 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
113 }
114 if let Some(ref local_var_token) = configuration.oauth_access_token {
115 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
116 };
117
118 let local_var_req = local_var_req_builder.build()?;
119 let local_var_resp = local_var_client.execute(local_var_req).await?;
120
121 let local_var_status = local_var_resp.status();
122 let local_var_content = local_var_resp.text().await?;
123
124 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
125 serde_json::from_str(&local_var_content).map_err(Error::from)
126 } else {
127 let local_var_entity: Option<ShowServiceManifestError> = serde_json::from_str(&local_var_content).ok();
128 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
129 Err(Error::ResponseError(local_var_error))
130 }
131}
132