use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct SubmitAbuseReport<'a> {
client: &'a crate::Client,
account_id: Result<types::SubmitAbuseReportAccountId, String>,
report_param: Result<types::AbuseReportsSubmissionReportType, String>,
body: Result<types::AbuseReportsSubmitReportRequest, String>,
}
impl<'a> SubmitAbuseReport<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
report_param: Err("report_param was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::SubmitAbuseReportAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `SubmitAbuseReportAccountId` for account_id failed".to_string()
});
self
}
pub fn report_param<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::AbuseReportsSubmissionReportType>,
{
self.report_param = value.try_into().map_err(|_| {
"conversion to `AbuseReportsSubmissionReportType` for report_param failed"
.to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::AbuseReportsSubmitReportRequest>,
{
self.body = value.try_into().map_err(|_| {
"conversion to `AbuseReportsSubmitReportRequest` for body 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,
report_param,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let report_param = report_param.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/abuse-reports/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&report_param.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: "submit_abuse_report",
};
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)),
}
}
}