diff --git a/src/core/set.rs b/src/core/set.rs index 739387f..fc2f683 100644 --- a/src/core/set.rs +++ b/src/core/set.rs @@ -234,6 +234,10 @@ impl SetResponse { self.new_state.as_deref() } + pub fn unwrap_new_state(&mut self) -> Option { + self.new_state.take() + } + pub fn created(&mut self, id: &str) -> crate::Result { if let Some(result) = self.created.as_mut().and_then(|r| r.remove(id)) { Ok(result) @@ -291,6 +295,18 @@ impl SetResponse { pub fn not_destroyed_ids(&self) -> Option> { 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 SetError { diff --git a/src/email/get.rs b/src/email/get.rs index a8ec751..8ce7e6c 100644 --- a/src/email/get.rs +++ b/src/email/get.rs @@ -11,7 +11,7 @@ impl Email { } pub fn unwrap_id(self) -> String { - self.id.unwrap() + self.id.unwrap_or_default() } pub fn blob_id(&self) -> Option<&str> { diff --git a/src/email_submission/get.rs b/src/email_submission/get.rs index 85fbbb6..59141b3 100644 --- a/src/email_submission/get.rs +++ b/src/email_submission/get.rs @@ -10,7 +10,7 @@ impl EmailSubmission { } pub fn unwrap_id(self) -> String { - self.id.unwrap() + self.id.unwrap_or_default() } pub fn identity_id(&self) -> Option<&str> { diff --git a/src/identity/get.rs b/src/identity/get.rs index c436e71..bd400c1 100644 --- a/src/identity/get.rs +++ b/src/identity/get.rs @@ -8,7 +8,7 @@ impl Identity { } pub fn unwrap_id(self) -> String { - self.id.unwrap() + self.id.unwrap_or_default() } pub fn name(&self) -> Option<&str> { diff --git a/src/mailbox/get.rs b/src/mailbox/get.rs index 92a9d47..cbeeb4f 100644 --- a/src/mailbox/get.rs +++ b/src/mailbox/get.rs @@ -10,7 +10,7 @@ impl Mailbox { } pub fn unwrap_id(self) -> String { - self.id.unwrap() + self.id.unwrap_or_default() } pub fn name(&self) -> Option<&str> { diff --git a/src/mailbox/helpers.rs b/src/mailbox/helpers.rs index f81d1fb..478b8ca 100644 --- a/src/mailbox/helpers.rs +++ b/src/mailbox/helpers.rs @@ -103,6 +103,22 @@ impl Client { .updated(id) } + pub async fn mailbox_subscribe( + &self, + id: &str, + is_subscribed: bool, + ) -> crate::Result> { + let mut request = self.build(); + request + .set_mailbox() + .update(id) + .is_subscribed(is_subscribed); + request + .send_single::() + .await? + .updated(id) + } + pub async fn mailbox_destroy(&self, id: &str, delete_emails: bool) -> crate::Result<()> { let mut request = self.build(); request diff --git a/src/mailbox/set.rs b/src/mailbox/set.rs index f8f58d7..60791e5 100644 --- a/src/mailbox/set.rs +++ b/src/mailbox/set.rs @@ -34,6 +34,11 @@ impl Mailbox { self } + pub fn is_subscribed(&mut self, is_subscribed: bool) -> &mut Self { + self.is_subscribed = is_subscribed.into(); + self + } + pub fn acls(&mut self, acls: T) -> &mut Self where T: IntoIterator, diff --git a/src/principal/get.rs b/src/principal/get.rs index a86eb1f..5f151ba 100644 --- a/src/principal/get.rs +++ b/src/principal/get.rs @@ -10,7 +10,7 @@ impl Principal { } pub fn unwrap_id(self) -> String { - self.id.unwrap() + self.id.unwrap_or_default() } pub fn ptype(&self) -> Option<&Type> { diff --git a/src/push_subscription/get.rs b/src/push_subscription/get.rs index e29047d..dfd0de2 100644 --- a/src/push_subscription/get.rs +++ b/src/push_subscription/get.rs @@ -8,7 +8,7 @@ impl PushSubscription { } pub fn unwrap_id(self) -> String { - self.id.unwrap() + self.id.unwrap_or_default() } pub fn device_client_id(&self) -> Option<&str> {