112 lines
3.3 KiB
Plaintext
112 lines
3.3 KiB
Plaintext
#[allow(unused_imports)]
|
|
use progenitor_client::{encode_path, RequestBuilderExt};
|
|
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
|
#[allow(unused_imports)]
|
|
use reqwest::header::{HeaderMap, HeaderValue};
|
|
pub mod types {
|
|
use serde::{Deserialize, Serialize};
|
|
#[allow(unused_imports)]
|
|
use std::convert::TryFrom;
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
///Client for Parameter override test
|
|
///
|
|
///Minimal API for testing parameter overrides
|
|
///
|
|
///Version: v1
|
|
pub struct Client {
|
|
pub(crate) baseurl: String,
|
|
pub(crate) client: reqwest::Client,
|
|
}
|
|
|
|
impl Client {
|
|
/// Create a new client.
|
|
///
|
|
/// `baseurl` is the base URL provided to the internal
|
|
/// `reqwest::Client`, and should include a scheme and hostname,
|
|
/// as well as port and a path stem if applicable.
|
|
pub fn new(baseurl: &str) -> Self {
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
let client = {
|
|
let dur = std::time::Duration::from_secs(15);
|
|
reqwest::ClientBuilder::new()
|
|
.connect_timeout(dur)
|
|
.timeout(dur)
|
|
};
|
|
#[cfg(target_arch = "wasm32")]
|
|
let client = reqwest::ClientBuilder::new();
|
|
Self::new_with_client(baseurl, client.build().unwrap())
|
|
}
|
|
|
|
/// Construct a new client with an existing `reqwest::Client`,
|
|
/// allowing more control over its configuration.
|
|
///
|
|
/// `baseurl` is the base URL provided to the internal
|
|
/// `reqwest::Client`, and should include a scheme and hostname,
|
|
/// as well as port and a path stem if applicable.
|
|
pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self {
|
|
Self {
|
|
baseurl: baseurl.to_string(),
|
|
client,
|
|
}
|
|
}
|
|
|
|
/// Get the base URL to which requests are made.
|
|
pub fn baseurl(&self) -> &String {
|
|
&self.baseurl
|
|
}
|
|
|
|
/// Get the internal `reqwest::Client` used to make requests.
|
|
pub fn client(&self) -> &reqwest::Client {
|
|
&self.client
|
|
}
|
|
|
|
/// Get the version of this API.
|
|
///
|
|
/// This string is pulled directly from the source OpenAPI
|
|
/// document and may be in any format the API selects.
|
|
pub fn api_version(&self) -> &'static str {
|
|
"v1"
|
|
}
|
|
}
|
|
|
|
impl Client {
|
|
///Gets a key
|
|
///
|
|
///Sends a `GET` request to `/key`
|
|
///
|
|
///Arguments:
|
|
/// - `key`: The same key parameter that overlaps with the path level
|
|
/// parameter
|
|
/// - `unique_key`: A key parameter that will not be overridden by the path
|
|
/// spec
|
|
pub async fn key_get<'a>(
|
|
&'a self,
|
|
key: Option<bool>,
|
|
unique_key: Option<&'a str>,
|
|
) -> Result<ResponseValue<()>, Error<()>> {
|
|
let url = format!("{}/key", self.baseurl,);
|
|
let mut query = Vec::with_capacity(2usize);
|
|
if let Some(v) = &key {
|
|
query.push(("key", v.to_string()));
|
|
}
|
|
|
|
if let Some(v) = &unique_key {
|
|
query.push(("uniqueKey", v.to_string()));
|
|
}
|
|
|
|
let request = self.client.get(url).query(&query).build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200u16 => Ok(ResponseValue::empty(response)),
|
|
_ => Err(Error::UnexpectedResponse(response)),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub mod prelude {
|
|
pub use super::Client;
|
|
}
|