use async_trait::async_trait; use futures::{ future, future::BoxFuture, future::FutureExt, future::TryFutureExt, stream, stream::StreamExt, Stream, }; use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE}; use hyper::{service::Service, Body, Request, Response, Uri}; use percent_encoding::{utf8_percent_encode, AsciiSet}; use std::borrow::Cow; use std::convert::TryInto; use std::error::Error; use std::fmt; use std::future::Future; use std::io::{ErrorKind, Read}; use std::marker::PhantomData; use std::path::Path; use std::str; use std::str::FromStr; use std::string::ToString; use std::sync::{Arc, Mutex}; use std::task::{Context, Poll}; use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString}; use url::form_urlencoded; use crate::header; use crate::models; /// https://url.spec.whatwg.org/#fragment-percent-encode-set #[allow(dead_code)] const FRAGMENT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS .add(b' ') .add(b'"') .add(b'<') .add(b'>') .add(b'`'); /// This encode set is used for object IDs /// /// Aside from the special characters defined in the `PATH_SEGMENT_ENCODE_SET`, /// the vertical bar (|) is encoded. #[allow(dead_code)] const ID_ENCODE_SET: &AsciiSet = &FRAGMENT_ENCODE_SET.add(b'|'); use crate::{ AcceptEditgroupResponse, Api, AuthCheckResponse, AuthOidcResponse, CreateAuthTokenResponse, CreateContainerAutoBatchResponse, CreateContainerResponse, CreateCreatorAutoBatchResponse, CreateCreatorResponse, CreateEditgroupAnnotationResponse, CreateEditgroupResponse, CreateFileAutoBatchResponse, CreateFileResponse, CreateFilesetAutoBatchResponse, CreateFilesetResponse, CreateReleaseAutoBatchResponse, CreateReleaseResponse, CreateWebcaptureAutoBatchResponse, CreateWebcaptureResponse, CreateWorkAutoBatchResponse, CreateWorkResponse, DeleteContainerEditResponse, DeleteContainerResponse, DeleteCreatorEditResponse, DeleteCreatorResponse, DeleteFileEditResponse, DeleteFileResponse, DeleteFilesetEditResponse, DeleteFilesetResponse, DeleteReleaseEditResponse, DeleteReleaseResponse, DeleteWebcaptureEditResponse, DeleteWebcaptureResponse, DeleteWorkEditResponse, DeleteWorkResponse, GetChangelogEntryResponse, GetChangelogResponse, GetContainerEditResponse, GetContainerHistoryResponse, GetContainerRedirectsResponse, GetContainerResponse, GetContainerRevisionResponse, GetCreatorEditResponse, GetCreatorHistoryResponse, GetCreatorRedirectsResponse, GetCreatorReleasesResponse, GetCreatorResponse, GetCreatorRevisionResponse, GetEditgroupAnnotationsResponse, GetEditgroupResponse, GetEditgroupsReviewableResponse, GetEditorAnnotationsResponse, GetEditorEditgroupsResponse, GetEditorResponse, GetFileEditResponse, GetFileHistoryResponse, GetFileRedirectsResponse, GetFileResponse, GetFileRevisionResponse, GetFilesetEditResponse, GetFilesetHistoryResponse, GetFilesetRedirectsResponse, GetFilesetResponse, GetFilesetRevisionResponse, GetReleaseEditResponse, GetReleaseFilesResponse, GetReleaseFilesetsResponse, GetReleaseHistoryResponse, GetReleaseRedirectsResponse, GetReleaseResponse, GetReleaseRevisionResponse, GetReleaseWebcapturesResponse, GetWebcaptureEditResponse, GetWebcaptureHistoryResponse, GetWebcaptureRedirectsResponse, GetWebcaptureResponse, GetWebcaptureRevisionResponse, GetWorkEditResponse, GetWorkHistoryResponse, GetWorkRedirectsResponse, GetWorkReleasesResponse, GetWorkResponse, GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, UpdateEditgroupResponse, UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, UpdateWebcaptureResponse, UpdateWorkResponse, }; /// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes. fn into_base_path( input: impl TryInto, correct_scheme: Option<&'static str>, ) -> Result { // First convert to Uri, since a base path is a subset of Uri. let uri = input.try_into()?; let scheme = uri.scheme_str().ok_or(ClientInitError::InvalidScheme)?; // Check the scheme if necessary if let Some(correct_scheme) = correct_scheme { if scheme != correct_scheme { return Err(ClientInitError::InvalidScheme); } } let host = uri.host().ok_or_else(|| ClientInitError::MissingHost)?; let port = uri .port_u16() .map(|x| format!(":{}", x)) .unwrap_or_default(); Ok(format!( "{}://{}{}{}", scheme, host, port, uri.path().trim_end_matches('/') )) } /// A client that implements the API by making HTTP calls out to a server. pub struct Client where S: Service<(Request, C), Response = Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, C: Clone + Send + Sync + 'static, { /// Inner service client_service: S, /// Base path of the API base_path: String, /// Marker marker: PhantomData, } impl fmt::Debug for Client where S: Service<(Request, C), Response = Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, C: Clone + Send + Sync + 'static, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Client {{ base_path: {} }}", self.base_path) } } impl Clone for Client where S: Service<(Request, C), Response = Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, C: Clone + Send + Sync + 'static, { fn clone(&self) -> Self { Self { client_service: self.client_service.clone(), base_path: self.base_path.clone(), marker: PhantomData, } } } impl Client, C>, C> where Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static, C: Clone + Send + Sync + 'static, { /// Create a client with a custom implementation of hyper::client::Connect. /// /// Intended for use with custom implementations of connect for e.g. protocol logging /// or similar functionality which requires wrapping the transport layer. When wrapping a TCP connection, /// this function should be used in conjunction with `swagger::Connector::builder()`. /// /// For ordinary tcp connections, prefer the use of `try_new_http`, `try_new_https` /// and `try_new_https_mutual`, to avoid introducing a dependency on the underlying transport layer. /// /// # Arguments /// /// * `base_path` - base path of the client API, i.e. "http://www.my-api-implementation.com" /// * `protocol` - Which protocol to use when constructing the request url, e.g. `Some("http")` /// * `connector` - Implementation of `hyper::client::Connect` to use for the client pub fn try_new_with_connector( base_path: &str, protocol: Option<&'static str>, connector: Connector, ) -> Result { let client_service = hyper::client::Client::builder().build(connector); let client_service = DropContextService::new(client_service); Ok(Self { client_service, base_path: into_base_path(base_path, protocol)?, marker: PhantomData, }) } } #[derive(Debug, Clone)] pub enum HyperClient { Http(hyper::client::Client), Https(hyper::client::Client), } impl Service> for HyperClient { type Response = Response; type Error = hyper::Error; type Future = hyper::client::ResponseFuture; fn poll_ready(&mut self, cx: &mut Context) -> Poll> { match self { HyperClient::Http(client) => client.poll_ready(cx), HyperClient::Https(client) => client.poll_ready(cx), } } fn call(&mut self, req: Request) -> Self::Future { match self { HyperClient::Http(client) => client.call(req), HyperClient::Https(client) => client.call(req), } } } impl Client, C> where C: Clone + Send + Sync + 'static, { /// Create an HTTP client. /// /// # Arguments /// * `base_path` - base path of the client API, i.e. "http://www.my-api-implementation.com" pub fn try_new(base_path: &str) -> Result { let uri = Uri::from_str(base_path)?; let scheme = uri.scheme_str().ok_or(ClientInitError::InvalidScheme)?; let scheme = scheme.to_ascii_lowercase(); let connector = Connector::builder(); let client_service = match scheme.as_str() { "http" => HyperClient::Http(hyper::client::Client::builder().build(connector.build())), "https" => { let connector = connector .https() .build() .map_err(|e| ClientInitError::SslError(e))?; HyperClient::Https(hyper::client::Client::builder().build(connector)) } _ => { return Err(ClientInitError::InvalidScheme); } }; let client_service = DropContextService::new(client_service); Ok(Self { client_service, base_path: into_base_path(base_path, None)?, marker: PhantomData, }) } } impl Client, C>, C> where C: Clone + Send + Sync + 'static, { /// Create an HTTP client. /// /// # Arguments /// * `base_path` - base path of the client API, i.e. "http://www.my-api-implementation.com" pub fn try_new_http(base_path: &str) -> Result { let http_connector = Connector::builder().build(); Self::try_new_with_connector(base_path, Some("http"), http_connector) } } #[cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))] type HttpsConnector = hyper_tls::HttpsConnector; #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] type HttpsConnector = hyper_openssl::HttpsConnector; impl Client, C>, C> where C: Clone + Send + Sync + 'static, { /// Create a client with a TLS connection to the server /// /// # Arguments /// * `base_path` - base path of the client API, i.e. "https://www.my-api-implementation.com" pub fn try_new_https(base_path: &str) -> Result { let https_connector = Connector::builder() .https() .build() .map_err(|e| ClientInitError::SslError(e))?; Self::try_new_with_connector(base_path, Some("https"), https_connector) } /// Create a client with a TLS connection to the server using a pinned certificate /// /// # Arguments /// * `base_path` - base path of the client API, i.e. "https://www.my-api-implementation.com" /// * `ca_certificate` - Path to CA certificate used to authenticate the server #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] pub fn try_new_https_pinned( base_path: &str, ca_certificate: CA, ) -> Result where CA: AsRef, { let https_connector = Connector::builder() .https() .pin_server_certificate(ca_certificate) .build() .map_err(|e| ClientInitError::SslError(e))?; Self::try_new_with_connector(base_path, Some("https"), https_connector) } /// Create a client with a mutually authenticated TLS connection to the server. /// /// # Arguments /// * `base_path` - base path of the client API, i.e. "https://www.my-api-implementation.com" /// * `ca_certificate` - Path to CA certificate used to authenticate the server /// * `client_key` - Path to the client private key /// * `client_certificate` - Path to the client's public certificate associated with the private key #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] pub fn try_new_https_mutual( base_path: &str, ca_certificate: CA, client_key: K, client_certificate: D, ) -> Result where CA: AsRef, K: AsRef, D: AsRef, { let https_connector = Connector::builder() .https() .pin_server_certificate(ca_certificate) .client_authentication(client_key, client_certificate) .build() .map_err(|e| ClientInitError::SslError(e))?; Self::try_new_with_connector(base_path, Some("https"), https_connector) } } impl Client where S: Service<(Request, C), Response = Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, C: Clone + Send + Sync + 'static, { /// Constructor for creating a `Client` by passing in a pre-made `hyper::service::Service` / /// `tower::Service` /// /// This allows adding custom wrappers around the underlying transport, for example for logging. pub fn try_new_with_client_service( client_service: S, base_path: &str, ) -> Result { Ok(Self { client_service, base_path: into_base_path(base_path, None)?, marker: PhantomData, }) } } /// Error type failing to create a Client #[derive(Debug)] pub enum ClientInitError { /// Invalid URL Scheme InvalidScheme, /// Invalid URI InvalidUri(hyper::http::uri::InvalidUri), /// Missing Hostname MissingHost, /// SSL Connection Error #[cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))] SslError(native_tls::Error), /// SSL Connection Error #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] SslError(openssl::error::ErrorStack), } impl From for ClientInitError { fn from(err: hyper::http::uri::InvalidUri) -> ClientInitError { ClientInitError::InvalidUri(err) } } impl fmt::Display for ClientInitError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let s: &dyn fmt::Debug = self; s.fmt(f) } } impl Error for ClientInitError { fn description(&self) -> &str { "Failed to produce a hyper client." } } #[async_trait] impl Api for Client where S: Service<(Request, C), Response = Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, C: Has + Has> + Clone + Send + Sync + 'static, { fn poll_ready(&self, cx: &mut Context) -> Poll> { match self.client_service.clone().poll_ready(cx) { Poll::Ready(Err(e)) => Poll::Ready(Err(e.into())), Poll::Ready(Ok(o)) => Poll::Ready(Ok(o)), Poll::Pending => Poll::Pending, } } async fn accept_editgroup( &self, param_editgroup_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/accept", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AcceptEditgroupResponse::MergedSuccessfully(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AcceptEditgroupResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AcceptEditgroupResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AcceptEditgroupResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AcceptEditgroupResponse::NotFound(body)) } 409 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AcceptEditgroupResponse::EditConflict(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AcceptEditgroupResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn auth_check( &self, param_role: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/auth/check", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_role) = param_role { query_string.append_pair("role", ¶m_role.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthCheckResponse::Success(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthCheckResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthCheckResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthCheckResponse::Forbidden(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthCheckResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn auth_oidc( &self, param_auth_oidc: models::AuthOidc, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/auth/oidc", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_auth_oidc).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthOidcResponse::Found(body)) } 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthOidcResponse::Created(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthOidcResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthOidcResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthOidcResponse::Forbidden(body)) } 409 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthOidcResponse::Conflict(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(AuthOidcResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_auth_token( &self, param_editor_id: String, param_duration_seconds: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/auth/token/{editor_id}", self.base_path, editor_id = utf8_percent_encode(¶m_editor_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_duration_seconds) = param_duration_seconds { query_string.append_pair("duration_seconds", ¶m_duration_seconds.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateAuthTokenResponse::Success(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateAuthTokenResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateAuthTokenResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateAuthTokenResponse::Forbidden(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateAuthTokenResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_container( &self, param_editgroup_id: String, param_container_entity: models::ContainerEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/container", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_container_entity) .expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerResponse::CreatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_container_auto_batch( &self, param_container_auto_batch: models::ContainerAutoBatch, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/container/batch", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_container_auto_batch) .expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerAutoBatchResponse::CreatedEditgroup(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerAutoBatchResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerAutoBatchResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerAutoBatchResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerAutoBatchResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateContainerAutoBatchResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_creator( &self, param_editgroup_id: String, param_creator_entity: models::CreatorEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/creator", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_creator_entity).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorResponse::CreatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_creator_auto_batch( &self, param_creator_auto_batch: models::CreatorAutoBatch, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/creator/batch", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_creator_auto_batch) .expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorAutoBatchResponse::CreatedEditgroup(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorAutoBatchResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorAutoBatchResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorAutoBatchResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorAutoBatchResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateCreatorAutoBatchResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_editgroup( &self, param_editgroup: models::Editgroup, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_editgroup).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupResponse::SuccessfullyCreated(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_editgroup_annotation( &self, param_editgroup_id: String, param_editgroup_annotation: models::EditgroupAnnotation, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/annotation", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_editgroup_annotation) .expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupAnnotationResponse::Created(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupAnnotationResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupAnnotationResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupAnnotationResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupAnnotationResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateEditgroupAnnotationResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_file( &self, param_editgroup_id: String, param_file_entity: models::FileEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/file", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_file_entity).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileResponse::CreatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_file_auto_batch( &self, param_file_auto_batch: models::FileAutoBatch, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/file/batch", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_file_auto_batch).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileAutoBatchResponse::CreatedEditgroup(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileAutoBatchResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileAutoBatchResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileAutoBatchResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileAutoBatchResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFileAutoBatchResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_fileset( &self, param_editgroup_id: String, param_fileset_entity: models::FilesetEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/fileset", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_fileset_entity).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetResponse::CreatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_fileset_auto_batch( &self, param_fileset_auto_batch: models::FilesetAutoBatch, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/fileset/batch", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_fileset_auto_batch) .expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetAutoBatchResponse::CreatedEditgroup(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetAutoBatchResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetAutoBatchResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetAutoBatchResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetAutoBatchResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateFilesetAutoBatchResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_release( &self, param_editgroup_id: String, param_release_entity: models::ReleaseEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/release", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_release_entity).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseResponse::CreatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_release_auto_batch( &self, param_release_auto_batch: models::ReleaseAutoBatch, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/release/batch", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_release_auto_batch) .expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseAutoBatchResponse::CreatedEditgroup(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseAutoBatchResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseAutoBatchResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseAutoBatchResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseAutoBatchResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateReleaseAutoBatchResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_webcapture( &self, param_editgroup_id: String, param_webcapture_entity: models::WebcaptureEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/webcapture", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_webcapture_entity) .expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureResponse::CreatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_webcapture_auto_batch( &self, param_webcapture_auto_batch: models::WebcaptureAutoBatch, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/webcapture/batch", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_webcapture_auto_batch) .expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureAutoBatchResponse::CreatedEditgroup(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureAutoBatchResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureAutoBatchResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureAutoBatchResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureAutoBatchResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWebcaptureAutoBatchResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_work( &self, param_editgroup_id: String, param_work_entity: models::WorkEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/work", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_work_entity).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkResponse::CreatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn create_work_auto_batch( &self, param_work_auto_batch: models::WorkAutoBatch, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/work/batch", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_work_auto_batch).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 201 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkAutoBatchResponse::CreatedEditgroup(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkAutoBatchResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkAutoBatchResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkAutoBatchResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkAutoBatchResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(CreateWorkAutoBatchResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_container( &self, param_editgroup_id: String, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/container/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerResponse::DeletedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_container_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/container/edit/{edit_id}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerEditResponse::DeletedEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerEditResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerEditResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerEditResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteContainerEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_creator( &self, param_editgroup_id: String, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/creator/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorResponse::DeletedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_creator_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/creator/edit/{edit_id}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorEditResponse::DeletedEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorEditResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorEditResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorEditResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteCreatorEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_file( &self, param_editgroup_id: String, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/file/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileResponse::DeletedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_file_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/file/edit/{edit_id}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileEditResponse::DeletedEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileEditResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileEditResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileEditResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFileEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_fileset( &self, param_editgroup_id: String, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/fileset/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetResponse::DeletedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_fileset_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/fileset/edit/{edit_id}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetEditResponse::DeletedEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetEditResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetEditResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetEditResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteFilesetEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_release( &self, param_editgroup_id: String, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/release/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseResponse::DeletedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_release_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/release/edit/{edit_id}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseEditResponse::DeletedEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseEditResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseEditResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseEditResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteReleaseEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_webcapture( &self, param_editgroup_id: String, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/webcapture/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureResponse::DeletedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_webcapture_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/webcapture/edit/{edit_id}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureEditResponse::DeletedEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureEditResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureEditResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureEditResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWebcaptureEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_work( &self, param_editgroup_id: String, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/work/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkResponse::DeletedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn delete_work_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/work/edit/{edit_id}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkEditResponse::DeletedEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkEditResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkEditResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkEditResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(DeleteWorkEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_changelog( &self, param_limit: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/changelog", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_limit) = param_limit { query_string.append_pair("limit", ¶m_limit.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetChangelogResponse::Success(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetChangelogResponse::BadRequest(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetChangelogResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_changelog_entry( &self, param_index: i64, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/changelog/{index}", self.base_path, index = utf8_percent_encode(¶m_index.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetChangelogEntryResponse::FoundChangelogEntry(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetChangelogEntryResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetChangelogEntryResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetChangelogEntryResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_container( &self, param_ident: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/container/{ident}", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerResponse::FoundEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_container_edit( &self, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/container/edit/{edit_id}", self.base_path, edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerEditResponse::FoundEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerEditResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_container_history( &self, param_ident: String, param_limit: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/container/{ident}/history", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_limit) = param_limit { query_string.append_pair("limit", ¶m_limit.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetContainerHistoryResponse::FoundEntityHistory(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerHistoryResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerHistoryResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerHistoryResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_container_redirects( &self, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/container/{ident}/redirects", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetContainerRedirectsResponse::FoundEntityRedirects(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerRedirectsResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerRedirectsResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerRedirectsResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_container_revision( &self, param_rev_id: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/container/rev/{rev_id}", self.base_path, rev_id = utf8_percent_encode(¶m_rev_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerRevisionResponse::FoundEntityRevision(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerRevisionResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerRevisionResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetContainerRevisionResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_creator( &self, param_ident: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/{ident}", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorResponse::FoundEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_creator_edit( &self, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/edit/{edit_id}", self.base_path, edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorEditResponse::FoundEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorEditResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_creator_history( &self, param_ident: String, param_limit: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/{ident}/history", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_limit) = param_limit { query_string.append_pair("limit", ¶m_limit.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetCreatorHistoryResponse::FoundEntityHistory(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorHistoryResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorHistoryResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorHistoryResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_creator_redirects( &self, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/{ident}/redirects", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetCreatorRedirectsResponse::FoundEntityRedirects(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorRedirectsResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorRedirectsResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorRedirectsResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_creator_releases( &self, param_ident: String, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/{ident}/releases", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetCreatorReleasesResponse::Found(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorReleasesResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorReleasesResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorReleasesResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_creator_revision( &self, param_rev_id: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/rev/{rev_id}", self.base_path, rev_id = utf8_percent_encode(¶m_rev_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorRevisionResponse::FoundEntityRevision(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorRevisionResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorRevisionResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetCreatorRevisionResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_editgroup( &self, param_editgroup_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupResponse::Found(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_editgroup_annotations( &self, param_editgroup_id: String, param_expand: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/annotations", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetEditgroupAnnotationsResponse::Success(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupAnnotationsResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupAnnotationsResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupAnnotationsResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupAnnotationsResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupAnnotationsResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_editgroups_reviewable( &self, param_expand: Option, param_limit: Option, param_before: Option>, param_since: Option>, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/reviewable", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_limit) = param_limit { query_string.append_pair("limit", ¶m_limit.to_string()); } if let Some(param_before) = param_before { query_string.append_pair("before", ¶m_before.to_string()); } if let Some(param_since) = param_since { query_string.append_pair("since", ¶m_since.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetEditgroupsReviewableResponse::Found(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupsReviewableResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupsReviewableResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditgroupsReviewableResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_editor( &self, param_editor_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editor/{editor_id}", self.base_path, editor_id = utf8_percent_encode(¶m_editor_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorResponse::Found(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_editor_annotations( &self, param_editor_id: String, param_limit: Option, param_before: Option>, param_since: Option>, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editor/{editor_id}/annotations", self.base_path, editor_id = utf8_percent_encode(¶m_editor_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_limit) = param_limit { query_string.append_pair("limit", ¶m_limit.to_string()); } if let Some(param_before) = param_before { query_string.append_pair("before", ¶m_before.to_string()); } if let Some(param_since) = param_since { query_string.append_pair("since", ¶m_since.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetEditorAnnotationsResponse::Success(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorAnnotationsResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorAnnotationsResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorAnnotationsResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorAnnotationsResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorAnnotationsResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_editor_editgroups( &self, param_editor_id: String, param_limit: Option, param_before: Option>, param_since: Option>, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editor/{editor_id}/editgroups", self.base_path, editor_id = utf8_percent_encode(¶m_editor_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_limit) = param_limit { query_string.append_pair("limit", ¶m_limit.to_string()); } if let Some(param_before) = param_before { query_string.append_pair("before", ¶m_before.to_string()); } if let Some(param_since) = param_since { query_string.append_pair("since", ¶m_since.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetEditorEditgroupsResponse::Found(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorEditgroupsResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorEditgroupsResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetEditorEditgroupsResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_file( &self, param_ident: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/file/{ident}", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileResponse::FoundEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_file_edit( &self, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/file/edit/{edit_id}", self.base_path, edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileEditResponse::FoundEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileEditResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_file_history( &self, param_ident: String, param_limit: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/file/{ident}/history", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_limit) = param_limit { query_string.append_pair("limit", ¶m_limit.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetFileHistoryResponse::FoundEntityHistory(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileHistoryResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileHistoryResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileHistoryResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_file_redirects( &self, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/file/{ident}/redirects", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetFileRedirectsResponse::FoundEntityRedirects(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileRedirectsResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileRedirectsResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileRedirectsResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_file_revision( &self, param_rev_id: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/file/rev/{rev_id}", self.base_path, rev_id = utf8_percent_encode(¶m_rev_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileRevisionResponse::FoundEntityRevision(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileRevisionResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileRevisionResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFileRevisionResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_fileset( &self, param_ident: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/fileset/{ident}", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetResponse::FoundEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_fileset_edit( &self, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/fileset/edit/{edit_id}", self.base_path, edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetEditResponse::FoundEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetEditResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_fileset_history( &self, param_ident: String, param_limit: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/fileset/{ident}/history", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_limit) = param_limit { query_string.append_pair("limit", ¶m_limit.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetFilesetHistoryResponse::FoundEntityHistory(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetHistoryResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetHistoryResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetHistoryResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_fileset_redirects( &self, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/fileset/{ident}/redirects", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetFilesetRedirectsResponse::FoundEntityRedirects(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetRedirectsResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetRedirectsResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetRedirectsResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_fileset_revision( &self, param_rev_id: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/fileset/rev/{rev_id}", self.base_path, rev_id = utf8_percent_encode(¶m_rev_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetRevisionResponse::FoundEntityRevision(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetRevisionResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetRevisionResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetFilesetRevisionResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_release( &self, param_ident: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseResponse::FoundEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_release_edit( &self, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/edit/{edit_id}", self.base_path, edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseEditResponse::FoundEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseEditResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_release_files( &self, param_ident: String, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}/files", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetReleaseFilesResponse::Found(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseFilesResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseFilesResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseFilesResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_release_filesets( &self, param_ident: String, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}/filesets", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetReleaseFilesetsResponse::Found(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseFilesetsResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseFilesetsResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseFilesetsResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_release_history( &self, param_ident: String, param_limit: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}/history", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_limit) = param_limit { query_string.append_pair("limit", ¶m_limit.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetReleaseHistoryResponse::FoundEntityHistory(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseHistoryResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseHistoryResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseHistoryResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_release_redirects( &self, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}/redirects", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetReleaseRedirectsResponse::FoundEntityRedirects(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseRedirectsResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseRedirectsResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseRedirectsResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_release_revision( &self, param_rev_id: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/rev/{rev_id}", self.base_path, rev_id = utf8_percent_encode(¶m_rev_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseRevisionResponse::FoundEntityRevision(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseRevisionResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseRevisionResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseRevisionResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_release_webcaptures( &self, param_ident: String, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}/webcaptures", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetReleaseWebcapturesResponse::Found(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseWebcapturesResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseWebcapturesResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetReleaseWebcapturesResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_webcapture( &self, param_ident: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/webcapture/{ident}", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureResponse::FoundEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_webcapture_edit( &self, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/webcapture/edit/{edit_id}", self.base_path, edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureEditResponse::FoundEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureEditResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_webcapture_history( &self, param_ident: String, param_limit: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/webcapture/{ident}/history", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_limit) = param_limit { query_string.append_pair("limit", ¶m_limit.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetWebcaptureHistoryResponse::FoundEntityHistory(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureHistoryResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureHistoryResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureHistoryResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_webcapture_redirects( &self, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/webcapture/{ident}/redirects", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetWebcaptureRedirectsResponse::FoundEntityRedirects(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureRedirectsResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureRedirectsResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureRedirectsResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_webcapture_revision( &self, param_rev_id: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/webcapture/rev/{rev_id}", self.base_path, rev_id = utf8_percent_encode(¶m_rev_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureRevisionResponse::FoundEntityRevision(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureRevisionResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureRevisionResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWebcaptureRevisionResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_work( &self, param_ident: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/{ident}", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkResponse::FoundEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_work_edit( &self, param_edit_id: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/edit/{edit_id}", self.base_path, edit_id = utf8_percent_encode(¶m_edit_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkEditResponse::FoundEdit(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkEditResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkEditResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkEditResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_work_history( &self, param_ident: String, param_limit: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/{ident}/history", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_limit) = param_limit { query_string.append_pair("limit", ¶m_limit.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetWorkHistoryResponse::FoundEntityHistory(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkHistoryResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkHistoryResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkHistoryResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_work_redirects( &self, param_ident: String, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/{ident}/redirects", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetWorkRedirectsResponse::FoundEntityRedirects(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkRedirectsResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkRedirectsResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkRedirectsResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_work_releases( &self, param_ident: String, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/{ident}/releases", self.base_path, ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::>(body)?; Ok(GetWorkReleasesResponse::Found(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkReleasesResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkReleasesResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkReleasesResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn get_work_revision( &self, param_rev_id: String, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/rev/{rev_id}", self.base_path, rev_id = utf8_percent_encode(¶m_rev_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkRevisionResponse::FoundEntityRevision(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkRevisionResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkRevisionResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(GetWorkRevisionResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn lookup_container( &self, param_issnl: Option, param_wikidata_qid: Option, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/container/lookup", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_issnl) = param_issnl { query_string.append_pair("issnl", ¶m_issnl.to_string()); } if let Some(param_wikidata_qid) = param_wikidata_qid { query_string.append_pair("wikidata_qid", ¶m_wikidata_qid.to_string()); } if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupContainerResponse::FoundEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupContainerResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupContainerResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupContainerResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn lookup_creator( &self, param_orcid: Option, param_wikidata_qid: Option, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/creator/lookup", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_orcid) = param_orcid { query_string.append_pair("orcid", ¶m_orcid.to_string()); } if let Some(param_wikidata_qid) = param_wikidata_qid { query_string.append_pair("wikidata_qid", ¶m_wikidata_qid.to_string()); } if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupCreatorResponse::FoundEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupCreatorResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupCreatorResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupCreatorResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn lookup_file( &self, param_md5: Option, param_sha1: Option, param_sha256: Option, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/file/lookup", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_md5) = param_md5 { query_string.append_pair("md5", ¶m_md5.to_string()); } if let Some(param_sha1) = param_sha1 { query_string.append_pair("sha1", ¶m_sha1.to_string()); } if let Some(param_sha256) = param_sha256 { query_string.append_pair("sha256", ¶m_sha256.to_string()); } if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupFileResponse::FoundEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupFileResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupFileResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupFileResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn lookup_release( &self, param_doi: Option, param_wikidata_qid: Option, param_isbn13: Option, param_pmid: Option, param_pmcid: Option, param_core: Option, param_arxiv: Option, param_jstor: Option, param_ark: Option, param_mag: Option, param_doaj: Option, param_dblp: Option, param_oai: Option, param_expand: Option, param_hide: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/release/lookup", self.base_path); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_doi) = param_doi { query_string.append_pair("doi", ¶m_doi.to_string()); } if let Some(param_wikidata_qid) = param_wikidata_qid { query_string.append_pair("wikidata_qid", ¶m_wikidata_qid.to_string()); } if let Some(param_isbn13) = param_isbn13 { query_string.append_pair("isbn13", ¶m_isbn13.to_string()); } if let Some(param_pmid) = param_pmid { query_string.append_pair("pmid", ¶m_pmid.to_string()); } if let Some(param_pmcid) = param_pmcid { query_string.append_pair("pmcid", ¶m_pmcid.to_string()); } if let Some(param_core) = param_core { query_string.append_pair("core", ¶m_core.to_string()); } if let Some(param_arxiv) = param_arxiv { query_string.append_pair("arxiv", ¶m_arxiv.to_string()); } if let Some(param_jstor) = param_jstor { query_string.append_pair("jstor", ¶m_jstor.to_string()); } if let Some(param_ark) = param_ark { query_string.append_pair("ark", ¶m_ark.to_string()); } if let Some(param_mag) = param_mag { query_string.append_pair("mag", ¶m_mag.to_string()); } if let Some(param_doaj) = param_doaj { query_string.append_pair("doaj", ¶m_doaj.to_string()); } if let Some(param_dblp) = param_dblp { query_string.append_pair("dblp", ¶m_dblp.to_string()); } if let Some(param_oai) = param_oai { query_string.append_pair("oai", ¶m_oai.to_string()); } if let Some(param_expand) = param_expand { query_string.append_pair("expand", ¶m_expand.to_string()); } if let Some(param_hide) = param_hide { query_string.append_pair("hide", ¶m_hide.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupReleaseResponse::FoundEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupReleaseResponse::BadRequest(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupReleaseResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(LookupReleaseResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn update_container( &self, param_editgroup_id: String, param_ident: String, param_container_entity: models::ContainerEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/container/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_container_entity) .expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateContainerResponse::UpdatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateContainerResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateContainerResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateContainerResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateContainerResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateContainerResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn update_creator( &self, param_editgroup_id: String, param_ident: String, param_creator_entity: models::CreatorEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/creator/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_creator_entity).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateCreatorResponse::UpdatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateCreatorResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateCreatorResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateCreatorResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateCreatorResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateCreatorResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn update_editgroup( &self, param_editgroup_id: String, param_editgroup: models::Editgroup, param_submit: Option, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); if let Some(param_submit) = param_submit { query_string.append_pair("submit", ¶m_submit.to_string()); } query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_editgroup).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditgroupResponse::UpdatedEditgroup(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditgroupResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditgroupResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditgroupResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditgroupResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditgroupResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn update_editor( &self, param_editor_id: String, param_editor: models::Editor, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editor/{editor_id}", self.base_path, editor_id = utf8_percent_encode(¶m_editor_id.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_editor).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditorResponse::UpdatedEditor(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditorResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditorResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditorResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditorResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateEditorResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn update_file( &self, param_editgroup_id: String, param_ident: String, param_file_entity: models::FileEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/file/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_file_entity).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFileResponse::UpdatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFileResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFileResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFileResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFileResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFileResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn update_fileset( &self, param_editgroup_id: String, param_ident: String, param_fileset_entity: models::FilesetEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/fileset/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_fileset_entity).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFilesetResponse::UpdatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFilesetResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFilesetResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFilesetResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFilesetResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateFilesetResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn update_release( &self, param_editgroup_id: String, param_ident: String, param_release_entity: models::ReleaseEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/release/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_release_entity).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateReleaseResponse::UpdatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateReleaseResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateReleaseResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateReleaseResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateReleaseResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateReleaseResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn update_webcapture( &self, param_editgroup_id: String, param_ident: String, param_webcapture_entity: models::WebcaptureEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/webcapture/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_webcapture_entity) .expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWebcaptureResponse::UpdatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWebcaptureResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWebcaptureResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWebcaptureResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWebcaptureResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWebcaptureResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } async fn update_work( &self, param_editgroup_id: String, param_ident: String, param_work_entity: models::WorkEntity, context: &C, ) -> Result { let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/work/{ident}", self.base_path, editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), ID_ENCODE_SET), ident = utf8_percent_encode(¶m_ident.to_string(), ID_ENCODE_SET) ); // Query parameters let query_string = { let mut query_string = form_urlencoded::Serializer::new("".to_owned()); query_string.finish() }; if !query_string.is_empty() { uri += "?"; uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_work_entity).expect("impossible to fail to serialize"); *request.body_mut() = Body::from(body); let header = "application/json"; request.headers_mut().insert( CONTENT_TYPE, match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create header: {} - {}", header, e ))) } }, ); let header = HeaderValue::from_str( Has::::get(context) .0 .clone() .to_string() .as_str(), ); request.headers_mut().insert( HeaderName::from_static("x-span-id"), match header { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e ))) } }, ); if let Some(auth_data) = Has::>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { let auth = swagger::auth::Header(bearer_header.clone()); let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { return Err(ApiError(format!( "Unable to create Authorization header: {}", e ))) } }; request .headers_mut() .insert(hyper::header::AUTHORIZATION, header); } _ => {} } } let mut response = client_service .call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))) .await?; match response.status().as_u16() { 200 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWorkResponse::UpdatedEntity(body)) } 400 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWorkResponse::BadRequest(body)) } 401 => { let response_www_authenticate = match response .headers() .get(HeaderName::from_static("www_authenticate")) { Some(response_www_authenticate) => { let response_www_authenticate = response_www_authenticate.clone(); let response_www_authenticate = match TryInto::< header::IntoHeaderValue, >::try_into( response_www_authenticate ) { Ok(value) => value, Err(e) => { return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } }; let response_www_authenticate = response_www_authenticate.0; Some(response_www_authenticate) } None => None, }; let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWorkResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate, }) } 403 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWorkResponse::Forbidden(body)) } 404 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWorkResponse::NotFound(body)) } 500 => { let body = response.into_body(); let body = body .to_raw() .map_err(|e| ApiError(format!("Failed to read response: {}", e))) .await?; let body = str::from_utf8(&body) .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(body)?; Ok(UpdateWorkResponse::GenericError(body)) } code => { let headers = response.headers().clone(); let body = response.into_body().take(100).to_raw().await; Err(ApiError(format!( "Unexpected response code {}:\n{:?}\n\n{}", code, headers, match body { Ok(body) => match String::from_utf8(body) { Ok(body) => body, Err(e) => format!("", e), }, Err(e) => format!("", e), } ))) } } } }