netlify_rust/apis/
service_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 `get_services`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetServicesError {
22    DefaultResponse(crate::models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method `show_service`
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum ShowServiceError {
30    DefaultResponse(crate::models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `show_service_manifest`
35#[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