#![allow(unused_extern_crates)] extern crate chrono; extern crate hyper_openssl; extern crate url; use self::hyper_openssl::openssl; use self::url::percent_encoding::{utf8_percent_encode, PATH_SEGMENT_ENCODE_SET, QUERY_ENCODE_SET}; use futures; use futures::{Future, Stream}; use futures::{future, stream}; use hyper; use hyper::Url; use hyper::client::IntoUrl; use hyper::header::{ContentType, Headers}; use hyper::mime; use hyper::mime::{Attr, Mime, SubLevel, TopLevel, Value}; use std::borrow::Cow; use std::error; use std::fmt; use std::io::{Error, Read}; use std::path::Path; use std::str; use std::sync::Arc; use mimetypes; use serde_json; #[allow(unused_imports)] use std::collections::{BTreeMap, HashMap}; #[allow(unused_imports)] use swagger; use swagger::{ApiError, Context, XSpanId}; use models; use {AcceptEditgroupResponse, Api, CreateContainerBatchResponse, CreateContainerResponse, CreateCreatorBatchResponse, CreateCreatorResponse, CreateEditgroupResponse, CreateFileBatchResponse, CreateFileResponse, CreateReleaseBatchResponse, CreateReleaseResponse, CreateWorkBatchResponse, CreateWorkResponse, GetContainerResponse, GetCreatorReleasesResponse, GetCreatorResponse, GetEditgroupResponse, GetEditorChangelogResponse, GetEditorResponse, GetFileResponse, GetReleaseFilesResponse, GetReleaseResponse, GetStatsResponse, GetWorkReleasesResponse, GetWorkResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, LookupReleaseResponse}; /// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes. fn into_base_path<T: IntoUrl>(input: T, correct_scheme: Option<&'static str>) -> Result<String, ClientInitError> { // First convert to Url, since a base path is a subset of Url. let url = input.into_url()?; let scheme = url.scheme(); // Check the scheme if necessary if let Some(correct_scheme) = correct_scheme { if scheme != correct_scheme { return Err(ClientInitError::InvalidScheme); } } let host = url.host().ok_or_else(|| ClientInitError::MissingHost)?; let port = url.port().map(|x| format!(":{}", x)).unwrap_or_default(); Ok(format!("{}://{}{}", scheme, host, port)) } /// A client that implements the API by making HTTP calls out to a server. #[derive(Clone)] pub struct Client { base_path: String, hyper_client: Arc<Fn() -> hyper::client::Client + Sync + Send>, } impl fmt::Debug for Client { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Client {{ base_path: {} }}", self.base_path) } } impl Client { pub fn try_new_http<T>(base_path: T) -> Result<Client, ClientInitError> where T: IntoUrl, { Ok(Client { base_path: into_base_path(base_path, Some("http"))?, hyper_client: Arc::new(hyper::client::Client::new), }) } pub fn try_new_https<T, CA>(base_path: T, ca_certificate: CA) -> Result<Client, ClientInitError> where T: IntoUrl, CA: AsRef<Path>, { let ca_certificate = ca_certificate.as_ref().to_owned(); let https_hyper_client = move || { // SSL implementation let mut ssl = openssl::ssl::SslConnectorBuilder::new(openssl::ssl::SslMethod::tls()).unwrap(); // Server authentication ssl.set_ca_file(ca_certificate.clone()).unwrap(); let ssl = hyper_openssl::OpensslClient::from(ssl.build()); let connector = hyper::net::HttpsConnector::new(ssl); hyper::client::Client::with_connector(connector) }; Ok(Client { base_path: into_base_path(base_path, Some("https"))?, hyper_client: Arc::new(https_hyper_client), }) } pub fn try_new_https_mutual<T, CA, K, C>(base_path: T, ca_certificate: CA, client_key: K, client_certificate: C) -> Result<Client, ClientInitError> where T: IntoUrl, CA: AsRef<Path>, K: AsRef<Path>, C: AsRef<Path>, { let ca_certificate = ca_certificate.as_ref().to_owned(); let client_key = client_key.as_ref().to_owned(); let client_certificate = client_certificate.as_ref().to_owned(); let https_mutual_hyper_client = move || { // SSL implementation let mut ssl = openssl::ssl::SslConnectorBuilder::new(openssl::ssl::SslMethod::tls()).unwrap(); // Server authentication ssl.set_ca_file(ca_certificate.clone()).unwrap(); // Client authentication ssl.set_private_key_file(client_key.clone(), openssl::x509::X509_FILETYPE_PEM).unwrap(); ssl.set_certificate_chain_file(client_certificate.clone()).unwrap(); ssl.check_private_key().unwrap(); let ssl = hyper_openssl::OpensslClient::from(ssl.build()); let connector = hyper::net::HttpsConnector::new(ssl); hyper::client::Client::with_connector(connector) }; Ok(Client { base_path: into_base_path(base_path, Some("https"))?, hyper_client: Arc::new(https_mutual_hyper_client), }) } /// Constructor for creating a `Client` by passing in a pre-made `hyper` client. /// /// One should avoid relying on this function if possible, since it adds a dependency on the underlying transport /// implementation, which it would be better to abstract away. Therefore, using this function may lead to a loss of /// code generality, which may make it harder to move the application to a serverless environment, for example. /// /// The reason for this function's existence is to support legacy test code, which did mocking at the hyper layer. /// This is not a recommended way to write new tests. If other reasons are found for using this function, they /// should be mentioned here. pub fn try_new_with_hyper_client<T>(base_path: T, hyper_client: Arc<Fn() -> hyper::client::Client + Sync + Send>) -> Result<Client, ClientInitError> where T: IntoUrl, { Ok(Client { base_path: into_base_path(base_path, None)?, hyper_client: hyper_client, }) } } impl Api for Client { fn accept_editgroup(&self, param_id: i64, context: &Context) -> Box<Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send> { let url = format!("{}/v0/editgroup/{id}/accept", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<AcceptEditgroupResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::Success>(&buf)?; Ok(AcceptEditgroupResponse::MergedSuccessfully(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(AcceptEditgroupResponse::Unmergable(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(AcceptEditgroupResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(AcceptEditgroupResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn create_container(&self, param_entity: models::ContainerEntity, context: &Context) -> Box<Future<Item = CreateContainerResponse, Error = ApiError> + Send> { let url = format!("{}/v0/container", self.base_path); let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); let request = request.body(&body); custom_headers.set(ContentType(mimetypes::requests::CREATE_CONTAINER.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<CreateContainerResponse, ApiError> { match response.status.to_u16() { 201 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::EntityEdit>(&buf)?; Ok(CreateContainerResponse::CreatedEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateContainerResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateContainerResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateContainerResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn create_container_batch(&self, param_entity_list: &Vec<models::ContainerEntity>, context: &Context) -> Box<Future<Item = CreateContainerBatchResponse, Error = ApiError> + Send> { let url = format!("{}/v0/container/batch", self.base_path); let body = serde_json::to_string(¶m_entity_list).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); let request = request.body(&body); custom_headers.set(ContentType(mimetypes::requests::CREATE_CONTAINER_BATCH.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<CreateContainerBatchResponse, ApiError> { match response.status.to_u16() { 201 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<Vec<models::EntityEdit>>(&buf)?; Ok(CreateContainerBatchResponse::CreatedEntities(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateContainerBatchResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateContainerBatchResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateContainerBatchResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn create_creator(&self, param_entity: models::CreatorEntity, context: &Context) -> Box<Future<Item = CreateCreatorResponse, Error = ApiError> + Send> { let url = format!("{}/v0/creator", self.base_path); let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); let request = request.body(&body); custom_headers.set(ContentType(mimetypes::requests::CREATE_CREATOR.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<CreateCreatorResponse, ApiError> { match response.status.to_u16() { 201 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::EntityEdit>(&buf)?; Ok(CreateCreatorResponse::CreatedEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateCreatorResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateCreatorResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateCreatorResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn create_creator_batch(&self, param_entity_list: &Vec<models::CreatorEntity>, context: &Context) -> Box<Future<Item = CreateCreatorBatchResponse, Error = ApiError> + Send> { let url = format!("{}/v0/creator/batch", self.base_path); let body = serde_json::to_string(¶m_entity_list).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); let request = request.body(&body); custom_headers.set(ContentType(mimetypes::requests::CREATE_CREATOR_BATCH.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<CreateCreatorBatchResponse, ApiError> { match response.status.to_u16() { 201 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<Vec<models::EntityEdit>>(&buf)?; Ok(CreateCreatorBatchResponse::CreatedEntities(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateCreatorBatchResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateCreatorBatchResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateCreatorBatchResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn create_editgroup(&self, param_entity: models::Editgroup, context: &Context) -> Box<Future<Item = CreateEditgroupResponse, Error = ApiError> + Send> { let url = format!("{}/v0/editgroup", self.base_path); let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); let request = request.body(&body); custom_headers.set(ContentType(mimetypes::requests::CREATE_EDITGROUP.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<CreateEditgroupResponse, ApiError> { match response.status.to_u16() { 201 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::Editgroup>(&buf)?; Ok(CreateEditgroupResponse::SuccessfullyCreated(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateEditgroupResponse::BadRequest(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateEditgroupResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn create_file(&self, param_entity: models::FileEntity, context: &Context) -> Box<Future<Item = CreateFileResponse, Error = ApiError> + Send> { let url = format!("{}/v0/file", self.base_path); let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); let request = request.body(&body); custom_headers.set(ContentType(mimetypes::requests::CREATE_FILE.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<CreateFileResponse, ApiError> { match response.status.to_u16() { 201 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::EntityEdit>(&buf)?; Ok(CreateFileResponse::CreatedEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateFileResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateFileResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateFileResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn create_file_batch(&self, param_entity_list: &Vec<models::FileEntity>, context: &Context) -> Box<Future<Item = CreateFileBatchResponse, Error = ApiError> + Send> { let url = format!("{}/v0/file/batch", self.base_path); let body = serde_json::to_string(¶m_entity_list).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); let request = request.body(&body); custom_headers.set(ContentType(mimetypes::requests::CREATE_FILE_BATCH.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<CreateFileBatchResponse, ApiError> { match response.status.to_u16() { 201 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<Vec<models::EntityEdit>>(&buf)?; Ok(CreateFileBatchResponse::CreatedEntities(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateFileBatchResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateFileBatchResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateFileBatchResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn create_release(&self, param_entity: models::ReleaseEntity, context: &Context) -> Box<Future<Item = CreateReleaseResponse, Error = ApiError> + Send> { let url = format!("{}/v0/release", self.base_path); let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); let request = request.body(&body); custom_headers.set(ContentType(mimetypes::requests::CREATE_RELEASE.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<CreateReleaseResponse, ApiError> { match response.status.to_u16() { 201 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::EntityEdit>(&buf)?; Ok(CreateReleaseResponse::CreatedEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateReleaseResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateReleaseResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateReleaseResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn create_release_batch(&self, param_entity_list: &Vec<models::ReleaseEntity>, context: &Context) -> Box<Future<Item = CreateReleaseBatchResponse, Error = ApiError> + Send> { let url = format!("{}/v0/release/batch", self.base_path); let body = serde_json::to_string(¶m_entity_list).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); let request = request.body(&body); custom_headers.set(ContentType(mimetypes::requests::CREATE_RELEASE_BATCH.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<CreateReleaseBatchResponse, ApiError> { match response.status.to_u16() { 201 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<Vec<models::EntityEdit>>(&buf)?; Ok(CreateReleaseBatchResponse::CreatedEntities(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateReleaseBatchResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateReleaseBatchResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateReleaseBatchResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn create_work(&self, param_entity: models::WorkEntity, context: &Context) -> Box<Future<Item = CreateWorkResponse, Error = ApiError> + Send> { let url = format!("{}/v0/work", self.base_path); let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); let request = request.body(&body); custom_headers.set(ContentType(mimetypes::requests::CREATE_WORK.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<CreateWorkResponse, ApiError> { match response.status.to_u16() { 201 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::EntityEdit>(&buf)?; Ok(CreateWorkResponse::CreatedEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateWorkResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateWorkResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateWorkResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn create_work_batch(&self, param_entity_list: &Vec<models::WorkEntity>, context: &Context) -> Box<Future<Item = CreateWorkBatchResponse, Error = ApiError> + Send> { let url = format!("{}/v0/work/batch", self.base_path); let body = serde_json::to_string(¶m_entity_list).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); let request = request.body(&body); custom_headers.set(ContentType(mimetypes::requests::CREATE_WORK_BATCH.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<CreateWorkBatchResponse, ApiError> { match response.status.to_u16() { 201 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<Vec<models::EntityEdit>>(&buf)?; Ok(CreateWorkBatchResponse::CreatedEntities(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateWorkBatchResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateWorkBatchResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(CreateWorkBatchResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_container(&self, param_id: String, context: &Context) -> Box<Future<Item = GetContainerResponse, Error = ApiError> + Send> { let url = format!("{}/v0/container/{id}", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetContainerResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ContainerEntity>(&buf)?; Ok(GetContainerResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetContainerResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetContainerResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetContainerResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_creator(&self, param_id: String, context: &Context) -> Box<Future<Item = GetCreatorResponse, Error = ApiError> + Send> { let url = format!("{}/v0/creator/{id}", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetCreatorResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::CreatorEntity>(&buf)?; Ok(GetCreatorResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetCreatorResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetCreatorResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetCreatorResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_creator_releases(&self, param_id: String, context: &Context) -> Box<Future<Item = GetCreatorReleasesResponse, Error = ApiError> + Send> { let url = format!("{}/v0/creator/{id}/releases", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetCreatorReleasesResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<Vec<models::ReleaseEntity>>(&buf)?; Ok(GetCreatorReleasesResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetCreatorReleasesResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetCreatorReleasesResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetCreatorReleasesResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_editgroup(&self, param_id: i64, context: &Context) -> Box<Future<Item = GetEditgroupResponse, Error = ApiError> + Send> { let url = format!("{}/v0/editgroup/{id}", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetEditgroupResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::Editgroup>(&buf)?; Ok(GetEditgroupResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetEditgroupResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetEditgroupResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetEditgroupResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_editor(&self, param_username: String, context: &Context) -> Box<Future<Item = GetEditorResponse, Error = ApiError> + Send> { let url = format!( "{}/v0/editor/{username}", self.base_path, username = utf8_percent_encode(¶m_username.to_string(), PATH_SEGMENT_ENCODE_SET) ); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetEditorResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::Editor>(&buf)?; Ok(GetEditorResponse::FoundEditor(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetEditorResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetEditorResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_editor_changelog(&self, param_username: String, context: &Context) -> Box<Future<Item = GetEditorChangelogResponse, Error = ApiError> + Send> { let url = format!( "{}/v0/editor/{username}/changelog", self.base_path, username = utf8_percent_encode(¶m_username.to_string(), PATH_SEGMENT_ENCODE_SET) ); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetEditorChangelogResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<Vec<models::ChangelogEntry>>(&buf)?; Ok(GetEditorChangelogResponse::FoundMergedChanges(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetEditorChangelogResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetEditorChangelogResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_file(&self, param_id: String, context: &Context) -> Box<Future<Item = GetFileResponse, Error = ApiError> + Send> { let url = format!("{}/v0/file/{id}", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetFileResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::FileEntity>(&buf)?; Ok(GetFileResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetFileResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetFileResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetFileResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_release(&self, param_id: String, context: &Context) -> Box<Future<Item = GetReleaseResponse, Error = ApiError> + Send> { let url = format!("{}/v0/release/{id}", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetReleaseResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ReleaseEntity>(&buf)?; Ok(GetReleaseResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetReleaseResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetReleaseResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetReleaseResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_release_files(&self, param_id: String, context: &Context) -> Box<Future<Item = GetReleaseFilesResponse, Error = ApiError> + Send> { let url = format!("{}/v0/release/{id}/files", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetReleaseFilesResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<Vec<models::FileEntity>>(&buf)?; Ok(GetReleaseFilesResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetReleaseFilesResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetReleaseFilesResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetReleaseFilesResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_stats(&self, param_more: Option<String>, context: &Context) -> Box<Future<Item = GetStatsResponse, Error = ApiError> + Send> { // Query parameters let query_more = param_more.map_or_else(String::new, |query| format!("more={more}&", more = query.to_string())); let url = format!("{}/v0/stats?{more}", self.base_path, more = utf8_percent_encode(&query_more, QUERY_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetStatsResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::StatsResponse>(&buf)?; Ok(GetStatsResponse::Success(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetStatsResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_work(&self, param_id: String, context: &Context) -> Box<Future<Item = GetWorkResponse, Error = ApiError> + Send> { let url = format!("{}/v0/work/{id}", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetWorkResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::WorkEntity>(&buf)?; Ok(GetWorkResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetWorkResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetWorkResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetWorkResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn get_work_releases(&self, param_id: String, context: &Context) -> Box<Future<Item = GetWorkReleasesResponse, Error = ApiError> + Send> { let url = format!("{}/v0/work/{id}/releases", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<GetWorkReleasesResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<Vec<models::ReleaseEntity>>(&buf)?; Ok(GetWorkReleasesResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetWorkReleasesResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetWorkReleasesResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(GetWorkReleasesResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn lookup_container(&self, param_issnl: String, context: &Context) -> Box<Future<Item = LookupContainerResponse, Error = ApiError> + Send> { // Query parameters let query_issnl = format!("issnl={issnl}&", issnl = param_issnl.to_string()); let url = format!("{}/v0/container/lookup?{issnl}", self.base_path, issnl = utf8_percent_encode(&query_issnl, QUERY_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<LookupContainerResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ContainerEntity>(&buf)?; Ok(LookupContainerResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupContainerResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupContainerResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupContainerResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn lookup_creator(&self, param_orcid: String, context: &Context) -> Box<Future<Item = LookupCreatorResponse, Error = ApiError> + Send> { // Query parameters let query_orcid = format!("orcid={orcid}&", orcid = param_orcid.to_string()); let url = format!("{}/v0/creator/lookup?{orcid}", self.base_path, orcid = utf8_percent_encode(&query_orcid, QUERY_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<LookupCreatorResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::CreatorEntity>(&buf)?; Ok(LookupCreatorResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupCreatorResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupCreatorResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupCreatorResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn lookup_file(&self, param_sha1: String, context: &Context) -> Box<Future<Item = LookupFileResponse, Error = ApiError> + Send> { // Query parameters let query_sha1 = format!("sha1={sha1}&", sha1 = param_sha1.to_string()); let url = format!("{}/v0/file/lookup?{sha1}", self.base_path, sha1 = utf8_percent_encode(&query_sha1, QUERY_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<LookupFileResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::FileEntity>(&buf)?; Ok(LookupFileResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupFileResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupFileResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupFileResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } fn lookup_release(&self, param_doi: String, context: &Context) -> Box<Future<Item = LookupReleaseResponse, Error = ApiError> + Send> { // Query parameters let query_doi = format!("doi={doi}&", doi = param_doi.to_string()); let url = format!("{}/v0/release/lookup?{doi}", self.base_path, doi = utf8_percent_encode(&query_doi, QUERY_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). fn parse_response(mut response: hyper::client::response::Response) -> Result<LookupReleaseResponse, ApiError> { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ReleaseEntity>(&buf)?; Ok(LookupReleaseResponse::FoundEntity(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupReleaseResponse::BadRequest(body)) } 404 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupReleaseResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::<models::ErrorResponse>(&buf)?; Ok(LookupReleaseResponse::GenericError(body)) } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), }; Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", code, response.headers, debug_body))) } } } let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); Box::new(futures::done(result)) } } #[derive(Debug)] pub enum ClientInitError { InvalidScheme, InvalidUrl(hyper::error::ParseError), MissingHost, SslError(openssl::error::ErrorStack), } impl From<hyper::error::ParseError> for ClientInitError { fn from(err: hyper::error::ParseError) -> ClientInitError { ClientInitError::InvalidUrl(err) } } impl From<openssl::error::ErrorStack> for ClientInitError { fn from(err: openssl::error::ErrorStack) -> ClientInitError { ClientInitError::SslError(err) } } impl fmt::Display for ClientInitError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (self as &fmt::Debug).fmt(f) } } impl error::Error for ClientInitError { fn description(&self) -> &str { "Failed to produce a hyper client." } }