2022-07-03 02:09:38 +00:00
|
|
|
#[allow(unused_imports)]
|
2022-07-08 01:35:36 +00:00
|
|
|
use progenitor_client::{encode_path, RequestBuilderExt};
|
2022-03-15 23:11:47 +00:00
|
|
|
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
2023-01-04 19:14:37 +00:00
|
|
|
#[allow(unused_imports)]
|
|
|
|
use reqwest::header::{HeaderMap, HeaderValue};
|
2022-03-15 23:11:47 +00:00
|
|
|
pub mod types {
|
|
|
|
use serde::{Deserialize, Serialize};
|
2022-07-18 18:55:21 +00:00
|
|
|
#[allow(unused_imports)]
|
|
|
|
use std::convert::TryFrom;
|
2022-07-03 02:09:38 +00:00
|
|
|
///Error information from a response.
|
2022-07-12 17:57:06 +00:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
2022-03-15 23:11:47 +00:00
|
|
|
pub struct Error {
|
|
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
|
|
pub error_code: Option<String>,
|
|
|
|
pub message: String,
|
|
|
|
pub request_id: String,
|
|
|
|
}
|
2023-02-05 01:22:55 +00:00
|
|
|
|
|
|
|
impl From<&Error> for Error {
|
|
|
|
fn from(value: &Error) -> Self {
|
|
|
|
value.clone()
|
|
|
|
}
|
|
|
|
}
|
2022-03-15 23:11:47 +00:00
|
|
|
}
|
|
|
|
|
2022-08-03 01:18:43 +00:00
|
|
|
#[derive(Clone, Debug)]
|
2023-01-08 02:05:33 +00:00
|
|
|
///Client for pagination-demo
|
2023-03-30 06:02:17 +00:00
|
|
|
///
|
|
|
|
///Version: 9000
|
2022-03-15 23:11:47 +00:00
|
|
|
pub struct Client {
|
2022-07-03 02:09:38 +00:00
|
|
|
pub(crate) baseurl: String,
|
|
|
|
pub(crate) client: reqwest::Client,
|
2022-03-15 23:11:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Client {
|
2023-01-08 02:05:33 +00:00
|
|
|
/// 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.
|
2022-03-15 23:11:47 +00:00
|
|
|
pub fn new(baseurl: &str) -> Self {
|
2023-04-26 04:50:04 +00:00
|
|
|
#[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())
|
2022-03-15 23:11:47 +00:00
|
|
|
}
|
|
|
|
|
2023-01-08 02:05:33 +00:00
|
|
|
/// 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.
|
2022-03-15 23:11:47 +00:00
|
|
|
pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self {
|
|
|
|
Self {
|
|
|
|
baseurl: baseurl.to_string(),
|
|
|
|
client,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-30 06:02:17 +00:00
|
|
|
/// Get the base URL to which requests are made.
|
2022-03-15 23:11:47 +00:00
|
|
|
pub fn baseurl(&self) -> &String {
|
|
|
|
&self.baseurl
|
|
|
|
}
|
|
|
|
|
2023-03-30 06:02:17 +00:00
|
|
|
/// Get the internal `reqwest::Client` used to make requests.
|
2022-03-15 23:11:47 +00:00
|
|
|
pub fn client(&self) -> &reqwest::Client {
|
|
|
|
&self.client
|
|
|
|
}
|
2023-03-30 06:02:17 +00:00
|
|
|
|
|
|
|
/// 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 {
|
|
|
|
"9000"
|
|
|
|
}
|
2022-07-03 02:09:38 +00:00
|
|
|
}
|
2022-03-15 23:11:47 +00:00
|
|
|
|
2022-07-03 02:09:38 +00:00
|
|
|
impl Client {
|
2022-07-08 23:54:53 +00:00
|
|
|
///Sends a `GET` request to `/`
|
2022-03-15 23:11:47 +00:00
|
|
|
pub async fn freeform_response<'a>(
|
|
|
|
&'a self,
|
|
|
|
) -> Result<ResponseValue<ByteStream>, Error<ByteStream>> {
|
2022-07-08 23:54:53 +00:00
|
|
|
let url = format!("{}/", self.baseurl,);
|
2022-03-15 23:11:47 +00:00
|
|
|
let request = self.client.get(url).build()?;
|
|
|
|
let result = self.client.execute(request).await;
|
|
|
|
let response = result?;
|
|
|
|
match response.status().as_u16() {
|
|
|
|
200..=299 => Ok(ResponseValue::stream(response)),
|
|
|
|
_ => Err(Error::ErrorResponse(ResponseValue::stream(response))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-27 15:23:02 +00:00
|
|
|
|
|
|
|
pub mod prelude {
|
|
|
|
pub use super::Client;
|
|
|
|
}
|