use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct R2GetEventNotificationConfigs<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2GetEventNotificationConfigs<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/event_notifications/r2/{}/configuration",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_get_event_notification_configs",
};
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 R2GetEventNotificationConfig<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
queue_id: Result<types::R2QueueIdentifier, String>,
cf_r2_jurisdiction: Result<types::R2GetEventNotificationConfigCfR2Jurisdiction, String>,
}
impl<'a> R2GetEventNotificationConfig<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
queue_id: Err("queue_id was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn queue_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2QueueIdentifier>,
{
self.queue_id = value
.try_into()
.map_err(|_| "conversion to `R2QueueIdentifier` for queue_id failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2GetEventNotificationConfigCfR2Jurisdiction>,
{
self . cf_r2_jurisdiction = value . try_into () . map_err (| _ | "conversion to `R2GetEventNotificationConfigCfR2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
queue_id,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let queue_id = queue_id.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/event_notifications/r2/{}/configuration/queues/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
encode_path(&queue_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_get_event_notification_config",
};
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 R2PutEventNotificationConfig<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
queue_id: Result<types::R2QueueIdentifier, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
body: Result<types::builder::R2PutEventNotificationConfigBody, String>,
}
impl<'a> R2PutEventNotificationConfig<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
queue_id: Err("queue_id was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction 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::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn queue_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2QueueIdentifier>,
{
self.queue_id = value
.try_into()
.map_err(|_| "conversion to `R2QueueIdentifier` for queue_id failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2PutEventNotificationConfigBody>,
<V as std::convert::TryInto<types::R2PutEventNotificationConfigBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `R2PutEventNotificationConfigBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::R2PutEventNotificationConfigBody,
) -> types::builder::R2PutEventNotificationConfigBody,
{
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,
bucket_name,
queue_id,
cf_r2_jurisdiction,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let queue_id = queue_id.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::R2PutEventNotificationConfigBody::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/event_notifications/r2/{}/configuration/queues/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
encode_path(&queue_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[allow(unused_mut)]
let mut request = client
.client
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "r2_put_event_notification_config",
};
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 R2EventNotificationDeleteConfig<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
queue_id: Result<types::R2QueueIdentifier, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
body: Result<types::builder::R2EventNotificationDeleteConfigBody, String>,
}
impl<'a> R2EventNotificationDeleteConfig<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
queue_id: Err("queue_id was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction 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::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn queue_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2QueueIdentifier>,
{
self.queue_id = value
.try_into()
.map_err(|_| "conversion to `R2QueueIdentifier` for queue_id failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2EventNotificationDeleteConfigBody>,
<V as std::convert::TryInto<types::R2EventNotificationDeleteConfigBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `R2EventNotificationDeleteConfigBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::R2EventNotificationDeleteConfigBody,
) -> types::builder::R2EventNotificationDeleteConfigBody,
{
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,
bucket_name,
queue_id,
cf_r2_jurisdiction,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let queue_id = queue_id.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::R2EventNotificationDeleteConfigBody::try_from(v)
.map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/event_notifications/r2/{}/configuration/queues/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
encode_path(&queue_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[allow(unused_mut)]
let mut request = client
.client
.delete(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "r2_event_notification_delete_config",
};
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 R2GetBucket<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2GetBucket<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_get_bucket",
};
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 R2DeleteBucket<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2DeleteBucket<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_delete_bucket",
};
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 R2PatchBucket<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
cf_r2_storage_class: Result<types::R2StorageClass, String>,
}
impl<'a> R2PatchBucket<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
cf_r2_storage_class: Err("cf_r2_storage_class was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction failed".to_string()
});
self
}
pub fn cf_r2_storage_class<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2StorageClass>,
{
self.cf_r2_storage_class = value.try_into().map_err(|_| {
"conversion to `R2StorageClass` for cf_r2_storage_class 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,
bucket_name,
cf_r2_jurisdiction,
cf_r2_storage_class,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let cf_r2_storage_class = cf_r2_storage_class.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(3usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
header_map.append(
"cf-r2-storage-class",
cf_r2_storage_class.to_string().try_into()?,
);
#[allow(unused_mut)]
let mut request = client
.client
.patch(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "r2_patch_bucket",
};
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 R2GetBucketCorsPolicy<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2GetBucketCorsPolicy<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/cors",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_get_bucket_cors_policy",
};
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 R2PutBucketCorsPolicy<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
body: Result<types::builder::R2PutBucketCorsPolicyBody, String>,
}
impl<'a> R2PutBucketCorsPolicy<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction 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::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2PutBucketCorsPolicyBody>,
<V as std::convert::TryInto<types::R2PutBucketCorsPolicyBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `R2PutBucketCorsPolicyBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::R2PutBucketCorsPolicyBody,
) -> types::builder::R2PutBucketCorsPolicyBody,
{
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,
bucket_name,
cf_r2_jurisdiction,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::R2PutBucketCorsPolicyBody::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/cors",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[allow(unused_mut)]
let mut request = client
.client
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "r2_put_bucket_cors_policy",
};
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 R2DeleteBucketCorsPolicy<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2DeleteBucketCorsPolicy<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/cors",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_delete_bucket_cors_policy",
};
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 R2ListCustomDomains<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2ListCustomDomains<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/domains/custom",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_list_custom_domains",
};
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 R2AddCustomDomain<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
body: Result<types::builder::R2AddCustomDomainRequest, String>,
}
impl<'a> R2AddCustomDomain<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction 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::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AddCustomDomainRequest>,
<V as std::convert::TryInto<types::R2AddCustomDomainRequest>>::Error: std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `R2AddCustomDomainRequest` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::R2AddCustomDomainRequest,
) -> types::builder::R2AddCustomDomainRequest,
{
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,
bucket_name,
cf_r2_jurisdiction,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::R2AddCustomDomainRequest::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/domains/custom",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_add_custom_domain",
};
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 R2GetCustomDomainSettings<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
domain: Result<types::R2DomainName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2GetCustomDomainSettings<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
domain: Err("domain was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn domain<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2DomainName>,
{
self.domain = value
.try_into()
.map_err(|_| "conversion to `R2DomainName` for domain failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
domain,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let domain = domain.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/domains/custom/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
encode_path(&domain.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_get_custom_domain_settings",
};
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 R2EditCustomDomainSettings<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
domain: Result<types::R2DomainName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
body: Result<types::builder::R2EditCustomDomainRequest, String>,
}
impl<'a> R2EditCustomDomainSettings<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
domain: Err("domain was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction 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::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn domain<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2DomainName>,
{
self.domain = value
.try_into()
.map_err(|_| "conversion to `R2DomainName` for domain failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2EditCustomDomainRequest>,
<V as std::convert::TryInto<types::R2EditCustomDomainRequest>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `R2EditCustomDomainRequest` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::R2EditCustomDomainRequest,
) -> types::builder::R2EditCustomDomainRequest,
{
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,
bucket_name,
domain,
cf_r2_jurisdiction,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let domain = domain.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::R2EditCustomDomainRequest::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/domains/custom/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
encode_path(&domain.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[allow(unused_mut)]
let mut request = client
.client
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "r2_edit_custom_domain_settings",
};
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 R2DeleteCustomDomain<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
domain: Result<types::R2DomainName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2DeleteCustomDomain<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
domain: Err("domain was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn domain<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2DomainName>,
{
self.domain = value
.try_into()
.map_err(|_| "conversion to `R2DomainName` for domain failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
domain,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let domain = domain.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/domains/custom/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
encode_path(&domain.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_delete_custom_domain",
};
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 R2GetBucketPublicPolicy<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2GetBucketPublicPolicy<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/domains/managed",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_get_bucket_public_policy",
};
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 R2PutBucketPublicPolicy<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
body: Result<types::builder::R2EditManagedDomainRequest, String>,
}
impl<'a> R2PutBucketPublicPolicy<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction 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::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2EditManagedDomainRequest>,
<V as std::convert::TryInto<types::R2EditManagedDomainRequest>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `R2EditManagedDomainRequest` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::R2EditManagedDomainRequest,
) -> types::builder::R2EditManagedDomainRequest,
{
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,
bucket_name,
cf_r2_jurisdiction,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::R2EditManagedDomainRequest::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/domains/managed",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[allow(unused_mut)]
let mut request = client
.client
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "r2_put_bucket_public_policy",
};
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 R2GetBucketLifecycleConfiguration<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2GetBucketLifecycleConfiguration<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/lifecycle",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_get_bucket_lifecycle_configuration",
};
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 R2PutBucketLifecycleConfiguration<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
body: Result<types::builder::R2PutBucketLifecycleConfigurationBody, String>,
}
impl<'a> R2PutBucketLifecycleConfiguration<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction 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::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2PutBucketLifecycleConfigurationBody>,
<V as std::convert::TryInto<types::R2PutBucketLifecycleConfigurationBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `R2PutBucketLifecycleConfigurationBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::R2PutBucketLifecycleConfigurationBody,
)
-> types::builder::R2PutBucketLifecycleConfigurationBody,
{
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,
bucket_name,
cf_r2_jurisdiction,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::R2PutBucketLifecycleConfigurationBody::try_from(v)
.map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/lifecycle",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[allow(unused_mut)]
let mut request = client
.client
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "r2_put_bucket_lifecycle_configuration",
};
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 R2GetBucketLocalUploadsConfiguration<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
}
impl<'a> R2GetBucketLocalUploadsConfiguration<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name 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,
bucket_name,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/local-uploads",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.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: "r2_get_bucket_local_uploads_configuration",
};
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 R2PutBucketLocalUploadsConfiguration<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
body: Result<types::builder::R2PutBucketLocalUploadsConfigurationBody, String>,
}
impl<'a> R2PutBucketLocalUploadsConfiguration<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name 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::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2PutBucketLocalUploadsConfigurationBody>,
<V as std::convert::TryInto<types::R2PutBucketLocalUploadsConfigurationBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `R2PutBucketLocalUploadsConfigurationBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::R2PutBucketLocalUploadsConfigurationBody,
)
-> types::builder::R2PutBucketLocalUploadsConfigurationBody,
{
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,
bucket_name,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::R2PutBucketLocalUploadsConfigurationBody::try_from(v)
.map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/local-uploads",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.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
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "r2_put_bucket_local_uploads_configuration",
};
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 R2GetBucketLockConfiguration<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2GetBucketLockConfiguration<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/lock",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_get_bucket_lock_configuration",
};
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 R2PutBucketLockConfiguration<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
body: Result<types::builder::R2PutBucketLockConfigurationBody, String>,
}
impl<'a> R2PutBucketLockConfiguration<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction 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::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2PutBucketLockConfigurationBody>,
<V as std::convert::TryInto<types::R2PutBucketLockConfigurationBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `R2PutBucketLockConfigurationBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::R2PutBucketLockConfigurationBody,
) -> types::builder::R2PutBucketLockConfigurationBody,
{
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,
bucket_name,
cf_r2_jurisdiction,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::R2PutBucketLockConfigurationBody::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/lock",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[allow(unused_mut)]
let mut request = client
.client
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "r2_put_bucket_lock_configuration",
};
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 R2GetBucketSippyConfig<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2GetBucketSippyConfig<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/sippy",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_get_bucket_sippy_config",
};
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 R2PutBucketSippyConfig<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
body: Result<types::R2PutBucketSippyConfigBody, String>,
}
impl<'a> R2PutBucketSippyConfig<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction 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::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2PutBucketSippyConfigBody>,
{
self.body = value.try_into().map_err(|_| {
"conversion to `R2PutBucketSippyConfigBody` 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,
bucket_name,
cf_r2_jurisdiction,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/sippy",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[allow(unused_mut)]
let mut request = client
.client
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "r2_put_bucket_sippy_config",
};
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 R2DeleteBucketSippyConfig<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
bucket_name: Result<types::R2BucketName, String>,
cf_r2_jurisdiction: Result<types::R2Jurisdiction, String>,
}
impl<'a> R2DeleteBucketSippyConfig<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
bucket_name: Err("bucket_name was not initialized".to_string()),
cf_r2_jurisdiction: Err("cf_r2_jurisdiction was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn bucket_name<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2BucketName>,
{
self.bucket_name = value
.try_into()
.map_err(|_| "conversion to `R2BucketName` for bucket_name failed".to_string());
self
}
pub fn cf_r2_jurisdiction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2Jurisdiction>,
{
self.cf_r2_jurisdiction = value.try_into().map_err(|_| {
"conversion to `R2Jurisdiction` for cf_r2_jurisdiction 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,
bucket_name,
cf_r2_jurisdiction,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let bucket_name = bucket_name.map_err(Error::InvalidRequest)?;
let cf_r2_jurisdiction = cf_r2_jurisdiction.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/buckets/{}/sippy",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&bucket_name.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(2usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
header_map.append(
"cf-r2-jurisdiction",
cf_r2_jurisdiction.to_string().try_into()?,
);
#[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: "r2_delete_bucket_sippy_config",
};
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 R2CreateTempAccessCredentials<'a> {
client: &'a crate::Client,
account_id: Result<types::R2AccountIdentifier, String>,
body: Result<types::builder::R2TempAccessCredsRequest, String>,
}
impl<'a> R2CreateTempAccessCredentials<'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::R2AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `R2AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::R2TempAccessCredsRequest>,
<V as std::convert::TryInto<types::R2TempAccessCredsRequest>>::Error: std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `R2TempAccessCredsRequest` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::R2TempAccessCredsRequest,
) -> types::builder::R2TempAccessCredsRequest,
{
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::R2TempAccessCredsRequest::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/r2/temp-access-credentials",
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: "r2_create_temp_access_credentials",
};
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)),
}
}
}