use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct SubscriptionsList<'a> {
client: &'a crate::Client,
account_id: Result<types::MqIdentifier, String>,
direction: Result<types::SubscriptionsListDirection, String>,
order: Result<types::SubscriptionsListOrder, String>,
page: Result<::std::num::NonZeroU64, String>,
per_page: Result<::std::num::NonZeroU64, String>,
}
impl<'a> SubscriptionsList<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
direction: Err("direction was not initialized".to_string()),
order: Err("order was not initialized".to_string()),
page: Err("page was not initialized".to_string()),
per_page: Err("per_page was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::MqIdentifier>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `MqIdentifier` for account_id failed".to_string());
self
}
pub fn direction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::SubscriptionsListDirection>,
{
self.direction = value.try_into().map_err(|_| {
"conversion to `SubscriptionsListDirection` for direction failed".to_string()
});
self
}
pub fn order<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::SubscriptionsListOrder>,
{
self.order = value
.try_into()
.map_err(|_| "conversion to `SubscriptionsListOrder` for order failed".to_string());
self
}
pub fn page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::num::NonZeroU64>,
{
self.page = value.try_into().map_err(|_| {
"conversion to `:: std :: num :: NonZeroU64` for page failed".to_string()
});
self
}
pub fn per_page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::num::NonZeroU64>,
{
self.per_page = value.try_into().map_err(|_| {
"conversion to `:: std :: num :: NonZeroU64` for per_page failed".to_string()
});
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
direction,
order,
page,
per_page,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let direction = direction.map_err(Error::InvalidRequest)?;
let order = order.map_err(Error::InvalidRequest)?;
let page = page.map_err(Error::InvalidRequest)?;
let per_page = per_page.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/event_subscriptions/subscriptions",
client.baseurl,
encode_path(&account_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.get(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.query(&progenitor_client::QueryParam::new("direction", &direction))
.query(&progenitor_client::QueryParam::new("order", &order))
.query(&progenitor_client::QueryParam::new("page", &page))
.query(&progenitor_client::QueryParam::new("per_page", &per_page))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "subscriptions_list",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct SubscriptionsCreate<'a> {
client: &'a crate::Client,
account_id: Result<types::MqIdentifier, String>,
body: Result<types::builder::SubscriptionsCreateBody, String>,
}
impl<'a> SubscriptionsCreate<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::MqIdentifier>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `MqIdentifier` for account_id failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::SubscriptionsCreateBody>,
<V as std::convert::TryInto<types::SubscriptionsCreateBody>>::Error: std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `SubscriptionsCreateBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::SubscriptionsCreateBody,
) -> types::builder::SubscriptionsCreateBody,
{
self.body = self.body.map(f);
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::SubscriptionsCreateBody::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/event_subscriptions/subscriptions",
client.baseurl,
encode_path(&account_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.post(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "subscriptions_create",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct SubscriptionsGet<'a> {
client: &'a crate::Client,
account_id: Result<types::MqIdentifier, String>,
subscription_id: Result<types::MqIdentifier, String>,
}
impl<'a> SubscriptionsGet<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
subscription_id: Err("subscription_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::MqIdentifier>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `MqIdentifier` for account_id failed".to_string());
self
}
pub fn subscription_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::MqIdentifier>,
{
self.subscription_id = value
.try_into()
.map_err(|_| "conversion to `MqIdentifier` for subscription_id failed".to_string());
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
subscription_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let subscription_id = subscription_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/event_subscriptions/subscriptions/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&subscription_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.get(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "subscriptions_get",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct SubscriptionsDelete<'a> {
client: &'a crate::Client,
account_id: Result<types::MqIdentifier, String>,
subscription_id: Result<types::MqIdentifier, String>,
}
impl<'a> SubscriptionsDelete<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
subscription_id: Err("subscription_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::MqIdentifier>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `MqIdentifier` for account_id failed".to_string());
self
}
pub fn subscription_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::MqIdentifier>,
{
self.subscription_id = value
.try_into()
.map_err(|_| "conversion to `MqIdentifier` for subscription_id failed".to_string());
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
subscription_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let subscription_id = subscription_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/event_subscriptions/subscriptions/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&subscription_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.delete(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "subscriptions_delete",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct SubscriptionsPatch<'a> {
client: &'a crate::Client,
account_id: Result<types::MqIdentifier, String>,
subscription_id: Result<types::MqIdentifier, String>,
body: Result<types::builder::SubscriptionsPatchBody, String>,
}
impl<'a> SubscriptionsPatch<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
subscription_id: Err("subscription_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::MqIdentifier>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `MqIdentifier` for account_id failed".to_string());
self
}
pub fn subscription_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::MqIdentifier>,
{
self.subscription_id = value
.try_into()
.map_err(|_| "conversion to `MqIdentifier` for subscription_id failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::SubscriptionsPatchBody>,
<V as std::convert::TryInto<types::SubscriptionsPatchBody>>::Error: std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `SubscriptionsPatchBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::SubscriptionsPatchBody,
) -> types::builder::SubscriptionsPatchBody,
{
self.body = self.body.map(f);
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
subscription_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let subscription_id = subscription_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| types::SubscriptionsPatchBody::try_from(v).map_err(|e| e.to_string()))
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/event_subscriptions/subscriptions/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&subscription_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.patch(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "subscriptions_patch",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}