Non-mutable client.

main
Mauro D 2022-06-17 17:31:00 +00:00
parent 951a8ea8c3
commit c085cf5c89
12 changed files with 155 additions and 127 deletions

View File

@ -1,4 +1,7 @@
use std::time::Duration; use std::{
sync::atomic::{AtomicBool, Ordering},
time::Duration,
};
use reqwest::{ use reqwest::{
header::{self}, header::{self},
@ -27,6 +30,7 @@ pub enum Credentials {
pub struct Client { pub struct Client {
session: Session, session: Session,
session_url: String, session_url: String,
session_outdated: AtomicBool,
#[cfg(feature = "websockets")] #[cfg(feature = "websockets")]
pub(crate) authorization: String, pub(crate) authorization: String,
upload_url: Vec<URLPart<blob::URLParameter>>, upload_url: Vec<URLPart<blob::URLParameter>>,
@ -36,7 +40,7 @@ pub struct Client {
headers: header::HeaderMap, headers: header::HeaderMap,
default_account_id: String, default_account_id: String,
#[cfg(feature = "websockets")] #[cfg(feature = "websockets")]
ws: Option<crate::client_ws::WsStream>, pub(crate) ws: tokio::sync::Mutex<Option<crate::client_ws::WsStream>>,
} }
impl Client { impl Client {
@ -87,13 +91,14 @@ impl Client {
event_source_url: URLPart::parse(session.event_source_url())?, event_source_url: URLPart::parse(session.event_source_url())?,
session, session,
session_url: url.to_string(), session_url: url.to_string(),
session_outdated: false.into(),
#[cfg(feature = "websockets")] #[cfg(feature = "websockets")]
authorization, authorization,
timeout: DEFAULT_TIMEOUT_MS, timeout: DEFAULT_TIMEOUT_MS,
headers, headers,
default_account_id, default_account_id,
#[cfg(feature = "websockets")] #[cfg(feature = "websockets")]
ws: None, ws: None.into(),
}) })
} }
@ -110,12 +115,16 @@ impl Client {
&self.session &self.session
} }
pub fn session_url(&self) -> &str {
&self.session_url
}
pub fn headers(&self) -> &header::HeaderMap { pub fn headers(&self) -> &header::HeaderMap {
&self.headers &self.headers
} }
pub async fn send<R>( pub async fn send<R>(
&mut self, &self,
request: &request::Request<'_>, request: &request::Request<'_>,
) -> crate::Result<response::Response<R>> ) -> crate::Result<response::Response<R>>
where where
@ -138,6 +147,13 @@ impl Client {
)?; )?;
if response.session_state() != self.session.state() { if response.session_state() != self.session.state() {
self.session_outdated.store(true, Ordering::Relaxed);
}
Ok(response)
}
pub async fn refresh_session(&mut self) -> crate::Result<()> {
let session: Session = serde_json::from_slice( let session: Session = serde_json::from_slice(
&Client::handle_error( &Client::handle_error(
reqwest::Client::builder() reqwest::Client::builder()
@ -156,9 +172,12 @@ impl Client {
self.upload_url = URLPart::parse(session.upload_url())?; self.upload_url = URLPart::parse(session.upload_url())?;
self.event_source_url = URLPart::parse(session.event_source_url())?; self.event_source_url = URLPart::parse(session.event_source_url())?;
self.session = session; self.session = session;
self.session_outdated.store(false, Ordering::Relaxed);
Ok(())
} }
Ok(response) pub fn is_session_updated(&self) -> bool {
!self.session_outdated.load(Ordering::Relaxed)
} }
pub fn set_default_account_id(&mut self, defaul_account_id: impl Into<String>) -> &mut Self { pub fn set_default_account_id(&mut self, defaul_account_id: impl Into<String>) -> &mut Self {
@ -170,7 +189,7 @@ impl Client {
&self.default_account_id &self.default_account_id
} }
pub fn build(&mut self) -> Request<'_> { pub fn build(&self) -> Request<'_> {
Request::new(self) Request::new(self)
} }
@ -201,16 +220,6 @@ impl Client {
Err(Error::Server(format!("{}", response.status()))) Err(Error::Server(format!("{}", response.status())))
} }
} }
#[cfg(feature = "websockets")]
pub fn set_ws_stream(&mut self, ws: crate::client_ws::WsStream) {
self.ws = Some(ws);
}
#[cfg(feature = "websockets")]
pub fn ws_stream(&mut self) -> Option<&mut crate::client_ws::WsStream> {
self.ws.as_mut()
}
} }
impl Credentials { impl Credentials {

View File

@ -123,7 +123,7 @@ pub struct WebSocketProblem {
status: Option<u32>, status: Option<u32>,
title: Option<String>, title: Option<String>,
detail: Option<String>, detail: Option<String>,
limit: Option<usize>, limit: Option<String>,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -152,7 +152,7 @@ pub struct WsStream {
impl Client { impl Client {
pub async fn connect_ws( pub async fn connect_ws(
&mut self, &self,
) -> crate::Result<Pin<Box<impl Stream<Item = crate::Result<WebSocketMessage>>>>> { ) -> crate::Result<Pin<Box<impl Stream<Item = crate::Result<WebSocketMessage>>>>> {
let capabilities = self.session().websocket_capabilities().ok_or_else(|| { let capabilities = self.session().websocket_capabilities().ok_or_else(|| {
crate::Error::Internal( crate::Error::Internal(
@ -168,7 +168,7 @@ impl Client {
let (stream, _) = tokio_tungstenite::connect_async(request).await?; let (stream, _) = tokio_tungstenite::connect_async(request).await?;
let (tx, mut rx) = stream.split(); let (tx, mut rx) = stream.split();
self.set_ws_stream(WsStream { tx, req_id: 0 }); *self.ws.lock().await = WsStream { tx, req_id: 0 }.into();
Ok(Box::pin(async_stream::stream! { Ok(Box::pin(async_stream::stream! {
while let Some(message) = rx.next().await { while let Some(message) = rx.next().await {
@ -202,9 +202,10 @@ impl Client {
})) }))
} }
pub async fn send_ws(&mut self, request: Request<'_>) -> crate::Result<String> { pub async fn send_ws(&self, request: Request<'_>) -> crate::Result<String> {
let ws = self let mut _ws = self.ws.lock().await;
.ws_stream() let ws = _ws
.as_mut()
.ok_or_else(|| crate::Error::Internal("Websocket stream not set.".to_string()))?; .ok_or_else(|| crate::Error::Internal("Websocket stream not set.".to_string()))?;
// Assing request id // Assing request id
@ -228,11 +229,14 @@ impl Client {
} }
pub async fn enable_push_ws( pub async fn enable_push_ws(
&mut self, &self,
data_types: Option<impl IntoIterator<Item = StateChangeType>>, data_types: Option<impl IntoIterator<Item = StateChangeType>>,
push_state: Option<impl Into<String>>, push_state: Option<impl Into<String>>,
) -> crate::Result<()> { ) -> crate::Result<()> {
self.ws_stream() self.ws
.lock()
.await
.as_mut()
.ok_or_else(|| crate::Error::Internal("Websocket stream not set.".to_string()))? .ok_or_else(|| crate::Error::Internal("Websocket stream not set.".to_string()))?
.tx .tx
.send(Message::text( .send(Message::text(
@ -247,8 +251,11 @@ impl Client {
.map_err(|err| err.into()) .map_err(|err| err.into())
} }
pub async fn disable_push_ws(&mut self) -> crate::Result<()> { pub async fn disable_push_ws(&self) -> crate::Result<()> {
self.ws_stream() self.ws
.lock()
.await
.as_mut()
.ok_or_else(|| crate::Error::Internal("Websocket stream not set.".to_string()))? .ok_or_else(|| crate::Error::Internal("Websocket stream not set.".to_string()))?
.tx .tx
.send(Message::text( .send(Message::text(
@ -261,8 +268,11 @@ impl Client {
.map_err(|err| err.into()) .map_err(|err| err.into())
} }
pub async fn ws_ping(&mut self) -> crate::Result<()> { pub async fn ws_ping(&self) -> crate::Result<()> {
self.ws_stream() self.ws
.lock()
.await
.as_mut()
.ok_or_else(|| crate::Error::Internal("Websocket stream not set.".to_string()))? .ok_or_else(|| crate::Error::Internal("Websocket stream not set.".to_string()))?
.tx .tx
.send(Message::Ping(vec![])) .send(Message::Ping(vec![]))

View File

@ -6,15 +6,15 @@ use serde::Deserialize;
pub struct ProblemDetails { pub struct ProblemDetails {
#[serde(rename = "type")] #[serde(rename = "type")]
p_type: ProblemType, p_type: ProblemType,
status: Option<u32>, pub status: Option<u32>,
title: Option<String>, title: Option<String>,
detail: Option<String>, detail: Option<String>,
limit: Option<usize>, limit: Option<String>,
request_id: Option<String>, request_id: Option<String>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub enum ProblemType { pub enum JMAPError {
#[serde(rename = "urn:ietf:params:jmap:error:unknownCapability")] #[serde(rename = "urn:ietf:params:jmap:error:unknownCapability")]
UnknownCapability, UnknownCapability,
#[serde(rename = "urn:ietf:params:jmap:error:notJSON")] #[serde(rename = "urn:ietf:params:jmap:error:notJSON")]
@ -26,12 +26,19 @@ pub enum ProblemType {
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct MethodError { #[serde(untagged)]
#[serde(rename = "type")] pub enum ProblemType {
p_type: MethodErrorType, JMAP(JMAPError),
Other(String),
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize, PartialEq, Eq)]
pub struct MethodError {
#[serde(rename = "type")]
pub p_type: MethodErrorType,
}
#[derive(Debug, Deserialize, PartialEq, Eq)]
pub enum MethodErrorType { pub enum MethodErrorType {
#[serde(rename = "serverUnavailable")] #[serde(rename = "serverUnavailable")]
ServerUnavailable, ServerUnavailable,
@ -81,7 +88,7 @@ impl ProblemDetails {
status: Option<u32>, status: Option<u32>,
title: Option<String>, title: Option<String>,
detail: Option<String>, detail: Option<String>,
limit: Option<usize>, limit: Option<String>,
request_id: Option<String>, request_id: Option<String>,
) -> Self { ) -> Self {
ProblemDetails { ProblemDetails {
@ -110,8 +117,8 @@ impl ProblemDetails {
self.detail.as_deref() self.detail.as_deref()
} }
pub fn limit(&self) -> Option<usize> { pub fn limit(&self) -> Option<&str> {
self.limit self.limit.as_deref()
} }
pub fn request_id(&self) -> Option<&str> { pub fn request_id(&self) -> Option<&str> {
@ -158,11 +165,14 @@ impl Display for MethodError {
impl Display for ProblemDetails { impl Display for ProblemDetails {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.p_type { match &self.p_type {
ProblemType::UnknownCapability => write!(f, "Unknown capability")?, ProblemType::JMAP(err) => match err {
ProblemType::NotJSON => write!(f, "Not JSON")?, JMAPError::UnknownCapability => write!(f, "Unknown capability")?,
ProblemType::NotRequest => write!(f, "Not request")?, JMAPError::NotJSON => write!(f, "Not JSON")?,
ProblemType::Limit => write!(f, "Limit")?, JMAPError::NotRequest => write!(f, "Not request")?,
JMAPError::Limit => write!(f, "Limit")?,
},
ProblemType::Other(err) => f.write_str(err.as_str())?,
} }
if let Some(status) = self.status { if let Some(status) = self.status {

View File

@ -30,7 +30,7 @@ use super::{
#[derive(Serialize)] #[derive(Serialize)]
pub struct Request<'x> { pub struct Request<'x> {
#[serde(skip)] #[serde(skip)]
client: Option<&'x mut Client>, client: &'x Client,
#[serde(skip)] #[serde(skip)]
default_account_id: String, default_account_id: String,
@ -401,31 +401,30 @@ impl Arguments {
} }
impl<'x> Request<'x> { impl<'x> Request<'x> {
pub fn new(client: &'x mut Client) -> Self { pub fn new(client: &'x Client) -> Self {
Request { Request {
using: vec![URI::Core, URI::Mail], using: vec![URI::Core, URI::Mail],
method_calls: vec![], method_calls: vec![],
created_ids: None, created_ids: None,
default_account_id: client.default_account_id().to_string(), default_account_id: client.default_account_id().to_string(),
client: client.into(), client,
} }
} }
pub async fn send(mut self) -> crate::Result<Response<TaggedMethodResponse>> { pub async fn send(self) -> crate::Result<Response<TaggedMethodResponse>> {
Option::take(&mut self.client).unwrap().send(&self).await self.client.send(&self).await
} }
#[cfg(feature = "websockets")] #[cfg(feature = "websockets")]
pub async fn send_ws(mut self) -> crate::Result<String> { pub async fn send_ws(self) -> crate::Result<String> {
Option::take(&mut self.client).unwrap().send_ws(self).await self.client.send_ws(self).await
} }
pub async fn send_single<T>(mut self) -> crate::Result<T> pub async fn send_single<T>(self) -> crate::Result<T>
where where
T: DeserializeOwned, T: DeserializeOwned,
{ {
let response: Response<SingleMethodResponse<T>> = let response: Response<SingleMethodResponse<T>> = self.client.send(&self).await?;
Option::take(&mut self.client).unwrap().send(&self).await?;
match response match response
.unwrap_method_responses() .unwrap_method_responses()
.pop() .pop()

View File

@ -21,7 +21,7 @@ use super::{
impl Client { impl Client {
pub async fn email_import<T, U, V, W>( pub async fn email_import<T, U, V, W>(
&mut self, &self,
raw_message: Vec<u8>, raw_message: Vec<u8>,
mailbox_ids: T, mailbox_ids: T,
keywords: Option<V>, keywords: Option<V>,
@ -56,7 +56,7 @@ impl Client {
} }
pub async fn email_set_mailbox( pub async fn email_set_mailbox(
&mut self, &self,
id: &str, id: &str,
mailbox_id: &str, mailbox_id: &str,
set: bool, set: bool,
@ -67,7 +67,7 @@ impl Client {
} }
pub async fn email_set_mailboxes<T, U>( pub async fn email_set_mailboxes<T, U>(
&mut self, &self,
id: &str, id: &str,
mailbox_ids: T, mailbox_ids: T,
) -> crate::Result<Option<Email>> ) -> crate::Result<Option<Email>>
@ -81,7 +81,7 @@ impl Client {
} }
pub async fn email_set_keyword( pub async fn email_set_keyword(
&mut self, &self,
id: &str, id: &str,
keyword: &str, keyword: &str,
set: bool, set: bool,
@ -92,7 +92,7 @@ impl Client {
} }
pub async fn email_set_keywords<T, U>( pub async fn email_set_keywords<T, U>(
&mut self, &self,
id: &str, id: &str,
keywords: T, keywords: T,
) -> crate::Result<Option<Email>> ) -> crate::Result<Option<Email>>
@ -105,7 +105,7 @@ impl Client {
request.send_single::<EmailSetResponse>().await?.updated(id) request.send_single::<EmailSetResponse>().await?.updated(id)
} }
pub async fn email_destroy(&mut self, id: &str) -> crate::Result<()> { pub async fn email_destroy(&self, id: &str) -> crate::Result<()> {
let mut request = self.build(); let mut request = self.build();
request.set_email().destroy([id]); request.set_email().destroy([id]);
request request
@ -115,7 +115,7 @@ impl Client {
} }
pub async fn email_get( pub async fn email_get(
&mut self, &self,
id: &str, id: &str,
properties: Option<impl IntoIterator<Item = Property>>, properties: Option<impl IntoIterator<Item = Property>>,
) -> crate::Result<Option<Email<Get>>> { ) -> crate::Result<Option<Email<Get>>> {
@ -131,7 +131,7 @@ impl Client {
} }
pub async fn email_changes( pub async fn email_changes(
&mut self, &self,
since_state: impl Into<String>, since_state: impl Into<String>,
max_changes: usize, max_changes: usize,
) -> crate::Result<ChangesResponse<Email<Get>>> { ) -> crate::Result<ChangesResponse<Email<Get>>> {
@ -141,7 +141,7 @@ impl Client {
} }
pub async fn email_query( pub async fn email_query(
&mut self, &self,
filter: Option<impl Into<Filter<super::query::Filter>>>, filter: Option<impl Into<Filter<super::query::Filter>>>,
sort: Option<Vec<Comparator<super::query::Comparator>>>, sort: Option<Vec<Comparator<super::query::Comparator>>>,
) -> crate::Result<QueryResponse> { ) -> crate::Result<QueryResponse> {
@ -157,7 +157,7 @@ impl Client {
} }
pub async fn email_parse( pub async fn email_parse(
&mut self, &self,
blob_id: &str, blob_id: &str,
properties: Option<impl IntoIterator<Item = Property>>, properties: Option<impl IntoIterator<Item = Property>>,
body_properties: Option<impl IntoIterator<Item = BodyProperty>>, body_properties: Option<impl IntoIterator<Item = BodyProperty>>,
@ -186,7 +186,7 @@ impl Client {
} }
pub async fn email_copy<T, U, V, W>( pub async fn email_copy<T, U, V, W>(
&mut self, &self,
from_account_id: impl Into<String>, from_account_id: impl Into<String>,
id: impl Into<String>, id: impl Into<String>,
mailbox_ids: T, mailbox_ids: T,

View File

@ -16,7 +16,7 @@ use super::{Address, EmailSubmission, Property, UndoStatus};
impl Client { impl Client {
pub async fn email_submission_create( pub async fn email_submission_create(
&mut self, &self,
email_id: impl Into<String>, email_id: impl Into<String>,
identity_id: impl Into<String>, identity_id: impl Into<String>,
) -> crate::Result<EmailSubmission<Get>> { ) -> crate::Result<EmailSubmission<Get>> {
@ -35,7 +35,7 @@ impl Client {
} }
pub async fn email_submission_create_envelope<S, T, U>( pub async fn email_submission_create_envelope<S, T, U>(
&mut self, &self,
email_id: impl Into<String>, email_id: impl Into<String>,
identity_id: impl Into<String>, identity_id: impl Into<String>,
mail_from: S, mail_from: S,
@ -62,7 +62,7 @@ impl Client {
} }
pub async fn email_submission_change_status( pub async fn email_submission_change_status(
&mut self, &self,
id: &str, id: &str,
undo_status: UndoStatus, undo_status: UndoStatus,
) -> crate::Result<Option<EmailSubmission>> { ) -> crate::Result<Option<EmailSubmission>> {
@ -77,7 +77,7 @@ impl Client {
.updated(id) .updated(id)
} }
pub async fn email_submission_destroy(&mut self, id: &str) -> crate::Result<()> { pub async fn email_submission_destroy(&self, id: &str) -> crate::Result<()> {
let mut request = self.build(); let mut request = self.build();
request.set_email_submission().destroy([id]); request.set_email_submission().destroy([id]);
request request
@ -87,7 +87,7 @@ impl Client {
} }
pub async fn email_submission_get( pub async fn email_submission_get(
&mut self, &self,
id: &str, id: &str,
properties: Option<Vec<Property>>, properties: Option<Vec<Property>>,
) -> crate::Result<Option<EmailSubmission>> { ) -> crate::Result<Option<EmailSubmission>> {
@ -103,7 +103,7 @@ impl Client {
} }
pub async fn email_submission_query( pub async fn email_submission_query(
&mut self, &self,
filter: Option<impl Into<Filter<super::query::Filter>>>, filter: Option<impl Into<Filter<super::query::Filter>>>,
sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>, sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>,
) -> crate::Result<QueryResponse> { ) -> crate::Result<QueryResponse> {
@ -119,7 +119,7 @@ impl Client {
} }
pub async fn email_submission_changes( pub async fn email_submission_changes(
&mut self, &self,
since_state: impl Into<String>, since_state: impl Into<String>,
max_changes: usize, max_changes: usize,
) -> crate::Result<ChangesResponse<EmailSubmission<Get>>> { ) -> crate::Result<ChangesResponse<EmailSubmission<Get>>> {

View File

@ -14,7 +14,7 @@ use super::{Identity, Property};
impl Client { impl Client {
pub async fn identity_create( pub async fn identity_create(
&mut self, &self,
name: impl Into<String>, name: impl Into<String>,
email: impl Into<String>, email: impl Into<String>,
) -> crate::Result<Identity> { ) -> crate::Result<Identity> {
@ -32,7 +32,7 @@ impl Client {
.created(&id) .created(&id)
} }
pub async fn identity_destroy(&mut self, id: &str) -> crate::Result<()> { pub async fn identity_destroy(&self, id: &str) -> crate::Result<()> {
let mut request = self.build(); let mut request = self.build();
request.set_identity().destroy([id]); request.set_identity().destroy([id]);
request request
@ -42,7 +42,7 @@ impl Client {
} }
pub async fn identity_get( pub async fn identity_get(
&mut self, &self,
id: &str, id: &str,
properties: Option<Vec<Property>>, properties: Option<Vec<Property>>,
) -> crate::Result<Option<Identity>> { ) -> crate::Result<Option<Identity>> {
@ -58,7 +58,7 @@ impl Client {
} }
pub async fn identity_changes( pub async fn identity_changes(
&mut self, &self,
since_state: impl Into<String>, since_state: impl Into<String>,
max_changes: usize, max_changes: usize,
) -> crate::Result<ChangesResponse<Identity<Get>>> { ) -> crate::Result<ChangesResponse<Identity<Get>>> {

View File

@ -16,7 +16,7 @@ use super::{Mailbox, Property, Role};
impl Client { impl Client {
pub async fn mailbox_create( pub async fn mailbox_create(
&mut self, &self,
name: impl Into<String>, name: impl Into<String>,
parent_id: Option<impl Into<String>>, parent_id: Option<impl Into<String>>,
role: Role, role: Role,
@ -37,7 +37,7 @@ impl Client {
} }
pub async fn mailbox_rename( pub async fn mailbox_rename(
&mut self, &self,
id: &str, id: &str,
name: impl Into<String>, name: impl Into<String>,
) -> crate::Result<Option<Mailbox>> { ) -> crate::Result<Option<Mailbox>> {
@ -50,7 +50,7 @@ impl Client {
} }
pub async fn mailbox_move( pub async fn mailbox_move(
&mut self, &self,
id: &str, id: &str,
parent_id: Option<impl Into<String>>, parent_id: Option<impl Into<String>>,
) -> crate::Result<Option<Mailbox>> { ) -> crate::Result<Option<Mailbox>> {
@ -63,7 +63,7 @@ impl Client {
} }
pub async fn mailbox_update_role( pub async fn mailbox_update_role(
&mut self, &self,
id: &str, id: &str,
role: Role, role: Role,
) -> crate::Result<Option<Mailbox>> { ) -> crate::Result<Option<Mailbox>> {
@ -76,7 +76,7 @@ impl Client {
} }
pub async fn mailbox_update_sort_order( pub async fn mailbox_update_sort_order(
&mut self, &self,
id: &str, id: &str,
sort_order: u32, sort_order: u32,
) -> crate::Result<Option<Mailbox>> { ) -> crate::Result<Option<Mailbox>> {
@ -88,7 +88,7 @@ impl Client {
.updated(id) .updated(id)
} }
pub async fn mailbox_destroy(&mut 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
.set_mailbox() .set_mailbox()
@ -102,7 +102,7 @@ impl Client {
} }
pub async fn mailbox_get( pub async fn mailbox_get(
&mut self, &self,
id: &str, id: &str,
properties: Option<Vec<Property>>, properties: Option<Vec<Property>>,
) -> crate::Result<Option<Mailbox>> { ) -> crate::Result<Option<Mailbox>> {
@ -118,7 +118,7 @@ impl Client {
} }
pub async fn mailbox_query( pub async fn mailbox_query(
&mut self, &self,
filter: Option<impl Into<Filter<super::query::Filter>>>, filter: Option<impl Into<Filter<super::query::Filter>>>,
sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>, sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>,
) -> crate::Result<QueryResponse> { ) -> crate::Result<QueryResponse> {
@ -134,7 +134,7 @@ impl Client {
} }
pub async fn mailbox_changes( pub async fn mailbox_changes(
&mut self, &self,
since_state: impl Into<String>, since_state: impl Into<String>,
max_changes: usize, max_changes: usize,
) -> crate::Result<ChangesResponse<Mailbox<Get>>> { ) -> crate::Result<ChangesResponse<Mailbox<Get>>> {

View File

@ -16,7 +16,7 @@ use super::{Principal, Property, Type};
impl Client { impl Client {
pub async fn individual_create( pub async fn individual_create(
&mut self, &self,
email: impl Into<String>, email: impl Into<String>,
secret: impl Into<String>, secret: impl Into<String>,
name: impl Into<String>, name: impl Into<String>,
@ -37,7 +37,7 @@ impl Client {
.created(&id) .created(&id)
} }
pub async fn domain_create(&mut self, name: impl Into<String>) -> crate::Result<Principal> { pub async fn domain_create(&self, name: impl Into<String>) -> crate::Result<Principal> {
let mut request = self.build(); let mut request = self.build();
let id = request let id = request
.set_principal() .set_principal()
@ -53,7 +53,7 @@ impl Client {
} }
pub async fn list_create( pub async fn list_create(
&mut self, &self,
email: impl Into<String>, email: impl Into<String>,
name: impl Into<String>, name: impl Into<String>,
members: impl IntoIterator<Item = impl Into<String>>, members: impl IntoIterator<Item = impl Into<String>>,
@ -75,7 +75,7 @@ impl Client {
} }
pub async fn group_create( pub async fn group_create(
&mut self, &self,
email: impl Into<String>, email: impl Into<String>,
name: impl Into<String>, name: impl Into<String>,
members: impl IntoIterator<Item = impl Into<String>>, members: impl IntoIterator<Item = impl Into<String>>,
@ -97,7 +97,7 @@ impl Client {
} }
pub async fn principal_set_name( pub async fn principal_set_name(
&mut self, &self,
id: &str, id: &str,
name: impl Into<String>, name: impl Into<String>,
) -> crate::Result<Option<Principal>> { ) -> crate::Result<Option<Principal>> {
@ -110,7 +110,7 @@ impl Client {
} }
pub async fn principal_set_secret( pub async fn principal_set_secret(
&mut self, &self,
id: &str, id: &str,
secret: impl Into<String>, secret: impl Into<String>,
) -> crate::Result<Option<Principal>> { ) -> crate::Result<Option<Principal>> {
@ -123,7 +123,7 @@ impl Client {
} }
pub async fn principal_set_email( pub async fn principal_set_email(
&mut self, &self,
id: &str, id: &str,
email: impl Into<String>, email: impl Into<String>,
) -> crate::Result<Option<Principal>> { ) -> crate::Result<Option<Principal>> {
@ -136,7 +136,7 @@ impl Client {
} }
pub async fn principal_set_timezone( pub async fn principal_set_timezone(
&mut self, &self,
id: &str, id: &str,
timezone: Option<impl Into<String>>, timezone: Option<impl Into<String>>,
) -> crate::Result<Option<Principal>> { ) -> crate::Result<Option<Principal>> {
@ -149,7 +149,7 @@ impl Client {
} }
pub async fn principal_set_members( pub async fn principal_set_members(
&mut self, &self,
id: &str, id: &str,
members: Option<impl IntoIterator<Item = impl Into<String>>>, members: Option<impl IntoIterator<Item = impl Into<String>>>,
) -> crate::Result<Option<Principal>> { ) -> crate::Result<Option<Principal>> {
@ -162,7 +162,7 @@ impl Client {
} }
pub async fn principal_set_aliases( pub async fn principal_set_aliases(
&mut self, &self,
id: &str, id: &str,
aliases: Option<impl IntoIterator<Item = impl Into<String>>>, aliases: Option<impl IntoIterator<Item = impl Into<String>>>,
) -> crate::Result<Option<Principal>> { ) -> crate::Result<Option<Principal>> {
@ -175,7 +175,7 @@ impl Client {
} }
pub async fn principal_set_capabilities( pub async fn principal_set_capabilities(
&mut self, &self,
id: &str, id: &str,
capabilities: Option<impl IntoIterator<Item = impl Into<String>>>, capabilities: Option<impl IntoIterator<Item = impl Into<String>>>,
) -> crate::Result<Option<Principal>> { ) -> crate::Result<Option<Principal>> {
@ -190,7 +190,7 @@ impl Client {
.updated(id) .updated(id)
} }
pub async fn principal_destroy(&mut self, id: &str) -> crate::Result<()> { pub async fn principal_destroy(&self, id: &str) -> crate::Result<()> {
let mut request = self.build(); let mut request = self.build();
request.set_principal().destroy([id]).arguments(); request.set_principal().destroy([id]).arguments();
request request
@ -200,7 +200,7 @@ impl Client {
} }
pub async fn principal_get( pub async fn principal_get(
&mut self, &self,
id: &str, id: &str,
properties: Option<Vec<Property>>, properties: Option<Vec<Property>>,
) -> crate::Result<Option<Principal>> { ) -> crate::Result<Option<Principal>> {
@ -216,7 +216,7 @@ impl Client {
} }
pub async fn principal_query( pub async fn principal_query(
&mut self, &self,
filter: Option<impl Into<Filter<super::query::Filter>>>, filter: Option<impl Into<Filter<super::query::Filter>>>,
sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>, sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>,
) -> crate::Result<QueryResponse> { ) -> crate::Result<QueryResponse> {
@ -232,7 +232,7 @@ impl Client {
} }
pub async fn principal_changes( pub async fn principal_changes(
&mut self, &self,
since_state: impl Into<String>, since_state: impl Into<String>,
max_changes: usize, max_changes: usize,
) -> crate::Result<ChangesResponse<Principal<Get>>> { ) -> crate::Result<ChangesResponse<Principal<Get>>> {

View File

@ -13,7 +13,7 @@ use super::{Keys, PushSubscription};
impl Client { impl Client {
pub async fn push_subscription_create( pub async fn push_subscription_create(
&mut self, &self,
device_client_id: impl Into<String>, device_client_id: impl Into<String>,
url: impl Into<String>, url: impl Into<String>,
keys: Option<Keys>, keys: Option<Keys>,
@ -37,7 +37,7 @@ impl Client {
} }
pub async fn push_subscription_verify( pub async fn push_subscription_verify(
&mut self, &self,
id: &str, id: &str,
verification_code: impl Into<String>, verification_code: impl Into<String>,
) -> crate::Result<Option<PushSubscription>> { ) -> crate::Result<Option<PushSubscription>> {
@ -53,7 +53,7 @@ impl Client {
} }
pub async fn push_subscription_update_types( pub async fn push_subscription_update_types(
&mut self, &self,
id: &str, id: &str,
types: Option<impl IntoIterator<Item = TypeState>>, types: Option<impl IntoIterator<Item = TypeState>>,
) -> crate::Result<Option<PushSubscription>> { ) -> crate::Result<Option<PushSubscription>> {
@ -65,7 +65,7 @@ impl Client {
.updated(id) .updated(id)
} }
pub async fn push_subscription_destroy(&mut self, id: &str) -> crate::Result<()> { pub async fn push_subscription_destroy(&self, id: &str) -> crate::Result<()> {
let mut request = self.build(); let mut request = self.build();
request.set_push_subscription().destroy([id]); request.set_push_subscription().destroy([id]);
request request

View File

@ -12,7 +12,7 @@ use crate::{
use super::Thread; use super::Thread;
impl Client { impl Client {
pub async fn thread_get(&mut self, id: &str) -> crate::Result<Option<Thread>> { pub async fn thread_get(&self, id: &str) -> crate::Result<Option<Thread>> {
let mut request = self.build(); let mut request = self.build();
request.get_thread().ids([id]); request.get_thread().ids([id]);
request request

View File

@ -13,7 +13,7 @@ use super::{Property, VacationResponse};
impl Client { impl Client {
pub async fn vacation_response_create( pub async fn vacation_response_create(
&mut self, &self,
subject: impl Into<String>, subject: impl Into<String>,
text_body: Option<impl Into<String>>, text_body: Option<impl Into<String>>,
html_body: Option<impl Into<String>>, html_body: Option<impl Into<String>>,
@ -36,7 +36,7 @@ impl Client {
} }
pub async fn vacation_response_enable( pub async fn vacation_response_enable(
&mut self, &self,
subject: impl Into<String>, subject: impl Into<String>,
text_body: Option<impl Into<String>>, text_body: Option<impl Into<String>>,
html_body: Option<impl Into<String>>, html_body: Option<impl Into<String>>,
@ -56,7 +56,7 @@ impl Client {
.updated("singleton") .updated("singleton")
} }
pub async fn vacation_response_disable(&mut self) -> crate::Result<Option<VacationResponse>> { pub async fn vacation_response_disable(&self) -> crate::Result<Option<VacationResponse>> {
let mut request = self.build(); let mut request = self.build();
request request
.set_vacation_response() .set_vacation_response()
@ -70,7 +70,7 @@ impl Client {
} }
pub async fn vacation_response_set_dates( pub async fn vacation_response_set_dates(
&mut self, &self,
from_date: Option<i64>, from_date: Option<i64>,
to_date: Option<i64>, to_date: Option<i64>,
) -> crate::Result<Option<VacationResponse>> { ) -> crate::Result<Option<VacationResponse>> {
@ -89,7 +89,7 @@ impl Client {
} }
pub async fn vacation_response_get( pub async fn vacation_response_get(
&mut self, &self,
properties: Option<Vec<Property>>, properties: Option<Vec<Property>>,
) -> crate::Result<Option<VacationResponse>> { ) -> crate::Result<Option<VacationResponse>> {
let mut request = self.build(); let mut request = self.build();
@ -103,7 +103,7 @@ impl Client {
.map(|mut r| r.unwrap_list().pop()) .map(|mut r| r.unwrap_list().pop())
} }
pub async fn vacation_response_destroy(&mut self) -> crate::Result<()> { pub async fn vacation_response_destroy(&self) -> crate::Result<()> {
let mut request = self.build(); let mut request = self.build();
request.set_vacation_response().destroy(["singleton"]); request.set_vacation_response().destroy(["singleton"]);
request request