76 lines
2.4 KiB
Plaintext
76 lines
2.4 KiB
Plaintext
|
pub use progenitor_client::{Error, ResponseValue};
|
||
|
pub mod types {
|
||
|
use serde::{Deserialize, Serialize};
|
||
|
#[doc = "Error information from a response."]
|
||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||
|
pub struct Error {
|
||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||
|
pub error_code: Option<String>,
|
||
|
pub message: String,
|
||
|
pub request_id: String,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[derive(Clone)]
|
||
|
pub struct Client {
|
||
|
baseurl: String,
|
||
|
client: reqwest::Client,
|
||
|
}
|
||
|
|
||
|
impl Client {
|
||
|
pub fn new(baseurl: &str) -> Self {
|
||
|
let dur = std::time::Duration::from_secs(15);
|
||
|
let client = reqwest::ClientBuilder::new()
|
||
|
.connect_timeout(dur)
|
||
|
.timeout(dur)
|
||
|
.build()
|
||
|
.unwrap();
|
||
|
Self::new_with_client(baseurl, client)
|
||
|
}
|
||
|
|
||
|
pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self {
|
||
|
Self {
|
||
|
baseurl: baseurl.to_string(),
|
||
|
client,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn baseurl(&self) -> &String {
|
||
|
&self.baseurl
|
||
|
}
|
||
|
|
||
|
pub fn client(&self) -> &reqwest::Client {
|
||
|
&self.client
|
||
|
}
|
||
|
|
||
|
#[doc = "renamed_parameters: GET /{ref}/{type}/{trait}"]
|
||
|
pub async fn renamed_parameters<'a>(
|
||
|
&'a self,
|
||
|
ref_: &'a str,
|
||
|
type_: &'a str,
|
||
|
trait_: &'a str,
|
||
|
if_: &'a str,
|
||
|
in_: &'a str,
|
||
|
use_: &'a str,
|
||
|
) -> Result<ResponseValue<()>, Error<types::Error>> {
|
||
|
let url = format ! ("{}/{}/{}/{}" , self . baseurl , progenitor_client :: encode_path (& ref . to_string ()) , progenitor_client :: encode_path (& type . to_string ()) , progenitor_client :: encode_path (& trait . to_string ()) ,);
|
||
|
let mut query = Vec::new();
|
||
|
query.push(("if", if_.to_string()));
|
||
|
query.push(("in", in_.to_string()));
|
||
|
query.push(("use", use_.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() {
|
||
|
204u16 => Ok(ResponseValue::empty(response)),
|
||
|
400u16..=499u16 => Err(Error::ErrorResponse(
|
||
|
ResponseValue::from_response(response).await?,
|
||
|
)),
|
||
|
500u16..=599u16 => Err(Error::ErrorResponse(
|
||
|
ResponseValue::from_response(response).await?,
|
||
|
)),
|
||
|
_ => Err(Error::UnexpectedResponse(response)),
|
||
|
}
|
||
|
}
|
||
|
}
|