Reference support in ChangesRequest.
parent
29ec39d98c
commit
47cad8fd17
|
@ -112,6 +112,7 @@ impl ClientBuilder {
|
||||||
let trusted_hosts = Arc::new(self.trusted_hosts);
|
let trusted_hosts = Arc::new(self.trusted_hosts);
|
||||||
|
|
||||||
let trusted_hosts_ = trusted_hosts.clone();
|
let trusted_hosts_ = trusted_hosts.clone();
|
||||||
|
let session_url = format!("{}/.well-known/jmap", url);
|
||||||
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()
|
||||||
|
@ -132,7 +133,7 @@ impl ClientBuilder {
|
||||||
}))
|
}))
|
||||||
.default_headers(headers.clone())
|
.default_headers(headers.clone())
|
||||||
.build()?
|
.build()?
|
||||||
.get(url)
|
.get(&session_url)
|
||||||
.send()
|
.send()
|
||||||
.await?,
|
.await?,
|
||||||
)
|
)
|
||||||
|
@ -159,7 +160,7 @@ impl ClientBuilder {
|
||||||
event_source_url: URLPart::parse(session.event_source_url())?,
|
event_source_url: URLPart::parse(session.event_source_url())?,
|
||||||
api_url: session.api_url().to_string(),
|
api_url: session.api_url().to_string(),
|
||||||
session: parking_lot::Mutex::new(Arc::new(session)),
|
session: parking_lot::Mutex::new(Arc::new(session)),
|
||||||
session_url: url.to_string(),
|
session_url,
|
||||||
session_updated: true.into(),
|
session_updated: true.into(),
|
||||||
trusted_hosts,
|
trusted_hosts,
|
||||||
#[cfg(feature = "websockets")]
|
#[cfg(feature = "websockets")]
|
||||||
|
@ -191,6 +192,7 @@ impl ClientBuilder {
|
||||||
let trusted_hosts = Arc::new(self.trusted_hosts);
|
let trusted_hosts = Arc::new(self.trusted_hosts);
|
||||||
|
|
||||||
let trusted_hosts_ = trusted_hosts.clone();
|
let trusted_hosts_ = trusted_hosts.clone();
|
||||||
|
let session_url = format!("{}/.well-known/jmap", url);
|
||||||
let session: Session = serde_json::from_slice(
|
let session: Session = serde_json::from_slice(
|
||||||
&Client::handle_error(
|
&Client::handle_error(
|
||||||
reqwest::blocking::Client::builder()
|
reqwest::blocking::Client::builder()
|
||||||
|
@ -211,7 +213,7 @@ impl ClientBuilder {
|
||||||
}))
|
}))
|
||||||
.default_headers(headers.clone())
|
.default_headers(headers.clone())
|
||||||
.build()?
|
.build()?
|
||||||
.get(url)
|
.get(&session_url)
|
||||||
.send()
|
.send()
|
||||||
?,
|
?,
|
||||||
)?
|
)?
|
||||||
|
@ -236,7 +238,7 @@ impl ClientBuilder {
|
||||||
event_source_url: URLPart::parse(session.event_source_url())?,
|
event_source_url: URLPart::parse(session.event_source_url())?,
|
||||||
api_url: session.api_url().to_string(),
|
api_url: session.api_url().to_string(),
|
||||||
session: parking_lot::Mutex::new(Arc::new(session)),
|
session: parking_lot::Mutex::new(Arc::new(session)),
|
||||||
session_url: url.to_string(),
|
session_url,
|
||||||
session_updated: true.into(),
|
session_updated: true.into(),
|
||||||
trusted_hosts,
|
trusted_hosts,
|
||||||
#[cfg(feature = "websockets")]
|
#[cfg(feature = "websockets")]
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{Object, RequestParams};
|
use crate::Method;
|
||||||
|
|
||||||
|
use super::{request::ResultReference, Object, RequestParams};
|
||||||
|
|
||||||
pub trait ChangesObject: Object {
|
pub trait ChangesObject: Object {
|
||||||
type ChangesResponse;
|
type ChangesResponse;
|
||||||
|
@ -8,6 +10,9 @@ pub trait ChangesObject: Object {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct ChangesRequest {
|
pub struct ChangesRequest {
|
||||||
|
#[serde(skip)]
|
||||||
|
method: (Method, usize),
|
||||||
|
|
||||||
#[serde(rename = "accountId")]
|
#[serde(rename = "accountId")]
|
||||||
account_id: String,
|
account_id: String,
|
||||||
|
|
||||||
|
@ -46,6 +51,7 @@ pub struct ChangesResponse<O: ChangesObject> {
|
||||||
impl ChangesRequest {
|
impl ChangesRequest {
|
||||||
pub fn new(params: RequestParams, since_state: String) -> Self {
|
pub fn new(params: RequestParams, since_state: String) -> Self {
|
||||||
ChangesRequest {
|
ChangesRequest {
|
||||||
|
method: (params.method, params.call_id),
|
||||||
account_id: params.account_id,
|
account_id: params.account_id,
|
||||||
since_state,
|
since_state,
|
||||||
max_changes: None,
|
max_changes: None,
|
||||||
|
@ -61,6 +67,18 @@ impl ChangesRequest {
|
||||||
self.max_changes = Some(max_changes);
|
self.max_changes = Some(max_changes);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn created_reference(&self) -> ResultReference {
|
||||||
|
ResultReference::new(self.method.0, self.method.1, "/created")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn updated_reference(&self) -> ResultReference {
|
||||||
|
ResultReference::new(self.method.0, self.method.1, "/updated")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn updated_properties_reference(&self) -> ResultReference {
|
||||||
|
ResultReference::new(self.method.0, self.method.1, "/updatedProperties")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<O: ChangesObject> ChangesResponse<O> {
|
impl<O: ChangesObject> ChangesResponse<O> {
|
||||||
|
|
|
@ -28,6 +28,11 @@ pub struct GetRequest<O: GetObject> {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
properties: Option<Vec<O::Property>>,
|
properties: Option<Vec<O::Property>>,
|
||||||
|
|
||||||
|
#[serde(rename = "#properties")]
|
||||||
|
#[serde(skip_deserializing)]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
properties_ref: Option<ResultReference>,
|
||||||
|
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
arguments: O::GetArguments,
|
arguments: O::GetArguments,
|
||||||
}
|
}
|
||||||
|
@ -57,6 +62,7 @@ impl<O: GetObject> GetRequest<O> {
|
||||||
ids: None,
|
ids: None,
|
||||||
ids_ref: None,
|
ids_ref: None,
|
||||||
properties: None,
|
properties: None,
|
||||||
|
properties_ref: None,
|
||||||
arguments: O::GetArguments::default(),
|
arguments: O::GetArguments::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,6 +92,13 @@ impl<O: GetObject> GetRequest<O> {
|
||||||
|
|
||||||
pub fn properties(&mut self, properties: impl IntoIterator<Item = O::Property>) -> &mut Self {
|
pub fn properties(&mut self, properties: impl IntoIterator<Item = O::Property>) -> &mut Self {
|
||||||
self.properties = Some(properties.into_iter().collect());
|
self.properties = Some(properties.into_iter().collect());
|
||||||
|
self.properties_ref = None;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn properties_ref(&mut self, reference: ResultReference) -> &mut Self {
|
||||||
|
self.properties_ref = Some(reference);
|
||||||
|
self.properties = None;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl Default for Role {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
pub struct MailboxRights {
|
pub struct MailboxRights {
|
||||||
#[serde(rename = "mayReadItems")]
|
#[serde(rename = "mayReadItems")]
|
||||||
may_read_items: bool,
|
may_read_items: bool,
|
||||||
|
|
Loading…
Reference in New Issue