Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
#![allow(unused_extern_crates)]
extern crate tokio_core;
extern crate native_tls;
extern crate hyper_tls;
extern crate openssl;
extern crate mime;
extern crate chrono;
extern crate url;
{{#apiHasFile}}extern crate multipart;{{/apiHasFile}}
{{#usesUrlEncodedForm}}extern crate serde_urlencoded;{{/usesUrlEncodedForm}}
{{#apiUsesUuid}}use uuid;{{/apiUsesUuid}}
{{#apiHasFile}}use self::multipart::client::lazy::Multipart;{{/apiHasFile}}
use hyper;
use hyper::header::{Headers, ContentType};
use hyper::Uri;
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 self::tokio_core::reactor::Handle;
use std::borrow::Cow;
use std::io::{Read, Error, ErrorKind};
use std::error;
use std::fmt;
use std::path::Path;
use std::sync::Arc;
use std::str;
use std::str::FromStr;
use mimetypes;
use serde_json;
{{#usesXml}}use serde_xml_rs;{{/usesXml}}
#[allow(unused_imports)]
use std::collections::{HashMap, BTreeMap};
#[allow(unused_imports)]
use swagger;
use swagger::{ApiError, XSpanId, XSpanIdString, Has, AuthData};
use {Api{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}},
{{operationId}}Response{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
};
use models;
/// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes.
fn into_base_path(input: &str, correct_scheme: Option<&'static str>) -> Result {
// First convert to Uri, since a base path is a subset of Uri.
let uri = Uri::from_str(input)?;
let scheme = uri.scheme().ok_or(ClientInitError::InvalidScheme)?;
// Check the scheme if necessary
if let Some(correct_scheme) = correct_scheme {
if scheme != correct_scheme {
return Err(ClientInitError::InvalidScheme);
}
}
let host = uri.host().ok_or_else(|| ClientInitError::MissingHost)?;
let port = uri.port().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 {
hyper_client: Arc, Response=hyper::Response, Error=hyper::Error, Future=hyper::client::FutureResponse>>>,
base_path: String,
}
impl fmt::Debug for Client {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Client {{ base_path: {} }}", self.base_path)
}
}
impl Client {
/// Create an HTTP client.
///
/// # Arguments
/// * `handle` - tokio reactor handle to use for execution
/// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
pub fn try_new_http(handle: Handle, base_path: &str) -> Result {
let http_connector = swagger::http_connector();
Self::try_new_with_connector::(
handle,
base_path,
Some("http"),
http_connector,
)
}
/// Create a client with a TLS connection to the server.
///
/// # Arguments
/// * `handle` - tokio reactor handle to use for execution
/// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
/// * `ca_certificate` - Path to CA certificate used to authenticate the server
pub fn try_new_https(
handle: Handle,
base_path: &str,
ca_certificate: CA,
) -> Result
where
CA: AsRef,
{
let https_connector = swagger::https_connector(ca_certificate);
Self::try_new_with_connector::>(
handle,
base_path,
Some("https"),
https_connector,
)
}
/// Create a client with a mutually authenticated TLS connection to the server.
///
/// # Arguments
/// * `handle` - tokio reactor handle to use for execution
/// * `base_path` - base path of the client API, i.e. "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
pub fn try_new_https_mutual(
handle: Handle,
base_path: &str,
ca_certificate: CA,
client_key: K,
client_certificate: C,
) -> Result
where
CA: AsRef,
K: AsRef,
C: AsRef,
{
let https_connector =
swagger::https_mutual_connector(ca_certificate, client_key, client_certificate);
Self::try_new_with_connector::>(
handle,
base_path,
Some("https"),
https_connector,
)
}
/// Create a client with a custom implementation of hyper::client::Connect.
///
/// Intended for use with custom implementations of connect for e.g. protocol logging
/// or similar functionality which requires wrapping the transport layer. When wrapping a TCP connection,
/// this function should be used in conjunction with
/// `swagger::{http_connector, https_connector, https_mutual_connector}`.
///
/// For ordinary tcp connections, prefer the use of `try_new_http`, `try_new_https`
/// and `try_new_https_mutual`, to avoid introducing a dependency on the underlying transport layer.
///
/// # Arguments
///
/// * `handle` - tokio reactor handle to use for execution
/// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
/// * `protocol` - Which protocol to use when constructing the request url, e.g. `Some("http")`
/// * `connector_fn` - Function which returns an implementation of `hyper::client::Connect`
pub fn try_new_with_connector(
handle: Handle,
base_path: &str,
protocol: Option<&'static str>,
connector_fn: Box C + Send + Sync>,
) -> Result
where
C: hyper::client::Connect + hyper::client::Service,
{
let connector = connector_fn(&handle);
let hyper_client = Box::new(hyper::Client::configure().connector(connector).build(
&handle,
));
Ok(Client {
hyper_client: Arc::new(hyper_client),
base_path: into_base_path(base_path, protocol)?,
})
}
/// 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(hyper_client: Arc, Response=hyper::Response, Error=hyper::Error, Future=hyper::client::FutureResponse>>>,
handle: Handle,
base_path: &str)
-> Result
{
Ok(Client {
hyper_client: hyper_client,
base_path: into_base_path(base_path, None)?,
})
}
}
impl Api for Client where C: Has {{#hasAuthMethods}}+ Has