|
| 1 | +#[allow(unused_imports)] |
| 2 | +use progenitor_client::{encode_path, ClientHooks, OperationInfo, RequestBuilderExt}; |
| 3 | +#[allow(unused_imports)] |
| 4 | +pub use progenitor_client::{ByteStream, ClientInfo, Error, ResponseValue}; |
| 5 | +/// Types used as operation parameters and responses. |
| 6 | +#[allow(clippy::all)] |
| 7 | +pub mod types { |
| 8 | + /// Error types. |
| 9 | + pub mod error { |
| 10 | + /// Error from a `TryFrom` or `FromStr` implementation. |
| 11 | + pub struct ConversionError(::std::borrow::Cow<'static, str>); |
| 12 | + impl ::std::error::Error for ConversionError {} |
| 13 | + impl ::std::fmt::Display for ConversionError { |
| 14 | + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> { |
| 15 | + ::std::fmt::Display::fmt(&self.0, f) |
| 16 | + } |
| 17 | + } |
| 18 | + |
| 19 | + impl ::std::fmt::Debug for ConversionError { |
| 20 | + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> { |
| 21 | + ::std::fmt::Debug::fmt(&self.0, f) |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + impl From<&'static str> for ConversionError { |
| 26 | + fn from(value: &'static str) -> Self { |
| 27 | + Self(value.into()) |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + impl From<String> for ConversionError { |
| 32 | + fn from(value: String) -> Self { |
| 33 | + Self(value.into()) |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +#[derive(Clone, Debug)] |
| 40 | +///Client for httpmock-query-array |
| 41 | +/// |
| 42 | +///Version: 0.0.0 |
| 43 | +pub struct Client { |
| 44 | + pub(crate) baseurl: String, |
| 45 | + pub(crate) client: reqwest::Client, |
| 46 | +} |
| 47 | + |
| 48 | +impl Client { |
| 49 | + /// Create a new client. |
| 50 | + /// |
| 51 | + /// `baseurl` is the base URL provided to the internal |
| 52 | + /// `reqwest::Client`, and should include a scheme and hostname, |
| 53 | + /// as well as port and a path stem if applicable. |
| 54 | + pub fn new(baseurl: &str) -> Self { |
| 55 | + #[cfg(not(target_arch = "wasm32"))] |
| 56 | + let client = { |
| 57 | + let dur = ::std::time::Duration::from_secs(15u64); |
| 58 | + reqwest::ClientBuilder::new() |
| 59 | + .connect_timeout(dur) |
| 60 | + .timeout(dur) |
| 61 | + }; |
| 62 | + #[cfg(target_arch = "wasm32")] |
| 63 | + let client = reqwest::ClientBuilder::new(); |
| 64 | + Self::new_with_client(baseurl, client.build().unwrap()) |
| 65 | + } |
| 66 | + |
| 67 | + /// Construct a new client with an existing `reqwest::Client`, |
| 68 | + /// allowing more control over its configuration. |
| 69 | + /// |
| 70 | + /// `baseurl` is the base URL provided to the internal |
| 71 | + /// `reqwest::Client`, and should include a scheme and hostname, |
| 72 | + /// as well as port and a path stem if applicable. |
| 73 | + pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self { |
| 74 | + Self { |
| 75 | + baseurl: baseurl.to_string(), |
| 76 | + client, |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +impl ClientInfo<()> for Client { |
| 82 | + fn api_version() -> &'static str { |
| 83 | + "0.0.0" |
| 84 | + } |
| 85 | + |
| 86 | + fn baseurl(&self) -> &str { |
| 87 | + self.baseurl.as_str() |
| 88 | + } |
| 89 | + |
| 90 | + fn client(&self) -> &reqwest::Client { |
| 91 | + &self.client |
| 92 | + } |
| 93 | + |
| 94 | + fn inner(&self) -> &() { |
| 95 | + &() |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +impl ClientHooks<()> for &Client {} |
| 100 | +impl Client { |
| 101 | + ///Sends a `GET` request to `/widgets` |
| 102 | + /// |
| 103 | + ///```ignore |
| 104 | + /// let response = client.list_widgets() |
| 105 | + /// .tags(tags) |
| 106 | + /// .send() |
| 107 | + /// .await; |
| 108 | + /// ``` |
| 109 | + pub fn list_widgets(&self) -> builder::ListWidgets<'_> { |
| 110 | + builder::ListWidgets::new(self) |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +/// Types for composing operation parameters. |
| 115 | +#[allow(clippy::all)] |
| 116 | +pub mod builder { |
| 117 | + use super::types; |
| 118 | + #[allow(unused_imports)] |
| 119 | + use super::{ |
| 120 | + encode_path, ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt, |
| 121 | + ResponseValue, |
| 122 | + }; |
| 123 | + ///Builder for [`Client::list_widgets`] |
| 124 | + /// |
| 125 | + ///[`Client::list_widgets`]: super::Client::list_widgets |
| 126 | + #[derive(Debug, Clone)] |
| 127 | + pub struct ListWidgets<'a> { |
| 128 | + client: &'a super::Client, |
| 129 | + tags: Result<::std::vec::Vec<::std::string::String>, String>, |
| 130 | + } |
| 131 | + |
| 132 | + impl<'a> ListWidgets<'a> { |
| 133 | + pub fn new(client: &'a super::Client) -> Self { |
| 134 | + Self { |
| 135 | + client: client, |
| 136 | + tags: Err("tags was not initialized".to_string()), |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + pub fn tags<V>(mut self, value: V) -> Self |
| 141 | + where |
| 142 | + V: std::convert::TryInto<::std::vec::Vec<::std::string::String>>, |
| 143 | + { |
| 144 | + self.tags = value.try_into().map_err(|_| { |
| 145 | + "conversion to `:: std :: vec :: Vec < :: std :: string :: String >` for tags \ |
| 146 | + failed" |
| 147 | + .to_string() |
| 148 | + }); |
| 149 | + self |
| 150 | + } |
| 151 | + |
| 152 | + ///Sends a `GET` request to `/widgets` |
| 153 | + pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> { |
| 154 | + let Self { client, tags } = self; |
| 155 | + let tags = tags.map_err(Error::InvalidRequest)?; |
| 156 | + let url = format!("{}/widgets", client.baseurl,); |
| 157 | + let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); |
| 158 | + header_map.append( |
| 159 | + ::reqwest::header::HeaderName::from_static("api-version"), |
| 160 | + ::reqwest::header::HeaderValue::from_static(super::Client::api_version()), |
| 161 | + ); |
| 162 | + #[allow(unused_mut)] |
| 163 | + let mut request = client |
| 164 | + .client |
| 165 | + .get(url) |
| 166 | + .query(&progenitor_client::QueryParam::new("tags", &tags)) |
| 167 | + .headers(header_map) |
| 168 | + .build()?; |
| 169 | + let info = OperationInfo { |
| 170 | + operation_id: "list_widgets", |
| 171 | + }; |
| 172 | + client.pre(&mut request, &info).await?; |
| 173 | + let result = client.exec(request, &info).await; |
| 174 | + client.post(&result, &info).await?; |
| 175 | + let response = result?; |
| 176 | + match response.status().as_u16() { |
| 177 | + 204u16 => Ok(ResponseValue::empty(response)), |
| 178 | + _ => Err(Error::UnexpectedResponse(response)), |
| 179 | + } |
| 180 | + } |
| 181 | + } |
| 182 | +} |
| 183 | + |
| 184 | +/// Items consumers will typically use such as the Client. |
| 185 | +pub mod prelude { |
| 186 | + pub use self::super::Client; |
| 187 | +} |
0 commit comments