API improvements.

main
Mauro D 2022-07-07 17:06:47 +00:00
parent a6d1dbeae9
commit 890bfa3a70
9 changed files with 43 additions and 6 deletions

View File

@ -234,6 +234,10 @@ impl<O: SetObject> SetResponse<O> {
self.new_state.as_deref() self.new_state.as_deref()
} }
pub fn unwrap_new_state(&mut self) -> Option<String> {
self.new_state.take()
}
pub fn created(&mut self, id: &str) -> crate::Result<O> { pub fn created(&mut self, id: &str) -> crate::Result<O> {
if let Some(result) = self.created.as_mut().and_then(|r| r.remove(id)) { if let Some(result) = self.created.as_mut().and_then(|r| r.remove(id)) {
Ok(result) Ok(result)
@ -291,6 +295,18 @@ impl<O: SetObject> SetResponse<O> {
pub fn not_destroyed_ids(&self) -> Option<impl Iterator<Item = &String>> { pub fn not_destroyed_ids(&self) -> Option<impl Iterator<Item = &String>> {
self.not_destroyed.as_ref().map(|map| map.keys()) self.not_destroyed.as_ref().map(|map| map.keys())
} }
pub fn has_updated(&self) -> bool {
self.updated.as_ref().map_or(false, |m| !m.is_empty())
}
pub fn has_created(&self) -> bool {
self.created.as_ref().map_or(false, |m| !m.is_empty())
}
pub fn has_destroyed(&self) -> bool {
self.destroyed.as_ref().map_or(false, |m| !m.is_empty())
}
} }
impl<U: Display> SetError<U> { impl<U: Display> SetError<U> {

View File

@ -11,7 +11,7 @@ impl Email<Get> {
} }
pub fn unwrap_id(self) -> String { pub fn unwrap_id(self) -> String {
self.id.unwrap() self.id.unwrap_or_default()
} }
pub fn blob_id(&self) -> Option<&str> { pub fn blob_id(&self) -> Option<&str> {

View File

@ -10,7 +10,7 @@ impl EmailSubmission<Get> {
} }
pub fn unwrap_id(self) -> String { pub fn unwrap_id(self) -> String {
self.id.unwrap() self.id.unwrap_or_default()
} }
pub fn identity_id(&self) -> Option<&str> { pub fn identity_id(&self) -> Option<&str> {

View File

@ -8,7 +8,7 @@ impl Identity<Get> {
} }
pub fn unwrap_id(self) -> String { pub fn unwrap_id(self) -> String {
self.id.unwrap() self.id.unwrap_or_default()
} }
pub fn name(&self) -> Option<&str> { pub fn name(&self) -> Option<&str> {

View File

@ -10,7 +10,7 @@ impl Mailbox<Get> {
} }
pub fn unwrap_id(self) -> String { pub fn unwrap_id(self) -> String {
self.id.unwrap() self.id.unwrap_or_default()
} }
pub fn name(&self) -> Option<&str> { pub fn name(&self) -> Option<&str> {

View File

@ -103,6 +103,22 @@ impl Client {
.updated(id) .updated(id)
} }
pub async fn mailbox_subscribe(
&self,
id: &str,
is_subscribed: bool,
) -> crate::Result<Option<Mailbox>> {
let mut request = self.build();
request
.set_mailbox()
.update(id)
.is_subscribed(is_subscribed);
request
.send_single::<MailboxSetResponse>()
.await?
.updated(id)
}
pub async fn mailbox_destroy(&self, id: &str, delete_emails: bool) -> crate::Result<()> { pub async fn mailbox_destroy(&self, id: &str, delete_emails: bool) -> crate::Result<()> {
let mut request = self.build(); let mut request = self.build();
request request

View File

@ -34,6 +34,11 @@ impl Mailbox<Set> {
self self
} }
pub fn is_subscribed(&mut self, is_subscribed: bool) -> &mut Self {
self.is_subscribed = is_subscribed.into();
self
}
pub fn acls<T, U, V>(&mut self, acls: T) -> &mut Self pub fn acls<T, U, V>(&mut self, acls: T) -> &mut Self
where where
T: IntoIterator<Item = (U, V)>, T: IntoIterator<Item = (U, V)>,

View File

@ -10,7 +10,7 @@ impl Principal<Get> {
} }
pub fn unwrap_id(self) -> String { pub fn unwrap_id(self) -> String {
self.id.unwrap() self.id.unwrap_or_default()
} }
pub fn ptype(&self) -> Option<&Type> { pub fn ptype(&self) -> Option<&Type> {

View File

@ -8,7 +8,7 @@ impl PushSubscription<Get> {
} }
pub fn unwrap_id(self) -> String { pub fn unwrap_id(self) -> String {
self.id.unwrap() self.id.unwrap_or_default()
} }
pub fn device_client_id(&self) -> Option<&str> { pub fn device_client_id(&self) -> Option<&str> {