use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct ShareDelete<'a> {
client: &'a crate::Client,
account_id: Result<types::ResourceSharingAccountId, String>,
share_id: Result<types::ResourceSharingShareId, String>,
}
impl<'a> ShareDelete<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
share_id: Err("share_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingAccountId` for account_id failed".to_string()
});
self
}
pub fn share_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingShareId>,
{
self.share_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingShareId` for share_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,
share_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let share_id = share_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/shares/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&share_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: "share_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 ShareRecipientsList<'a> {
client: &'a crate::Client,
account_id: Result<types::ResourceSharingAccountId, String>,
share_id: Result<types::ResourceSharingShareId, String>,
include_resources: Result<bool, String>,
page: Result<u64, String>,
per_page: Result<i64, String>,
}
impl<'a> ShareRecipientsList<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
share_id: Err("share_id was not initialized".to_string()),
include_resources: Err("include_resources 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::ResourceSharingAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingAccountId` for account_id failed".to_string()
});
self
}
pub fn share_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingShareId>,
{
self.share_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingShareId` for share_id failed".to_string()
});
self
}
pub fn include_resources<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.include_resources = value
.try_into()
.map_err(|_| "conversion to `bool` for include_resources failed".to_string());
self
}
pub fn page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<u64>,
{
self.page = value
.try_into()
.map_err(|_| "conversion to `u64` for page failed".to_string());
self
}
pub fn per_page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<i64>,
{
self.per_page = value
.try_into()
.map_err(|_| "conversion to `i64` 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,
share_id,
include_resources,
page,
per_page,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let share_id = share_id.map_err(Error::InvalidRequest)?;
let include_resources = include_resources.map_err(Error::InvalidRequest)?;
let page = page.map_err(Error::InvalidRequest)?;
let per_page = per_page.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/shares/{}/recipients",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&share_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(
"include_resources",
&include_resources,
))
.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: "share_recipients_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 ShareRecipientsUpdate<'a> {
client: &'a crate::Client,
account_id: Result<types::ResourceSharingAccountId, String>,
share_id: Result<types::ResourceSharingShareId, String>,
body: Result<types::ResourceSharingUpdateShareRecipientsRequest, String>,
}
impl<'a> ShareRecipientsUpdate<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
share_id: Err("share_id 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::ResourceSharingAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingAccountId` for account_id failed".to_string()
});
self
}
pub fn share_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingShareId>,
{
self.share_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingShareId` for share_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingUpdateShareRecipientsRequest>,
{
self.body = value.try_into().map_err(|_| {
"conversion to `ResourceSharingUpdateShareRecipientsRequest` for body failed"
.to_string()
});
self
}
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self {
client,
account_id,
share_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let share_id = share_id.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/shares/{}/recipients",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&share_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
.put(url)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "share_recipients_update",
};
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() {
204u16 => Ok(ResponseValue::empty(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct ShareRecipientCreate<'a> {
client: &'a crate::Client,
account_id: Result<types::ResourceSharingAccountId, String>,
share_id: Result<types::ResourceSharingShareId, String>,
body: Result<types::builder::ResourceSharingCreateShareRecipientRequest, String>,
}
impl<'a> ShareRecipientCreate<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
share_id: Err("share_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::ResourceSharingAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingAccountId` for account_id failed".to_string()
});
self
}
pub fn share_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingShareId>,
{
self.share_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingShareId` for share_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingCreateShareRecipientRequest>,
<V as std::convert::TryInto<types::ResourceSharingCreateShareRecipientRequest>>::Error:
std::fmt::Display,
{
self . body = value . try_into () . map (From :: from) . map_err (| s | format ! ("conversion to `ResourceSharingCreateShareRecipientRequest` for body failed: {}" , s)) ;
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::ResourceSharingCreateShareRecipientRequest,
)
-> types::builder::ResourceSharingCreateShareRecipientRequest,
{
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,
share_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let share_id = share_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::ResourceSharingCreateShareRecipientRequest::try_from(v)
.map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/shares/{}/recipients",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&share_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: "share_recipient_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() {
201u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct ShareRecipientsGetById<'a> {
client: &'a crate::Client,
account_id: Result<types::ResourceSharingAccountId, String>,
share_id: Result<types::ResourceSharingShareId, String>,
recipient_id: Result<types::ResourceSharingRecipientId, String>,
include_resources: Result<bool, String>,
}
impl<'a> ShareRecipientsGetById<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
share_id: Err("share_id was not initialized".to_string()),
recipient_id: Err("recipient_id was not initialized".to_string()),
include_resources: Err("include_resources was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingAccountId` for account_id failed".to_string()
});
self
}
pub fn share_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingShareId>,
{
self.share_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingShareId` for share_id failed".to_string()
});
self
}
pub fn recipient_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingRecipientId>,
{
self.recipient_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingRecipientId` for recipient_id failed".to_string()
});
self
}
pub fn include_resources<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.include_resources = value
.try_into()
.map_err(|_| "conversion to `bool` for include_resources 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,
share_id,
recipient_id,
include_resources,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let share_id = share_id.map_err(Error::InvalidRequest)?;
let recipient_id = recipient_id.map_err(Error::InvalidRequest)?;
let include_resources = include_resources.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/shares/{}/recipients/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&share_id.to_string()),
encode_path(&recipient_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(
"include_resources",
&include_resources,
))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "share_recipients_get_by_id",
};
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 ShareRecipientDelete<'a> {
client: &'a crate::Client,
account_id: Result<types::ResourceSharingAccountId, String>,
share_id: Result<types::ResourceSharingShareId, String>,
recipient_id: Result<types::ResourceSharingRecipientId, String>,
}
impl<'a> ShareRecipientDelete<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
share_id: Err("share_id was not initialized".to_string()),
recipient_id: Err("recipient_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingAccountId` for account_id failed".to_string()
});
self
}
pub fn share_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingShareId>,
{
self.share_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingShareId` for share_id failed".to_string()
});
self
}
pub fn recipient_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingRecipientId>,
{
self.recipient_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingRecipientId` for recipient_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,
share_id,
recipient_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let share_id = share_id.map_err(Error::InvalidRequest)?;
let recipient_id = recipient_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/shares/{}/recipients/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&share_id.to_string()),
encode_path(&recipient_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: "share_recipient_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 ShareResourcesList<'a> {
client: &'a crate::Client,
account_id: Result<types::ResourceSharingAccountId, String>,
share_id: Result<types::ResourceSharingShareId, String>,
page: Result<u64, String>,
per_page: Result<i64, String>,
resource_type: Result<types::ResourceSharingResourceType, String>,
status: Result<types::ResourceSharingResourceStatus, String>,
}
impl<'a> ShareResourcesList<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
share_id: Err("share_id was not initialized".to_string()),
page: Err("page was not initialized".to_string()),
per_page: Err("per_page was not initialized".to_string()),
resource_type: Err("resource_type was not initialized".to_string()),
status: Err("status was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingAccountId` for account_id failed".to_string()
});
self
}
pub fn share_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingShareId>,
{
self.share_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingShareId` for share_id failed".to_string()
});
self
}
pub fn page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<u64>,
{
self.page = value
.try_into()
.map_err(|_| "conversion to `u64` for page failed".to_string());
self
}
pub fn per_page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<i64>,
{
self.per_page = value
.try_into()
.map_err(|_| "conversion to `i64` for per_page failed".to_string());
self
}
pub fn resource_type<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingResourceType>,
{
self.resource_type = value.try_into().map_err(|_| {
"conversion to `ResourceSharingResourceType` for resource_type failed".to_string()
});
self
}
pub fn status<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingResourceStatus>,
{
self.status = value.try_into().map_err(|_| {
"conversion to `ResourceSharingResourceStatus` for status 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,
share_id,
page,
per_page,
resource_type,
status,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let share_id = share_id.map_err(Error::InvalidRequest)?;
let page = page.map_err(Error::InvalidRequest)?;
let per_page = per_page.map_err(Error::InvalidRequest)?;
let resource_type = resource_type.map_err(Error::InvalidRequest)?;
let status = status.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/shares/{}/resources",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&share_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("page", &page))
.query(&progenitor_client::QueryParam::new("per_page", &per_page))
.query(&progenitor_client::QueryParam::new(
"resource_type",
&resource_type,
))
.query(&progenitor_client::QueryParam::new("status", &status))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "share_resources_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 ShareResourceCreate<'a> {
client: &'a crate::Client,
account_id: Result<types::ResourceSharingAccountId, String>,
share_id: Result<types::ResourceSharingShareId, String>,
body: Result<types::builder::ResourceSharingCreateShareResourceRequest, String>,
}
impl<'a> ShareResourceCreate<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
share_id: Err("share_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::ResourceSharingAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingAccountId` for account_id failed".to_string()
});
self
}
pub fn share_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingShareId>,
{
self.share_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingShareId` for share_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingCreateShareResourceRequest>,
<V as std::convert::TryInto<types::ResourceSharingCreateShareResourceRequest>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `ResourceSharingCreateShareResourceRequest` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::ResourceSharingCreateShareResourceRequest,
)
-> types::builder::ResourceSharingCreateShareResourceRequest,
{
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,
share_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let share_id = share_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::ResourceSharingCreateShareResourceRequest::try_from(v)
.map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/shares/{}/resources",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&share_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: "share_resource_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() {
201u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct ShareResourcesGetById<'a> {
client: &'a crate::Client,
account_id: Result<types::ResourceSharingAccountId, String>,
share_id: Result<types::ResourceSharingShareId, String>,
resource_id: Result<types::ResourceSharingResourceId, String>,
}
impl<'a> ShareResourcesGetById<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
share_id: Err("share_id was not initialized".to_string()),
resource_id: Err("resource_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingAccountId` for account_id failed".to_string()
});
self
}
pub fn share_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingShareId>,
{
self.share_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingShareId` for share_id failed".to_string()
});
self
}
pub fn resource_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingResourceId>,
{
self.resource_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingResourceId` for resource_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,
share_id,
resource_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let share_id = share_id.map_err(Error::InvalidRequest)?;
let resource_id = resource_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/shares/{}/resources/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&share_id.to_string()),
encode_path(&resource_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: "share_resources_get_by_id",
};
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 ShareResourceUpdate<'a> {
client: &'a crate::Client,
account_id: Result<types::ResourceSharingAccountId, String>,
share_id: Result<types::ResourceSharingShareId, String>,
resource_id: Result<types::ResourceSharingResourceId, String>,
body: Result<types::builder::ResourceSharingUpdateShareResourceRequest, String>,
}
impl<'a> ShareResourceUpdate<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
share_id: Err("share_id was not initialized".to_string()),
resource_id: Err("resource_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::ResourceSharingAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingAccountId` for account_id failed".to_string()
});
self
}
pub fn share_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingShareId>,
{
self.share_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingShareId` for share_id failed".to_string()
});
self
}
pub fn resource_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingResourceId>,
{
self.resource_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingResourceId` for resource_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingUpdateShareResourceRequest>,
<V as std::convert::TryInto<types::ResourceSharingUpdateShareResourceRequest>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `ResourceSharingUpdateShareResourceRequest` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::ResourceSharingUpdateShareResourceRequest,
)
-> types::builder::ResourceSharingUpdateShareResourceRequest,
{
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,
share_id,
resource_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let share_id = share_id.map_err(Error::InvalidRequest)?;
let resource_id = resource_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::ResourceSharingUpdateShareResourceRequest::try_from(v)
.map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/shares/{}/resources/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&share_id.to_string()),
encode_path(&resource_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
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "share_resource_update",
};
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 ShareResourceDelete<'a> {
client: &'a crate::Client,
account_id: Result<types::ResourceSharingAccountId, String>,
share_id: Result<types::ResourceSharingShareId, String>,
resource_id: Result<types::ResourceSharingResourceId, String>,
}
impl<'a> ShareResourceDelete<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
share_id: Err("share_id was not initialized".to_string()),
resource_id: Err("resource_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingAccountId>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingAccountId` for account_id failed".to_string()
});
self
}
pub fn share_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingShareId>,
{
self.share_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingShareId` for share_id failed".to_string()
});
self
}
pub fn resource_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ResourceSharingResourceId>,
{
self.resource_id = value.try_into().map_err(|_| {
"conversion to `ResourceSharingResourceId` for resource_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,
share_id,
resource_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let share_id = share_id.map_err(Error::InvalidRequest)?;
let resource_id = resource_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/shares/{}/resources/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&share_id.to_string()),
encode_path(&resource_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: "share_resource_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)),
}
}
}