JmapClient

Struct JmapClient 

Source
pub struct JmapClient<C>
where C: Service<Request<String>, Response = Response<Incoming>> + Sync + Send + 'static,
{ /* private fields */ }
Expand description

JMAP client for interacting with JMAP servers.

Implementations§

Source§

impl<C> JmapClient<C>
where C: Service<Request<String>, Response = Response<Incoming>> + Sync + Send + 'static, <C as Service<Request<String>>>::Error: Error + Send + Sync,

Source

pub fn new(client: C, session_url: Uri, api_url: Uri) -> JmapClient<C>

Create a new JMAP client.

Source

pub async fn discover_session_url( client: C, scheme: Scheme, domain: String, ) -> Result<Uri, DiscoverError>

Discover the JMAP session URL for a domain.

The provided client: C MUST handle authentication as required by the server.

§Errors

Returns an error if the domain is invalid or the well-known resource cannot be retrieved.

Source

pub fn api_url(&self) -> &Uri

Returns the server’s apiUrl.

Source

pub fn session_context_url(&self) -> &Uri

Returns the URL for the JMAP session resource.

Source

pub async fn get_session_resource(&self) -> Result<SessionResource>

Fetch the current session resource.

§Errors

Returns an error if the HTTP request fails, the server returns an error status, or the response cannot be parsed as JSON.

Source

pub async fn create_collection<T: RecordType>( &self, name: &str, ) -> Result<Record>

Create a new collection.

§Errors

Returns an error if the server request fails or the server rejects the operation.

Source

pub async fn create_record<T: RecordType>( &self, calendar_id: &str, record: &JsonValue, if_state: Option<&str>, ) -> Result<Record>

Create a new record in a collection.

§Errors

Returns an error if the record is not a JSON object, the server request fails, or the server rejects the operation.

Source

pub async fn update_record<T: RecordType>( &self, record_id: &str, calendar_id: &str, record: &JsonValue, if_state: Option<&str>, ) -> Result<Record>

Update an existing record in a collection.

§Errors

Returns an error if the record is not a JSON object, the server request fails, or the server rejects the operation.

Source

pub async fn delete_collection<T: RecordType>( &self, collection_id: &str, if_state: Option<&str>, ) -> Result<String>

Delete a collection.

§Errors

Returns an error if the server request fails or the server rejects the operation.

Source

pub async fn delete_record<T: RecordType>( &self, record_id: &str, if_state: Option<&str>, ) -> Result<String>

Returns the new server state. Delete a record.

§Errors

Returns an error if the server request fails or the server rejects the operation.

Source

pub async fn get_collections<T>(&self) -> Result<Vec<T>>
where T: RecordType,

Get all collections of a specific type.

§Errors

Returns an error if the server request fails or the response cannot be parsed.

Source

pub async fn get_records<T: RecordType>( &self, calendar_id: &str, ) -> Result<Vec<Record>>

Get all records in a collection.

§Errors

Returns an error if the server request fails or the response cannot be parsed.

Source

pub async fn changes<T: RecordType>( &self, since_state: &str, max_changes: Option<u32>, ) -> Result<ChangesResponse>

Get changes for a data type since a given state.

Uses the JMAP Foo/changes method to retrieve all changes (created, updated, destroyed) since the provided state.

§Errors

Returns an error if the server request fails or the response cannot be parsed.

Source

pub async fn changed_since<T: RecordType>( &self, id: &str, old_state: &str, ) -> Result<(ChangeStatus, String)>

Check if an item has changed since a given state.

Uses the JMAP Foo/changes method to determine if an item has been created, updated, or deleted since the provided state. Handles pagination via hasMoreChanges.

Returns a tuple of (ChangeStatus, new_state) where new_state is the latest state from the server that can be used for subsequent operations.

This method is rather inefficient, and not advisable for JMAP-native applications.

§Errors

Returns an error if the server request fails or the response cannot be parsed.

Auto Trait Implementations§

§

impl<C> !Freeze for JmapClient<C>

§

impl<C> !RefUnwindSafe for JmapClient<C>

§

impl<C> Send for JmapClient<C>

§

impl<C> Sync for JmapClient<C>

§

impl<C> Unpin for JmapClient<C>
where C: Unpin,

§

impl<C> UnwindSafe for JmapClient<C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.