aboutsummaryrefslogtreecommitdiffstats
path: root/rust/fatcat-openapi/src/client/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/fatcat-openapi/src/client/mod.rs')
-rw-r--r--rust/fatcat-openapi/src/client/mod.rs24991
1 files changed, 10375 insertions, 14616 deletions
diff --git a/rust/fatcat-openapi/src/client/mod.rs b/rust/fatcat-openapi/src/client/mod.rs
index 06ecf4c..bb1cee8 100644
--- a/rust/fatcat-openapi/src/client/mod.rs
+++ b/rust/fatcat-openapi/src/client/mod.rs
@@ -1,37 +1,45 @@
-use futures;
-use futures::{future, stream, Future, Stream};
-use hyper;
-use hyper::client::HttpConnector;
+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::{Body, Response, Uri};
-#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
-use hyper_openssl::HttpsConnector;
-use serde_json;
+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;
+use std::error::Error;
use std::fmt;
-use std::io::{Error, ErrorKind, Read};
+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;
-use swagger;
-use swagger::{client::Service, ApiError, AuthData, Connector, Has, XSpanIdString};
+use std::sync::{Arc, Mutex};
+use std::task::{Context, Poll};
+use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString};
use url::form_urlencoded;
-use url::percent_encoding::{utf8_percent_encode, PATH_SEGMENT_ENCODE_SET, QUERY_ENCODE_SET};
use crate::header;
use crate::models;
-url::define_encode_set! {
- /// 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.
- pub ID_ENCODE_SET = [PATH_SEGMENT_ENCODE_SET] | {'|'}
-}
+/// 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,
@@ -67,13 +75,13 @@ use crate::{
/// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes.
fn into_base_path(
- input: &str,
+ input: impl TryInto<Uri, Error = hyper::http::uri::InvalidUri>,
correct_scheme: Option<&'static str>,
) -> Result<String, ClientInitError> {
// First convert to Uri, since a base path is a subset of Uri.
- let uri = Uri::from_str(input)?;
+ let uri = input.try_into()?;
- let scheme = uri.scheme_part().ok_or(ClientInitError::InvalidScheme)?;
+ let scheme = uri.scheme_str().ok_or(ClientInitError::InvalidScheme)?;
// Check the scheme if necessary
if let Some(correct_scheme) = correct_scheme {
@@ -84,7 +92,7 @@ fn into_base_path(
let host = uri.host().ok_or_else(|| ClientInitError::MissingHost)?;
let port = uri
- .port_part()
+ .port_u16()
.map(|x| format!(":{}", x))
.unwrap_or_default();
Ok(format!(
@@ -97,30 +105,56 @@ fn into_base_path(
}
/// A client that implements the API by making HTTP calls out to a server.
-pub struct Client<F> {
+pub struct Client<S, C>
+where
+ S: Service<(Request<Body>, C), Response = Response<Body>> + Clone + Sync + Send + 'static,
+ S::Future: Send + 'static,
+ S::Error: Into<crate::ServiceError> + fmt::Display,
+ C: Clone + Send + Sync + 'static,
+{
/// Inner service
- client_service: Arc<Box<dyn Service<ReqBody = Body, Future = F> + Send + Sync>>,
+ client_service: S,
/// Base path of the API
base_path: String,
+
+ /// Marker
+ marker: PhantomData<fn(C)>,
}
-impl<F> fmt::Debug for Client<F> {
+impl<S, C> fmt::Debug for Client<S, C>
+where
+ S: Service<(Request<Body>, C), Response = Response<Body>> + Clone + Sync + Send + 'static,
+ S::Future: Send + 'static,
+ S::Error: Into<crate::ServiceError> + 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<F> Clone for Client<F> {
+impl<S, C> Clone for Client<S, C>
+where
+ S: Service<(Request<Body>, C), Response = Response<Body>> + Clone + Sync + Send + 'static,
+ S::Future: Send + 'static,
+ S::Error: Into<crate::ServiceError> + fmt::Display,
+ C: Clone + Send + Sync + 'static,
+{
fn clone(&self) -> Self {
- Client {
+ Self {
client_service: self.client_service.clone(),
base_path: self.base_path.clone(),
+ marker: PhantomData,
}
}
}
-impl Client<hyper::client::ResponseFuture> {
+impl<Connector, C> Client<DropContextService<hyper::client::Client<Connector, Body>, 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
@@ -132,41 +166,120 @@ impl Client<hyper::client::ResponseFuture> {
///
/// # Arguments
///
- /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
+ /// * `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<C>(
+ pub fn try_new_with_connector(
base_path: &str,
protocol: Option<&'static str>,
- connector: C,
- ) -> Result<Self, ClientInitError>
- where
- C: hyper::client::connect::Connect + 'static,
- C::Transport: 'static,
- C::Future: 'static,
- {
- let client_service = Box::new(hyper::client::Client::builder().build(connector));
+ connector: Connector,
+ ) -> Result<Self, ClientInitError> {
+ let client_service = hyper::client::Client::builder().build(connector);
+ let client_service = DropContextService::new(client_service);
- Ok(Client {
- client_service: Arc::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<hyper::client::HttpConnector, Body>),
+ Https(hyper::client::Client<HttpsConnector, Body>),
+}
+
+impl Service<Request<Body>> for HyperClient {
+ type Response = Response<Body>;
+ type Error = hyper::Error;
+ type Future = hyper::client::ResponseFuture;
+
+ fn poll_ready(&mut self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
+ match self {
+ HyperClient::Http(client) => client.poll_ready(cx),
+ HyperClient::Https(client) => client.poll_ready(cx),
+ }
+ }
+
+ fn call(&mut self, req: Request<Body>) -> Self::Future {
+ match self {
+ HyperClient::Http(client) => client.call(req),
+ HyperClient::Https(client) => client.call(req),
+ }
+ }
+}
+
+impl<C> Client<DropContextService<HyperClient, 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(base_path: &str) -> Result<Self, ClientInitError> {
+ 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<C> Client<DropContextService<hyper::client::Client<hyper::client::HttpConnector, Body>, C>, C>
+where
+ C: Clone + Send + Sync + 'static,
+{
/// Create an HTTP client.
///
/// # Arguments
- /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
+ /// * `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<Self, ClientInitError> {
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<hyper::client::HttpConnector>;
+
+#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
+type HttpsConnector = hyper_openssl::HttpsConnector<hyper::client::HttpConnector>;
+impl<C> Client<DropContextService<hyper::client::Client<HttpsConnector, Body>, 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. "www.my-api-implementation.com"
+ /// * `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<Self, ClientInitError> {
let https_connector = Connector::builder()
.https()
@@ -178,7 +291,7 @@ impl Client<hyper::client::ResponseFuture> {
/// 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. "www.my-api-implementation.com"
+ /// * `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<CA>(
@@ -199,7 +312,7 @@ impl Client<hyper::client::ResponseFuture> {
/// Create a client with a mutually authenticated TLS connection to the server.
///
/// # Arguments
- /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
+ /// * `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
@@ -225,17 +338,25 @@ impl Client<hyper::client::ResponseFuture> {
}
}
-impl<F> Client<F> {
- /// Constructor for creating a `Client` by passing in a pre-made `swagger::Service`
+impl<S, C> Client<S, C>
+where
+ S: Service<(Request<Body>, C), Response = Response<Body>> + Clone + Sync + Send + 'static,
+ S::Future: Send + 'static,
+ S::Error: Into<crate::ServiceError> + 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: Arc<Box<dyn Service<ReqBody = Body, Future = F> + Send + Sync>>,
+ client_service: S,
base_path: &str,
) -> Result<Self, ClientInitError> {
- Ok(Client {
- client_service: client_service,
+ Ok(Self {
+ client_service,
base_path: into_base_path(base_path, None)?,
+ marker: PhantomData,
})
}
}
@@ -274,22 +395,34 @@ impl fmt::Display for ClientInitError {
}
}
-impl error::Error for ClientInitError {
+impl Error for ClientInitError {
fn description(&self) -> &str {
"Failed to produce a hyper client."
}
}
-impl<C, F> Api<C> for Client<F>
+#[async_trait]
+impl<S, C> Api<C> for Client<S, C>
where
- C: Has<XSpanIdString> + Has<Option<AuthData>>,
- F: Future<Item = Response<Body>, Error = hyper::Error> + Send + 'static,
+ S: Service<(Request<Body>, C), Response = Response<Body>> + Clone + Sync + Send + 'static,
+ S::Future: Send + 'static,
+ S::Error: Into<crate::ServiceError> + fmt::Display,
+ C: Has<XSpanIdString> + Has<Option<AuthData>> + Clone + Send + Sync + 'static,
{
- fn accept_editgroup(
+ fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), crate::ServiceError>> {
+ 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,
- ) -> Box<dyn Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send> {
+ ) -> Result<AcceptEditgroupResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/accept",
self.base_path,
@@ -297,40 +430,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -341,15 +465,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -357,10 +481,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -371,233 +495,170 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Success>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AcceptEditgroupResponse::MergedSuccessfully
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AcceptEditgroupResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AcceptEditgroupResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Success>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AcceptEditgroupResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AcceptEditgroupResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 409 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AcceptEditgroupResponse::EditConflict
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AcceptEditgroupResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn auth_check(
+ async fn auth_check(
&self,
param_role: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = AuthCheckResponse, Error = ApiError> + Send> {
+ ) -> Result<AuthCheckResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/auth/check", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_role) = param_role {
- query_string.append_pair("role", &param_role.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_role.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -608,15 +669,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -624,10 +685,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -638,185 +699,141 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Success>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthCheckResponse::Success
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthCheckResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthCheckResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Success>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthCheckResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthCheckResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn auth_oidc(
+ async fn auth_oidc(
&self,
param_auth_oidc: models::AuthOidc,
context: &C,
- ) -> Box<dyn Future<Item = AuthOidcResponse, Error = ApiError> + Send> {
+ ) -> Result<AuthOidcResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/auth/oidc", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -829,16 +846,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -849,15 +865,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -865,10 +881,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -879,194 +895,140 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::AuthOidcResult>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthOidcResponse::Found
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::AuthOidcResult>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthOidcResponse::Created
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthOidcResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthOidcResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::AuthOidcResult>(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::<models::AuthOidcResult>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthOidcResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 409 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthOidcResponse::Conflict
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- AuthOidcResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_auth_token(
+ async fn create_auth_token(
&self,
param_editor_id: String,
param_duration_seconds: Option<i32>,
context: &C,
- ) -> Box<dyn Future<Item = CreateAuthTokenResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateAuthTokenResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/auth/token/{editor_id}",
self.base_path,
@@ -1074,43 +1036,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_duration_seconds) = param_duration_seconds {
- query_string.append_pair("duration_seconds", &param_duration_seconds.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_duration_seconds.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -1121,15 +1074,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -1137,10 +1090,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -1151,154 +1104,118 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::AuthTokenResult>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateAuthTokenResponse::Success
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateAuthTokenResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateAuthTokenResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::AuthTokenResult>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateAuthTokenResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateAuthTokenResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_container(
+ async fn create_container(
&self,
param_editgroup_id: String,
param_container_entity: models::ContainerEntity,
context: &C,
- ) -> Box<dyn Future<Item = CreateContainerResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateContainerResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/container",
self.base_path,
@@ -1306,35 +1223,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body = serde_json::to_string(&param_container_entity)
@@ -1347,16 +1256,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -1367,15 +1275,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -1383,10 +1291,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -1397,205 +1305,152 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerResponse::CreatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_container_auto_batch(
+ async fn create_container_auto_batch(
&self,
param_container_auto_batch: models::ContainerAutoBatch,
context: &C,
- ) -> Box<dyn Future<Item = CreateContainerAutoBatchResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateContainerAutoBatchResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/editgroup/auto/container/batch", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body = serde_json::to_string(&param_container_auto_batch)
@@ -1608,16 +1463,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -1628,15 +1482,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -1644,10 +1498,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -1658,174 +1512,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Editgroup>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerAutoBatchResponse::CreatedEditgroup
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerAutoBatchResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerAutoBatchResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Editgroup>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerAutoBatchResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerAutoBatchResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateContainerAutoBatchResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_creator(
+ async fn create_creator(
&self,
param_editgroup_id: String,
param_creator_entity: models::CreatorEntity,
context: &C,
- ) -> Box<dyn Future<Item = CreateCreatorResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateCreatorResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/creator",
self.base_path,
@@ -1833,35 +1642,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -1874,16 +1675,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -1894,15 +1694,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -1910,10 +1710,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -1924,205 +1724,152 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorResponse::CreatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_creator_auto_batch(
+ async fn create_creator_auto_batch(
&self,
param_creator_auto_batch: models::CreatorAutoBatch,
context: &C,
- ) -> Box<dyn Future<Item = CreateCreatorAutoBatchResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateCreatorAutoBatchResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/editgroup/auto/creator/batch", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body = serde_json::to_string(&param_creator_auto_batch)
@@ -2135,16 +1882,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -2155,15 +1901,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -2171,10 +1917,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -2185,205 +1931,152 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Editgroup>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorAutoBatchResponse::CreatedEditgroup
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorAutoBatchResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorAutoBatchResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Editgroup>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorAutoBatchResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorAutoBatchResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateCreatorAutoBatchResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_editgroup(
+ async fn create_editgroup(
&self,
param_editgroup: models::Editgroup,
context: &C,
- ) -> Box<dyn Future<Item = CreateEditgroupResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateEditgroupResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/editgroup", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -2396,16 +2089,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -2416,15 +2108,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -2432,10 +2124,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -2446,174 +2138,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Editgroup>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupResponse::SuccessfullyCreated
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Editgroup>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_editgroup_annotation(
+ async fn create_editgroup_annotation(
&self,
param_editgroup_id: String,
param_editgroup_annotation: models::EditgroupAnnotation,
context: &C,
- ) -> Box<dyn Future<Item = CreateEditgroupAnnotationResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateEditgroupAnnotationResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/annotation",
self.base_path,
@@ -2621,35 +2268,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body = serde_json::to_string(&param_editgroup_annotation)
@@ -2662,16 +2301,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -2682,15 +2320,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -2698,10 +2336,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -2712,174 +2350,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EditgroupAnnotation>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupAnnotationResponse::Created
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupAnnotationResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupAnnotationResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EditgroupAnnotation>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupAnnotationResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupAnnotationResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateEditgroupAnnotationResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_file(
+ async fn create_file(
&self,
param_editgroup_id: String,
param_file_entity: models::FileEntity,
context: &C,
- ) -> Box<dyn Future<Item = CreateFileResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateFileResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/file",
self.base_path,
@@ -2887,35 +2480,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -2928,16 +2513,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -2948,15 +2532,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -2964,10 +2548,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -2978,205 +2562,152 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileResponse::CreatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_file_auto_batch(
+ async fn create_file_auto_batch(
&self,
param_file_auto_batch: models::FileAutoBatch,
context: &C,
- ) -> Box<dyn Future<Item = CreateFileAutoBatchResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateFileAutoBatchResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/editgroup/auto/file/batch", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -3189,16 +2720,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -3209,15 +2739,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -3225,10 +2755,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -3239,174 +2769,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Editgroup>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileAutoBatchResponse::CreatedEditgroup
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileAutoBatchResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileAutoBatchResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Editgroup>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileAutoBatchResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileAutoBatchResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFileAutoBatchResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_fileset(
+ async fn create_fileset(
&self,
param_editgroup_id: String,
param_fileset_entity: models::FilesetEntity,
context: &C,
- ) -> Box<dyn Future<Item = CreateFilesetResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateFilesetResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/fileset",
self.base_path,
@@ -3414,35 +2899,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -3455,16 +2932,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -3475,15 +2951,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -3491,10 +2967,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -3505,205 +2981,152 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetResponse::CreatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_fileset_auto_batch(
+ async fn create_fileset_auto_batch(
&self,
param_fileset_auto_batch: models::FilesetAutoBatch,
context: &C,
- ) -> Box<dyn Future<Item = CreateFilesetAutoBatchResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateFilesetAutoBatchResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/editgroup/auto/fileset/batch", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body = serde_json::to_string(&param_fileset_auto_batch)
@@ -3716,16 +3139,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -3736,15 +3158,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -3752,10 +3174,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -3766,174 +3188,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Editgroup>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetAutoBatchResponse::CreatedEditgroup
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetAutoBatchResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetAutoBatchResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Editgroup>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetAutoBatchResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetAutoBatchResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateFilesetAutoBatchResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_release(
+ async fn create_release(
&self,
param_editgroup_id: String,
param_release_entity: models::ReleaseEntity,
context: &C,
- ) -> Box<dyn Future<Item = CreateReleaseResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateReleaseResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/release",
self.base_path,
@@ -3941,35 +3318,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -3982,16 +3351,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -4002,15 +3370,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -4018,10 +3386,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -4032,205 +3400,152 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseResponse::CreatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_release_auto_batch(
+ async fn create_release_auto_batch(
&self,
param_release_auto_batch: models::ReleaseAutoBatch,
context: &C,
- ) -> Box<dyn Future<Item = CreateReleaseAutoBatchResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateReleaseAutoBatchResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/editgroup/auto/release/batch", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body = serde_json::to_string(&param_release_auto_batch)
@@ -4243,16 +3558,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -4263,15 +3577,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -4279,10 +3593,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -4293,174 +3607,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Editgroup>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseAutoBatchResponse::CreatedEditgroup
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseAutoBatchResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseAutoBatchResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Editgroup>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseAutoBatchResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseAutoBatchResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateReleaseAutoBatchResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_webcapture(
+ async fn create_webcapture(
&self,
param_editgroup_id: String,
param_webcapture_entity: models::WebcaptureEntity,
context: &C,
- ) -> Box<dyn Future<Item = CreateWebcaptureResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateWebcaptureResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/webcapture",
self.base_path,
@@ -4468,35 +3737,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body = serde_json::to_string(&param_webcapture_entity)
@@ -4509,16 +3770,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -4529,15 +3789,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -4545,10 +3805,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -4559,205 +3819,152 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureResponse::CreatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_webcapture_auto_batch(
+ async fn create_webcapture_auto_batch(
&self,
param_webcapture_auto_batch: models::WebcaptureAutoBatch,
context: &C,
- ) -> Box<dyn Future<Item = CreateWebcaptureAutoBatchResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateWebcaptureAutoBatchResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/editgroup/auto/webcapture/batch", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body = serde_json::to_string(&param_webcapture_auto_batch)
@@ -4770,16 +3977,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -4790,15 +3996,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -4806,10 +4012,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -4820,174 +4026,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Editgroup>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureAutoBatchResponse::CreatedEditgroup
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureAutoBatchResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureAutoBatchResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Editgroup>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureAutoBatchResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureAutoBatchResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWebcaptureAutoBatchResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_work(
+ async fn create_work(
&self,
param_editgroup_id: String,
param_work_entity: models::WorkEntity,
context: &C,
- ) -> Box<dyn Future<Item = CreateWorkResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateWorkResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/work",
self.base_path,
@@ -4995,35 +4156,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -5036,16 +4189,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -5056,15 +4208,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -5072,10 +4224,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -5086,205 +4238,152 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkResponse::CreatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn create_work_auto_batch(
+ async fn create_work_auto_batch(
&self,
param_work_auto_batch: models::WorkAutoBatch,
context: &C,
- ) -> Box<dyn Future<Item = CreateWorkAutoBatchResponse, Error = ApiError> + Send> {
+ ) -> Result<CreateWorkAutoBatchResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/editgroup/auto/work/batch", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("POST")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -5297,16 +4396,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -5317,15 +4415,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -5333,10 +4431,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -5347,174 +4445,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 201 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Editgroup>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkAutoBatchResponse::CreatedEditgroup
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkAutoBatchResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkAutoBatchResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Editgroup>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkAutoBatchResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkAutoBatchResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- CreateWorkAutoBatchResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_container(
+ async fn delete_container(
&self,
param_editgroup_id: String,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteContainerResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteContainerResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/container/{ident}",
self.base_path,
@@ -5523,40 +4576,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -5567,15 +4611,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -5583,10 +4627,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -5597,174 +4641,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerResponse::DeletedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_container_edit(
+ async fn delete_container_edit(
&self,
param_editgroup_id: String,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteContainerEditResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteContainerEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/container/edit/{edit_id}",
self.base_path,
@@ -5773,40 +4772,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -5817,15 +4807,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -5833,10 +4823,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -5847,174 +4837,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Success>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerEditResponse::DeletedEdit
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerEditResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerEditResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Success>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerEditResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerEditResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteContainerEditResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_creator(
+ async fn delete_creator(
&self,
param_editgroup_id: String,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteCreatorResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteCreatorResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/creator/{ident}",
self.base_path,
@@ -6023,40 +4968,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -6067,15 +5003,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -6083,10 +5019,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -6097,174 +5033,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorResponse::DeletedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_creator_edit(
+ async fn delete_creator_edit(
&self,
param_editgroup_id: String,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteCreatorEditResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteCreatorEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/creator/edit/{edit_id}",
self.base_path,
@@ -6273,40 +5164,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -6317,15 +5199,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -6333,10 +5215,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -6347,174 +5229,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Success>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorEditResponse::DeletedEdit
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorEditResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorEditResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Success>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorEditResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorEditResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteCreatorEditResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_file(
+ async fn delete_file(
&self,
param_editgroup_id: String,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteFileResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteFileResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/file/{ident}",
self.base_path,
@@ -6523,40 +5360,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -6567,15 +5395,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -6583,10 +5411,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -6597,174 +5425,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileResponse::DeletedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_file_edit(
+ async fn delete_file_edit(
&self,
param_editgroup_id: String,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteFileEditResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteFileEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/file/edit/{edit_id}",
self.base_path,
@@ -6773,40 +5556,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -6817,15 +5591,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -6833,10 +5607,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -6847,174 +5621,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Success>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileEditResponse::DeletedEdit
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileEditResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileEditResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Success>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileEditResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileEditResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFileEditResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_fileset(
+ async fn delete_fileset(
&self,
param_editgroup_id: String,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteFilesetResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteFilesetResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/fileset/{ident}",
self.base_path,
@@ -7023,40 +5752,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -7067,15 +5787,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -7083,10 +5803,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -7097,174 +5817,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetResponse::DeletedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_fileset_edit(
+ async fn delete_fileset_edit(
&self,
param_editgroup_id: String,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteFilesetEditResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteFilesetEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/fileset/edit/{edit_id}",
self.base_path,
@@ -7273,40 +5948,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -7317,15 +5983,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -7333,10 +5999,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -7347,174 +6013,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Success>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetEditResponse::DeletedEdit
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetEditResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetEditResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Success>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetEditResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetEditResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteFilesetEditResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_release(
+ async fn delete_release(
&self,
param_editgroup_id: String,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteReleaseResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteReleaseResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/release/{ident}",
self.base_path,
@@ -7523,40 +6144,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -7567,15 +6179,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -7583,10 +6195,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -7597,174 +6209,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseResponse::DeletedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_release_edit(
+ async fn delete_release_edit(
&self,
param_editgroup_id: String,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteReleaseEditResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteReleaseEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/release/edit/{edit_id}",
self.base_path,
@@ -7773,40 +6340,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -7817,15 +6375,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -7833,10 +6391,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -7847,174 +6405,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Success>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseEditResponse::DeletedEdit
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseEditResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseEditResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Success>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseEditResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseEditResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteReleaseEditResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_webcapture(
+ async fn delete_webcapture(
&self,
param_editgroup_id: String,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteWebcaptureResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteWebcaptureResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/webcapture/{ident}",
self.base_path,
@@ -8023,40 +6536,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -8067,15 +6571,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -8083,10 +6587,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -8097,174 +6601,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureResponse::DeletedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_webcapture_edit(
+ async fn delete_webcapture_edit(
&self,
param_editgroup_id: String,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteWebcaptureEditResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteWebcaptureEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/webcapture/edit/{edit_id}",
self.base_path,
@@ -8273,40 +6732,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -8317,15 +6767,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -8333,10 +6783,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -8347,174 +6797,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Success>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureEditResponse::DeletedEdit
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureEditResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureEditResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Success>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureEditResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureEditResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWebcaptureEditResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_work(
+ async fn delete_work(
&self,
param_editgroup_id: String,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteWorkResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteWorkResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/work/{ident}",
self.base_path,
@@ -8523,40 +6928,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -8567,15 +6963,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -8583,10 +6979,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -8597,174 +6993,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkResponse::DeletedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn delete_work_edit(
+ async fn delete_work_edit(
&self,
param_editgroup_id: String,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = DeleteWorkEditResponse, Error = ApiError> + Send> {
+ ) -> Result<DeleteWorkEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/work/edit/{edit_id}",
self.base_path,
@@ -8773,40 +7124,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("DELETE")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -8817,15 +7159,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -8833,10 +7175,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -8847,213 +7189,159 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Success>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkEditResponse::DeletedEdit
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkEditResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkEditResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Success>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkEditResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkEditResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- DeleteWorkEditResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn get_changelog(
+ async fn get_changelog(
&self,
param_limit: Option<i64>,
context: &C,
- ) -> Box<dyn Future<Item = GetChangelogResponse, Error = ApiError> + Send> {
+ ) -> Result<GetChangelogResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/changelog", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_limit) = param_limit {
- query_string.append_pair("limit", &param_limit.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_limit.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -9064,102 +7352,78 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::ChangelogEntry>>(
- body,
- )
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetChangelogResponse::Success(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetChangelogResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetChangelogResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::ChangelogEntry>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_changelog_entry(
+ async fn get_changelog_entry(
&self,
param_index: i64,
context: &C,
- ) -> Box<dyn Future<Item = GetChangelogEntryResponse, Error = ApiError> + Send> {
+ ) -> Result<GetChangelogEntryResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/changelog/{index}",
self.base_path,
@@ -9167,40 +7431,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -9211,122 +7466,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ChangelogEntry>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetChangelogEntryResponse::FoundChangelogEntry(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetChangelogEntryResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetChangelogEntryResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetChangelogEntryResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::ChangelogEntry>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_container(
+ async fn get_container(
&self,
param_ident: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetContainerResponse, Error = ApiError> + Send> {
+ ) -> Result<GetContainerResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/container/{ident}",
self.base_path,
@@ -9334,46 +7558,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -9384,118 +7599,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ContainerEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerResponse::FoundEntity(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::ContainerEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_container_edit(
+ async fn get_container_edit(
&self,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = GetContainerEditResponse, Error = ApiError> + Send> {
+ ) -> Result<GetContainerEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/container/edit/{edit_id}",
self.base_path,
@@ -9503,40 +7689,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -9547,119 +7724,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerEditResponse::FoundEdit(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerEditResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerEditResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerEditResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_container_history(
+ async fn get_container_history(
&self,
param_ident: String,
param_limit: Option<i64>,
context: &C,
- ) -> Box<dyn Future<Item = GetContainerHistoryResponse, Error = ApiError> + Send> {
+ ) -> Result<GetContainerHistoryResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/container/{ident}/history",
self.base_path,
@@ -9667,43 +7815,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_limit) = param_limit {
- query_string.append_pair("limit", &param_limit.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_limit.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -9714,122 +7853,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::EntityHistoryEntry>>(
- body,
- )
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetContainerHistoryResponse::FoundEntityHistory(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerHistoryResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerHistoryResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerHistoryResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::EntityHistoryEntry>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_container_redirects(
+ async fn get_container_redirects(
&self,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = GetContainerRedirectsResponse, Error = ApiError> + Send> {
+ ) -> Result<GetContainerRedirectsResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/container/{ident}/redirects",
self.base_path,
@@ -9837,40 +7943,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -9881,122 +7978,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<String>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetContainerRedirectsResponse::FoundEntityRedirects(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerRedirectsResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerRedirectsResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerRedirectsResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<String>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_container_revision(
+ async fn get_container_revision(
&self,
param_rev_id: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetContainerRevisionResponse, Error = ApiError> + Send> {
+ ) -> Result<GetContainerRevisionResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/container/rev/{rev_id}",
self.base_path,
@@ -10004,46 +8070,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -10054,122 +8111,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ContainerEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetContainerRevisionResponse::FoundEntityRevision(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerRevisionResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerRevisionResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetContainerRevisionResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::ContainerEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_creator(
+ async fn get_creator(
&self,
param_ident: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetCreatorResponse, Error = ApiError> + Send> {
+ ) -> Result<GetCreatorResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/creator/{ident}",
self.base_path,
@@ -10177,46 +8203,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -10227,118 +8244,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::CreatorEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorResponse::FoundEntity(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::CreatorEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_creator_edit(
+ async fn get_creator_edit(
&self,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = GetCreatorEditResponse, Error = ApiError> + Send> {
+ ) -> Result<GetCreatorEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/creator/edit/{edit_id}",
self.base_path,
@@ -10346,40 +8334,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -10390,119 +8369,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorEditResponse::FoundEdit(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorEditResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorEditResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorEditResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_creator_history(
+ async fn get_creator_history(
&self,
param_ident: String,
param_limit: Option<i64>,
context: &C,
- ) -> Box<dyn Future<Item = GetCreatorHistoryResponse, Error = ApiError> + Send> {
+ ) -> Result<GetCreatorHistoryResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/creator/{ident}/history",
self.base_path,
@@ -10510,43 +8460,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_limit) = param_limit {
- query_string.append_pair("limit", &param_limit.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_limit.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -10557,122 +8498,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::EntityHistoryEntry>>(
- body,
- )
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetCreatorHistoryResponse::FoundEntityHistory(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorHistoryResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorHistoryResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorHistoryResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::EntityHistoryEntry>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_creator_redirects(
+ async fn get_creator_redirects(
&self,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = GetCreatorRedirectsResponse, Error = ApiError> + Send> {
+ ) -> Result<GetCreatorRedirectsResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/creator/{ident}/redirects",
self.base_path,
@@ -10680,40 +8588,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -10724,121 +8623,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<String>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetCreatorRedirectsResponse::FoundEntityRedirects(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorRedirectsResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorRedirectsResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorRedirectsResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<String>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_creator_releases(
+ async fn get_creator_releases(
&self,
param_ident: String,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetCreatorReleasesResponse, Error = ApiError> + Send> {
+ ) -> Result<GetCreatorReleasesResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/creator/{ident}/releases",
self.base_path,
@@ -10846,43 +8714,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -10893,120 +8752,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::ReleaseEntity>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorReleasesResponse::Found(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorReleasesResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorReleasesResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorReleasesResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::ReleaseEntity>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_creator_revision(
+ async fn get_creator_revision(
&self,
param_rev_id: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetCreatorRevisionResponse, Error = ApiError> + Send> {
+ ) -> Result<GetCreatorRevisionResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/creator/rev/{rev_id}",
self.base_path,
@@ -11014,46 +8844,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -11064,120 +8885,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::CreatorEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetCreatorRevisionResponse::FoundEntityRevision(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorRevisionResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorRevisionResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetCreatorRevisionResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::CreatorEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_editgroup(
+ async fn get_editgroup(
&self,
param_editgroup_id: String,
context: &C,
- ) -> Box<dyn Future<Item = GetEditgroupResponse, Error = ApiError> + Send> {
+ ) -> Result<GetEditgroupResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}",
self.base_path,
@@ -11185,40 +8975,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -11229,119 +9010,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::Editgroup>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditgroupResponse::Found(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditgroupResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditgroupResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditgroupResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::Editgroup>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_editgroup_annotations(
+ async fn get_editgroup_annotations(
&self,
param_editgroup_id: String,
param_expand: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetEditgroupAnnotationsResponse, Error = ApiError> + Send> {
+ ) -> Result<GetEditgroupAnnotationsResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/annotations",
self.base_path,
@@ -11349,43 +9101,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -11396,233 +9139,179 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<Vec<models::EditgroupAnnotation>>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditgroupAnnotationsResponse::Success
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditgroupAnnotationsResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditgroupAnnotationsResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<Vec<models::EditgroupAnnotation>>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditgroupAnnotationsResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditgroupAnnotationsResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditgroupAnnotationsResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn get_editgroups_reviewable(
+ async fn get_editgroups_reviewable(
&self,
param_expand: Option<String>,
param_limit: Option<i64>,
param_before: Option<chrono::DateTime<chrono::Utc>>,
param_since: Option<chrono::DateTime<chrono::Utc>>,
context: &C,
- ) -> Box<dyn Future<Item = GetEditgroupsReviewableResponse, Error = ApiError> + Send> {
+ ) -> Result<GetEditgroupsReviewableResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/editgroup/reviewable", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_limit) = param_limit {
- query_string.append_pair("limit", &param_limit.to_string());
- }
- if let Some(param_before) = param_before {
- query_string.append_pair("before", &param_before.to_string());
- }
- if let Some(param_since) = param_since {
- query_string.append_pair("since", &param_since.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_limit) = param_limit {
+ query_string.append_pair("limit", &param_limit.to_string());
+ }
+ if let Some(param_before) = param_before {
+ query_string.append_pair("before", &param_before.to_string());
+ }
+ if let Some(param_since) = param_since {
+ query_string.append_pair("since", &param_since.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -11633,120 +9322,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::Editgroup>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditgroupsReviewableResponse::Found(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditgroupsReviewableResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditgroupsReviewableResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetEditgroupsReviewableResponse::GenericError(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::Editgroup>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_editor(
+ async fn get_editor(
&self,
param_editor_id: String,
context: &C,
- ) -> Box<dyn Future<Item = GetEditorResponse, Error = ApiError> + Send> {
+ ) -> Result<GetEditorResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editor/{editor_id}",
self.base_path,
@@ -11754,40 +9412,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -11798,121 +9447,92 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::Editor>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditorResponse::Found(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditorResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditorResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditorResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::Editor>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_editor_annotations(
+ async fn get_editor_annotations(
&self,
param_editor_id: String,
param_limit: Option<i64>,
param_before: Option<chrono::DateTime<chrono::Utc>>,
param_since: Option<chrono::DateTime<chrono::Utc>>,
context: &C,
- ) -> Box<dyn Future<Item = GetEditorAnnotationsResponse, Error = ApiError> + Send> {
+ ) -> Result<GetEditorAnnotationsResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editor/{editor_id}/annotations",
self.base_path,
@@ -11920,49 +9540,40 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_limit) = param_limit {
- query_string.append_pair("limit", &param_limit.to_string());
- }
- if let Some(param_before) = param_before {
- query_string.append_pair("before", &param_before.to_string());
- }
- if let Some(param_since) = param_since {
- query_string.append_pair("since", &param_since.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_limit.to_string());
+ }
+ if let Some(param_before) = param_before {
+ query_string.append_pair("before", &param_before.to_string());
+ }
+ if let Some(param_since) = param_since {
+ query_string.append_pair("since", &param_since.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -11973,184 +9584,139 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<Vec<models::EditgroupAnnotation>>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditorAnnotationsResponse::Success
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditorAnnotationsResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditorAnnotationsResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<Vec<models::EditgroupAnnotation>>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditorAnnotationsResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditorAnnotationsResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- GetEditorAnnotationsResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn get_editor_editgroups(
+ async fn get_editor_editgroups(
&self,
param_editor_id: String,
param_limit: Option<i64>,
param_before: Option<chrono::DateTime<chrono::Utc>>,
param_since: Option<chrono::DateTime<chrono::Utc>>,
context: &C,
- ) -> Box<dyn Future<Item = GetEditorEditgroupsResponse, Error = ApiError> + Send> {
+ ) -> Result<GetEditorEditgroupsResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editor/{editor_id}/editgroups",
self.base_path,
@@ -12158,49 +9724,40 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_limit) = param_limit {
- query_string.append_pair("limit", &param_limit.to_string());
- }
- if let Some(param_before) = param_before {
- query_string.append_pair("before", &param_before.to_string());
- }
- if let Some(param_since) = param_since {
- query_string.append_pair("since", &param_since.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_limit.to_string());
+ }
+ if let Some(param_before) = param_before {
+ query_string.append_pair("before", &param_before.to_string());
+ }
+ if let Some(param_since) = param_since {
+ query_string.append_pair("since", &param_since.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -12211,120 +9768,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::Editgroup>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditorEditgroupsResponse::Found(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditorEditgroupsResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditorEditgroupsResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetEditorEditgroupsResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::Editgroup>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_file(
+ async fn get_file(
&self,
param_ident: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetFileResponse, Error = ApiError> + Send> {
+ ) -> Result<GetFileResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/file/{ident}",
self.base_path,
@@ -12332,46 +9860,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -12382,118 +9901,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::FileEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileResponse::FoundEntity(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::FileEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_file_edit(
+ async fn get_file_edit(
&self,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = GetFileEditResponse, Error = ApiError> + Send> {
+ ) -> Result<GetFileEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/file/edit/{edit_id}",
self.base_path,
@@ -12501,40 +9991,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -12545,119 +10026,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileEditResponse::FoundEdit(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileEditResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileEditResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileEditResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_file_history(
+ async fn get_file_history(
&self,
param_ident: String,
param_limit: Option<i64>,
context: &C,
- ) -> Box<dyn Future<Item = GetFileHistoryResponse, Error = ApiError> + Send> {
+ ) -> Result<GetFileHistoryResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/file/{ident}/history",
self.base_path,
@@ -12665,43 +10117,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_limit) = param_limit {
- query_string.append_pair("limit", &param_limit.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_limit.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -12712,120 +10155,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::EntityHistoryEntry>>(
- body,
- )
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileHistoryResponse::FoundEntityHistory(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileHistoryResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileHistoryResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileHistoryResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::EntityHistoryEntry>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_file_redirects(
+ async fn get_file_redirects(
&self,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = GetFileRedirectsResponse, Error = ApiError> + Send> {
+ ) -> Result<GetFileRedirectsResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/file/{ident}/redirects",
self.base_path,
@@ -12833,40 +10245,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -12877,122 +10280,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<String>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetFileRedirectsResponse::FoundEntityRedirects(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileRedirectsResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileRedirectsResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileRedirectsResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<String>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_file_revision(
+ async fn get_file_revision(
&self,
param_rev_id: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetFileRevisionResponse, Error = ApiError> + Send> {
+ ) -> Result<GetFileRevisionResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/file/rev/{rev_id}",
self.base_path,
@@ -13000,46 +10372,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -13050,122 +10413,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::FileEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetFileRevisionResponse::FoundEntityRevision(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileRevisionResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileRevisionResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFileRevisionResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::FileEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_fileset(
+ async fn get_fileset(
&self,
param_ident: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetFilesetResponse, Error = ApiError> + Send> {
+ ) -> Result<GetFilesetResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/fileset/{ident}",
self.base_path,
@@ -13173,46 +10505,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -13223,118 +10546,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::FilesetEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetResponse::FoundEntity(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::FilesetEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_fileset_edit(
+ async fn get_fileset_edit(
&self,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = GetFilesetEditResponse, Error = ApiError> + Send> {
+ ) -> Result<GetFilesetEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/fileset/edit/{edit_id}",
self.base_path,
@@ -13342,40 +10636,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -13386,119 +10671,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetEditResponse::FoundEdit(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetEditResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetEditResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetEditResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_fileset_history(
+ async fn get_fileset_history(
&self,
param_ident: String,
param_limit: Option<i64>,
context: &C,
- ) -> Box<dyn Future<Item = GetFilesetHistoryResponse, Error = ApiError> + Send> {
+ ) -> Result<GetFilesetHistoryResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/fileset/{ident}/history",
self.base_path,
@@ -13506,43 +10762,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_limit) = param_limit {
- query_string.append_pair("limit", &param_limit.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_limit.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -13553,122 +10800,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::EntityHistoryEntry>>(
- body,
- )
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetFilesetHistoryResponse::FoundEntityHistory(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetHistoryResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetHistoryResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetHistoryResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::EntityHistoryEntry>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_fileset_redirects(
+ async fn get_fileset_redirects(
&self,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = GetFilesetRedirectsResponse, Error = ApiError> + Send> {
+ ) -> Result<GetFilesetRedirectsResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/fileset/{ident}/redirects",
self.base_path,
@@ -13676,40 +10890,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -13720,122 +10925,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<String>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetFilesetRedirectsResponse::FoundEntityRedirects(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetRedirectsResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetRedirectsResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetRedirectsResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<String>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_fileset_revision(
+ async fn get_fileset_revision(
&self,
param_rev_id: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetFilesetRevisionResponse, Error = ApiError> + Send> {
+ ) -> Result<GetFilesetRevisionResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/fileset/rev/{rev_id}",
self.base_path,
@@ -13843,46 +11017,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -13893,122 +11058,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::FilesetEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetFilesetRevisionResponse::FoundEntityRevision(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetRevisionResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetRevisionResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetFilesetRevisionResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::FilesetEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_release(
+ async fn get_release(
&self,
param_ident: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetReleaseResponse, Error = ApiError> + Send> {
+ ) -> Result<GetReleaseResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/release/{ident}",
self.base_path,
@@ -14016,46 +11150,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -14066,118 +11191,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ReleaseEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseResponse::FoundEntity(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::ReleaseEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_release_edit(
+ async fn get_release_edit(
&self,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = GetReleaseEditResponse, Error = ApiError> + Send> {
+ ) -> Result<GetReleaseEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/release/edit/{edit_id}",
self.base_path,
@@ -14185,40 +11281,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -14229,119 +11316,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseEditResponse::FoundEdit(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseEditResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseEditResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseEditResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_release_files(
+ async fn get_release_files(
&self,
param_ident: String,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetReleaseFilesResponse, Error = ApiError> + Send> {
+ ) -> Result<GetReleaseFilesResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/release/{ident}/files",
self.base_path,
@@ -14349,43 +11407,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -14396,119 +11445,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::FileEntity>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseFilesResponse::Found(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseFilesResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseFilesResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseFilesResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::FileEntity>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_release_filesets(
+ async fn get_release_filesets(
&self,
param_ident: String,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetReleaseFilesetsResponse, Error = ApiError> + Send> {
+ ) -> Result<GetReleaseFilesetsResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/release/{ident}/filesets",
self.base_path,
@@ -14516,43 +11536,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -14563,119 +11574,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::FilesetEntity>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseFilesetsResponse::Found(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseFilesetsResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseFilesetsResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseFilesetsResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::FilesetEntity>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_release_history(
+ async fn get_release_history(
&self,
param_ident: String,
param_limit: Option<i64>,
context: &C,
- ) -> Box<dyn Future<Item = GetReleaseHistoryResponse, Error = ApiError> + Send> {
+ ) -> Result<GetReleaseHistoryResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/release/{ident}/history",
self.base_path,
@@ -14683,43 +11665,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_limit) = param_limit {
- query_string.append_pair("limit", &param_limit.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_limit.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -14730,122 +11703,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::EntityHistoryEntry>>(
- body,
- )
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetReleaseHistoryResponse::FoundEntityHistory(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseHistoryResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseHistoryResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseHistoryResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::EntityHistoryEntry>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_release_redirects(
+ async fn get_release_redirects(
&self,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = GetReleaseRedirectsResponse, Error = ApiError> + Send> {
+ ) -> Result<GetReleaseRedirectsResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/release/{ident}/redirects",
self.base_path,
@@ -14853,40 +11793,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -14897,122 +11828,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<String>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetReleaseRedirectsResponse::FoundEntityRedirects(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseRedirectsResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseRedirectsResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseRedirectsResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<String>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_release_revision(
+ async fn get_release_revision(
&self,
param_rev_id: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetReleaseRevisionResponse, Error = ApiError> + Send> {
+ ) -> Result<GetReleaseRevisionResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/release/rev/{rev_id}",
self.base_path,
@@ -15020,46 +11920,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -15070,121 +11961,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ReleaseEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetReleaseRevisionResponse::FoundEntityRevision(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseRevisionResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseRevisionResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseRevisionResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::ReleaseEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_release_webcaptures(
+ async fn get_release_webcaptures(
&self,
param_ident: String,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetReleaseWebcapturesResponse, Error = ApiError> + Send> {
+ ) -> Result<GetReleaseWebcapturesResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/release/{ident}/webcaptures",
self.base_path,
@@ -15192,43 +12052,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -15239,122 +12090,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::WebcaptureEntity>>(
- body,
- )
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseWebcapturesResponse::Found(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseWebcapturesResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseWebcapturesResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetReleaseWebcapturesResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::WebcaptureEntity>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_webcapture(
+ async fn get_webcapture(
&self,
param_ident: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetWebcaptureResponse, Error = ApiError> + Send> {
+ ) -> Result<GetWebcaptureResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/webcapture/{ident}",
self.base_path,
@@ -15362,46 +12182,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -15412,118 +12223,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::WebcaptureEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureResponse::FoundEntity(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::WebcaptureEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_webcapture_edit(
+ async fn get_webcapture_edit(
&self,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = GetWebcaptureEditResponse, Error = ApiError> + Send> {
+ ) -> Result<GetWebcaptureEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/webcapture/edit/{edit_id}",
self.base_path,
@@ -15531,40 +12313,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -15575,119 +12348,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureEditResponse::FoundEdit(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureEditResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureEditResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureEditResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_webcapture_history(
+ async fn get_webcapture_history(
&self,
param_ident: String,
param_limit: Option<i64>,
context: &C,
- ) -> Box<dyn Future<Item = GetWebcaptureHistoryResponse, Error = ApiError> + Send> {
+ ) -> Result<GetWebcaptureHistoryResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/webcapture/{ident}/history",
self.base_path,
@@ -15695,43 +12439,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_limit) = param_limit {
- query_string.append_pair("limit", &param_limit.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_limit.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -15742,122 +12477,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::EntityHistoryEntry>>(
- body,
- )
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetWebcaptureHistoryResponse::FoundEntityHistory(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureHistoryResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureHistoryResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureHistoryResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::EntityHistoryEntry>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_webcapture_redirects(
+ async fn get_webcapture_redirects(
&self,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = GetWebcaptureRedirectsResponse, Error = ApiError> + Send> {
+ ) -> Result<GetWebcaptureRedirectsResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/webcapture/{ident}/redirects",
self.base_path,
@@ -15865,40 +12567,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -15909,124 +12602,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<String>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetWebcaptureRedirectsResponse::FoundEntityRedirects(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureRedirectsResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureRedirectsResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetWebcaptureRedirectsResponse::GenericError(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<String>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_webcapture_revision(
+ async fn get_webcapture_revision(
&self,
param_rev_id: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetWebcaptureRevisionResponse, Error = ApiError> + Send> {
+ ) -> Result<GetWebcaptureRevisionResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/webcapture/rev/{rev_id}",
self.base_path,
@@ -16034,46 +12694,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -16084,122 +12735,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::WebcaptureEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetWebcaptureRevisionResponse::FoundEntityRevision(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureRevisionResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureRevisionResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWebcaptureRevisionResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::WebcaptureEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_work(
+ async fn get_work(
&self,
param_ident: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetWorkResponse, Error = ApiError> + Send> {
+ ) -> Result<GetWorkResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/work/{ident}",
self.base_path,
@@ -16207,46 +12827,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -16257,118 +12868,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::WorkEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkResponse::FoundEntity(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::WorkEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_work_edit(
+ async fn get_work_edit(
&self,
param_edit_id: String,
context: &C,
- ) -> Box<dyn Future<Item = GetWorkEditResponse, Error = ApiError> + Send> {
+ ) -> Result<GetWorkEditResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/work/edit/{edit_id}",
self.base_path,
@@ -16376,40 +12958,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -16420,119 +12993,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkEditResponse::FoundEdit(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkEditResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkEditResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkEditResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_work_history(
+ async fn get_work_history(
&self,
param_ident: String,
param_limit: Option<i64>,
context: &C,
- ) -> Box<dyn Future<Item = GetWorkHistoryResponse, Error = ApiError> + Send> {
+ ) -> Result<GetWorkHistoryResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/work/{ident}/history",
self.base_path,
@@ -16540,43 +13084,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_limit) = param_limit {
- query_string.append_pair("limit", &param_limit.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_limit.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -16587,120 +13122,89 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::EntityHistoryEntry>>(
- body,
- )
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkHistoryResponse::FoundEntityHistory(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkHistoryResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkHistoryResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkHistoryResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::EntityHistoryEntry>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_work_redirects(
+ async fn get_work_redirects(
&self,
param_ident: String,
context: &C,
- ) -> Box<dyn Future<Item = GetWorkRedirectsResponse, Error = ApiError> + Send> {
+ ) -> Result<GetWorkRedirectsResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/work/{ident}/redirects",
self.base_path,
@@ -16708,40 +13212,31 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -16752,121 +13247,90 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<String>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetWorkRedirectsResponse::FoundEntityRedirects(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkRedirectsResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkRedirectsResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkRedirectsResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<String>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_work_releases(
+ async fn get_work_releases(
&self,
param_ident: String,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetWorkReleasesResponse, Error = ApiError> + Send> {
+ ) -> Result<GetWorkReleasesResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/work/{ident}/releases",
self.base_path,
@@ -16874,43 +13338,34 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -16921,120 +13376,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<Vec<models::ReleaseEntity>>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkReleasesResponse::Found(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkReleasesResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkReleasesResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkReleasesResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<Vec<models::ReleaseEntity>>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn get_work_revision(
+ async fn get_work_revision(
&self,
param_rev_id: String,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = GetWorkRevisionResponse, Error = ApiError> + Send> {
+ ) -> Result<GetWorkRevisionResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/work/rev/{rev_id}",
self.base_path,
@@ -17042,46 +13468,37 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -17092,172 +13509,132 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::WorkEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| {
- GetWorkRevisionResponse::FoundEntityRevision(body)
- }),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkRevisionResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkRevisionResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| GetWorkRevisionResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::WorkEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn lookup_container(
+ async fn lookup_container(
&self,
param_issnl: Option<String>,
param_wikidata_qid: Option<String>,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = LookupContainerResponse, Error = ApiError> + Send> {
+ ) -> Result<LookupContainerResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/container/lookup", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_issnl) = param_issnl {
- query_string.append_pair("issnl", &param_issnl.to_string());
- }
- if let Some(param_wikidata_qid) = param_wikidata_qid {
- query_string.append_pair("wikidata_qid", &param_wikidata_qid.to_string());
- }
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_issnl.to_string());
+ }
+ if let Some(param_wikidata_qid) = param_wikidata_qid {
+ query_string.append_pair("wikidata_qid", &param_wikidata_qid.to_string());
+ }
+ if let Some(param_expand) = param_expand {
+ query_string.append_pair("expand", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -17268,170 +13645,132 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ContainerEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupContainerResponse::FoundEntity(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupContainerResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupContainerResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupContainerResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::ContainerEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn lookup_creator(
+ async fn lookup_creator(
&self,
param_orcid: Option<String>,
param_wikidata_qid: Option<String>,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = LookupCreatorResponse, Error = ApiError> + Send> {
+ ) -> Result<LookupCreatorResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/creator/lookup", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_orcid) = param_orcid {
- query_string.append_pair("orcid", &param_orcid.to_string());
- }
- if let Some(param_wikidata_qid) = param_wikidata_qid {
- query_string.append_pair("wikidata_qid", &param_wikidata_qid.to_string());
- }
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_orcid.to_string());
+ }
+ if let Some(param_wikidata_qid) = param_wikidata_qid {
+ query_string.append_pair("wikidata_qid", &param_wikidata_qid.to_string());
+ }
+ if let Some(param_expand) = param_expand {
+ query_string.append_pair("expand", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -17442,114 +13781,84 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::CreatorEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupCreatorResponse::FoundEntity(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupCreatorResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupCreatorResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupCreatorResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::CreatorEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn lookup_file(
+ async fn lookup_file(
&self,
param_md5: Option<String>,
param_sha1: Option<String>,
@@ -17557,59 +13866,51 @@ where
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = LookupFileResponse, Error = ApiError> + Send> {
+ ) -> Result<LookupFileResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/file/lookup", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_md5) = param_md5 {
- query_string.append_pair("md5", &param_md5.to_string());
- }
- if let Some(param_sha1) = param_sha1 {
- query_string.append_pair("sha1", &param_sha1.to_string());
- }
- if let Some(param_sha256) = param_sha256 {
- query_string.append_pair("sha256", &param_sha256.to_string());
- }
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_md5.to_string());
+ }
+ if let Some(param_sha1) = param_sha1 {
+ query_string.append_pair("sha1", &param_sha1.to_string());
+ }
+ if let Some(param_sha256) = param_sha256 {
+ query_string.append_pair("sha256", &param_sha256.to_string());
+ }
+ if let Some(param_expand) = param_expand {
+ query_string.append_pair("expand", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -17620,114 +13921,84 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::FileEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupFileResponse::FoundEntity(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupFileResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupFileResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupFileResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::FileEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn lookup_release(
+ async fn lookup_release(
&self,
param_doi: Option<String>,
param_wikidata_qid: Option<String>,
@@ -17739,83 +14010,87 @@ where
param_jstor: Option<String>,
param_ark: Option<String>,
param_mag: Option<String>,
+ param_doaj: Option<String>,
+ param_dblp: Option<String>,
+ param_oai: Option<String>,
param_expand: Option<String>,
param_hide: Option<String>,
context: &C,
- ) -> Box<dyn Future<Item = LookupReleaseResponse, Error = ApiError> + Send> {
+ ) -> Result<LookupReleaseResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!("{}/v0/release/lookup", self.base_path);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_doi) = param_doi {
- query_string.append_pair("doi", &param_doi.to_string());
- }
- if let Some(param_wikidata_qid) = param_wikidata_qid {
- query_string.append_pair("wikidata_qid", &param_wikidata_qid.to_string());
- }
- if let Some(param_isbn13) = param_isbn13 {
- query_string.append_pair("isbn13", &param_isbn13.to_string());
- }
- if let Some(param_pmid) = param_pmid {
- query_string.append_pair("pmid", &param_pmid.to_string());
- }
- if let Some(param_pmcid) = param_pmcid {
- query_string.append_pair("pmcid", &param_pmcid.to_string());
- }
- if let Some(param_core) = param_core {
- query_string.append_pair("core", &param_core.to_string());
- }
- if let Some(param_arxiv) = param_arxiv {
- query_string.append_pair("arxiv", &param_arxiv.to_string());
- }
- if let Some(param_jstor) = param_jstor {
- query_string.append_pair("jstor", &param_jstor.to_string());
- }
- if let Some(param_ark) = param_ark {
- query_string.append_pair("ark", &param_ark.to_string());
- }
- if let Some(param_mag) = param_mag {
- query_string.append_pair("mag", &param_mag.to_string());
- }
- if let Some(param_expand) = param_expand {
- query_string.append_pair("expand", &param_expand.to_string());
- }
- if let Some(param_hide) = param_hide {
- query_string.append_pair("hide", &param_hide.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_doi.to_string());
+ }
+ if let Some(param_wikidata_qid) = param_wikidata_qid {
+ query_string.append_pair("wikidata_qid", &param_wikidata_qid.to_string());
+ }
+ if let Some(param_isbn13) = param_isbn13 {
+ query_string.append_pair("isbn13", &param_isbn13.to_string());
+ }
+ if let Some(param_pmid) = param_pmid {
+ query_string.append_pair("pmid", &param_pmid.to_string());
+ }
+ if let Some(param_pmcid) = param_pmcid {
+ query_string.append_pair("pmcid", &param_pmcid.to_string());
+ }
+ if let Some(param_core) = param_core {
+ query_string.append_pair("core", &param_core.to_string());
+ }
+ if let Some(param_arxiv) = param_arxiv {
+ query_string.append_pair("arxiv", &param_arxiv.to_string());
+ }
+ if let Some(param_jstor) = param_jstor {
+ query_string.append_pair("jstor", &param_jstor.to_string());
+ }
+ if let Some(param_ark) = param_ark {
+ query_string.append_pair("ark", &param_ark.to_string());
+ }
+ if let Some(param_mag) = param_mag {
+ query_string.append_pair("mag", &param_mag.to_string());
+ }
+ if let Some(param_doaj) = param_doaj {
+ query_string.append_pair("doaj", &param_doaj.to_string());
+ }
+ if let Some(param_dblp) = param_dblp {
+ query_string.append_pair("dblp", &param_dblp.to_string());
+ }
+ if let Some(param_oai) = param_oai {
+ query_string.append_pair("oai", &param_oai.to_string());
+ }
+ if let Some(param_expand) = param_expand {
+ query_string.append_pair("expand", &param_expand.to_string());
+ }
+ if let Some(param_hide) = param_hide {
+ query_string.append_pair("hide", &param_hide.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("GET")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -17826,120 +14101,91 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- Box::new(
- self.client_service
- .request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ReleaseEntity>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupReleaseResponse::FoundEntity(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 400 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupReleaseResponse::BadRequest(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 404 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupReleaseResponse::NotFound(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- 500 => {
- let body = response.into_body();
- Box::new(
- body.concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body| {
- str::from_utf8(&body)
- .map_err(|e| {
- ApiError(format!("Response was not valid UTF8: {}", e))
- })
- .and_then(|body| {
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- })
- })
- .map(move |body| LookupReleaseResponse::GenericError(body)),
- ) as Box<dyn Future<Item = _, Error = _> + Send>
- }
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body().take(100).concat2().then(move |body| {
- future::err(ApiError(format!(
- "Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) =>
- Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- }
- )))
- })) as Box<dyn Future<Item = _, Error = _> + Send>
+ 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::<models::ReleaseEntity>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
}
- }),
- )
+ )))
+ }
+ }
}
- fn update_container(
+ async fn update_container(
&self,
param_editgroup_id: String,
param_ident: String,
param_container_entity: models::ContainerEntity,
context: &C,
- ) -> Box<dyn Future<Item = UpdateContainerResponse, Error = ApiError> + Send> {
+ ) -> Result<UpdateContainerResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/container/{ident}",
self.base_path,
@@ -17948,35 +14194,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("PUT")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body = serde_json::to_string(&param_container_entity)
@@ -17989,16 +14227,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -18009,15 +14246,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -18025,10 +14262,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -18039,175 +14276,130 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateContainerResponse::UpdatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateContainerResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateContainerResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateContainerResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateContainerResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateContainerResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn update_creator(
+ async fn update_creator(
&self,
param_editgroup_id: String,
param_ident: String,
param_creator_entity: models::CreatorEntity,
context: &C,
- ) -> Box<dyn Future<Item = UpdateCreatorResponse, Error = ApiError> + Send> {
+ ) -> Result<UpdateCreatorResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/creator/{ident}",
self.base_path,
@@ -18216,35 +14408,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("PUT")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -18257,16 +14441,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -18277,15 +14460,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -18293,10 +14476,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -18307,175 +14490,130 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateCreatorResponse::UpdatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateCreatorResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateCreatorResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateCreatorResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateCreatorResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateCreatorResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn update_editgroup(
+ async fn update_editgroup(
&self,
param_editgroup_id: String,
param_editgroup: models::Editgroup,
param_submit: Option<bool>,
context: &C,
- ) -> Box<dyn Future<Item = UpdateEditgroupResponse, Error = ApiError> + Send> {
+ ) -> Result<UpdateEditgroupResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}",
self.base_path,
@@ -18483,38 +14621,30 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- if let Some(param_submit) = param_submit {
- query_string.append_pair("submit", &param_submit.to_string());
- }
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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", &param_submit.to_string());
+ }
+ query_string.finish()
+ };
+ if !query_string.is_empty() {
uri += "?";
- uri += &query_string_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("PUT")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -18527,16 +14657,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -18547,15 +14676,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -18563,10 +14692,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -18577,174 +14706,129 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Editgroup>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditgroupResponse::UpdatedEditgroup
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditgroupResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditgroupResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Editgroup>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditgroupResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditgroupResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditgroupResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn update_editor(
+ async fn update_editor(
&self,
param_editor_id: String,
param_editor: models::Editor,
context: &C,
- ) -> Box<dyn Future<Item = UpdateEditorResponse, Error = ApiError> + Send> {
+ ) -> Result<UpdateEditorResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editor/{editor_id}",
self.base_path,
@@ -18752,35 +14836,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("PUT")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body = serde_json::to_string(&param_editor).expect("impossible to fail to serialize");
@@ -18792,16 +14868,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -18812,15 +14887,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -18828,10 +14903,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -18842,175 +14917,130 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::Editor>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditorResponse::UpdatedEditor
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditorResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditorResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::Editor>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditorResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditorResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateEditorResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn update_file(
+ async fn update_file(
&self,
param_editgroup_id: String,
param_ident: String,
param_file_entity: models::FileEntity,
context: &C,
- ) -> Box<dyn Future<Item = UpdateFileResponse, Error = ApiError> + Send> {
+ ) -> Result<UpdateFileResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/file/{ident}",
self.base_path,
@@ -19019,35 +15049,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("PUT")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -19060,16 +15082,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -19080,15 +15101,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -19096,10 +15117,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -19110,175 +15131,130 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFileResponse::UpdatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFileResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFileResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFileResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFileResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFileResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn update_fileset(
+ async fn update_fileset(
&self,
param_editgroup_id: String,
param_ident: String,
param_fileset_entity: models::FilesetEntity,
context: &C,
- ) -> Box<dyn Future<Item = UpdateFilesetResponse, Error = ApiError> + Send> {
+ ) -> Result<UpdateFilesetResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/fileset/{ident}",
self.base_path,
@@ -19287,35 +15263,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("PUT")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -19328,16 +15296,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -19348,15 +15315,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -19364,10 +15331,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -19378,175 +15345,130 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFilesetResponse::UpdatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFilesetResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFilesetResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFilesetResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFilesetResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateFilesetResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn update_release(
+ async fn update_release(
&self,
param_editgroup_id: String,
param_ident: String,
param_release_entity: models::ReleaseEntity,
context: &C,
- ) -> Box<dyn Future<Item = UpdateReleaseResponse, Error = ApiError> + Send> {
+ ) -> Result<UpdateReleaseResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/release/{ident}",
self.base_path,
@@ -19555,35 +15477,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("PUT")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -19596,16 +15510,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -19616,15 +15529,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -19632,10 +15545,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -19646,175 +15559,130 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateReleaseResponse::UpdatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateReleaseResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateReleaseResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateReleaseResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateReleaseResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateReleaseResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn update_webcapture(
+ async fn update_webcapture(
&self,
param_editgroup_id: String,
param_ident: String,
param_webcapture_entity: models::WebcaptureEntity,
context: &C,
- ) -> Box<dyn Future<Item = UpdateWebcaptureResponse, Error = ApiError> + Send> {
+ ) -> Result<UpdateWebcaptureResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/webcapture/{ident}",
self.base_path,
@@ -19823,35 +15691,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("PUT")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body = serde_json::to_string(&param_webcapture_entity)
@@ -19864,16 +15724,15 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -19884,15 +15743,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -19900,10 +15759,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -19914,175 +15773,130 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWebcaptureResponse::UpdatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWebcaptureResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWebcaptureResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWebcaptureResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWebcaptureResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWebcaptureResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
- fn update_work(
+ async fn update_work(
&self,
param_editgroup_id: String,
param_ident: String,
param_work_entity: models::WorkEntity,
context: &C,
- ) -> Box<dyn Future<Item = UpdateWorkResponse, Error = ApiError> + Send> {
+ ) -> Result<UpdateWorkResponse, ApiError> {
+ let mut client_service = self.client_service.clone();
let mut uri = format!(
"{}/v0/editgroup/{editgroup_id}/work/{ident}",
self.base_path,
@@ -20091,35 +15905,27 @@ where
);
// Query parameters
- let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
- let query_string_str = query_string.finish();
- if !query_string_str.is_empty() {
+ 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_str;
+ uri += &query_string;
}
let uri = match Uri::from_str(&uri) {
Ok(uri) => uri,
- Err(err) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to build URI: {}",
- err
- ))))
- }
+ Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
};
- let mut request = match hyper::Request::builder()
+ let mut request = match Request::builder()
.method("PUT")
.uri(uri)
.body(Body::empty())
{
Ok(req) => req,
- Err(e) => {
- return Box::new(future::err(ApiError(format!(
- "Unable to create request: {}",
- e
- ))))
- }
+ Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
};
let body =
@@ -20133,17 +15939,16 @@ where
match HeaderValue::from_str(header) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create header: {} - {}",
header, e
- ))))
+ )))
}
},
);
let header = HeaderValue::from_str(
- (context as &dyn Has<XSpanIdString>)
- .get()
+ Has::<XSpanIdString>::get(context)
.0
.clone()
.to_string()
@@ -20154,15 +15959,15 @@ where
match header {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create X-Span ID header value: {}",
e
- ))))
+ )))
}
},
);
- if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() {
+ if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() {
// Currently only authentication with Basic and Bearer are supported
match auth_data {
&AuthData::Bearer(ref bearer_header) => {
@@ -20170,10 +15975,10 @@ where
let header = match HeaderValue::from_str(&format!("{}", auth)) {
Ok(h) => h,
Err(e) => {
- return Box::new(future::err(ApiError(format!(
+ return Err(ApiError(format!(
"Unable to create Authorization header: {}",
e
- ))))
+ )))
}
};
request
@@ -20184,165 +15989,119 @@ where
}
}
- Box::new(self.client_service.request(request)
- .map_err(|e| ApiError(format!("No response received: {}", e)))
- .and_then(|mut response| {
- match response.status().as_u16() {
- 200 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::EntityEdit>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWorkResponse::UpdatedEntity
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 400 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWorkResponse::BadRequest
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 401 => {
- let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) {
- Some(response_www_authenticate) => response_www_authenticate.clone(),
- None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>,
- };
- let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) {
- Ok(value) => value,
- Err(e) => {
- return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>;
- },
- };
- let response_www_authenticate = response_www_authenticate.0;
-
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWorkResponse::NotAuthorized
- {
- body: body,
- www_authenticate: response_www_authenticate,
+ 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::<models::EntityEdit>(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::<models::ErrorResponse>(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<String>,
+ >::try_into(
+ response_www_authenticate
+ ) {
+ Ok(value) => value,
+ Err(e) => {
+ return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)));
}
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 403 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWorkResponse::Forbidden
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 404 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWorkResponse::NotFound
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- 500 => {
- let body = response.into_body();
- Box::new(
- body
- .concat2()
- .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
- .and_then(|body|
- str::from_utf8(&body)
- .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
- .and_then(|body|
- serde_json::from_str::<models::ErrorResponse>(body)
- .map_err(|e| e.into())
- )
- )
- .map(move |body| {
- UpdateWorkResponse::GenericError
- (body)
- })
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- },
- code => {
- let headers = response.headers().clone();
- Box::new(response.into_body()
- .take(100)
- .concat2()
- .then(move |body|
- future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
- code,
- headers,
- match body {
- Ok(ref body) => match str::from_utf8(body) {
- Ok(body) => Cow::from(body),
- Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
- },
- Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
- })))
- )
- ) as Box<dyn Future<Item=_, Error=_> + Send>
- }
+ };
+ 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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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::<models::ErrorResponse>(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!("<Body was not UTF8: {:?}>", e),
+ },
+ Err(e) => format!("<Failed to read body: {}>", e),
+ }
+ )))
}
- }))
+ }
}
}