pub struct JmapClient<C>{ /* private fields */ }Expand description
JMAP client for interacting with JMAP servers.
Implementations§
Source§impl<C> JmapClient<C>
impl<C> JmapClient<C>
Sourcepub fn new(client: C, session_url: Uri, api_url: Uri) -> JmapClient<C>
pub fn new(client: C, session_url: Uri, api_url: Uri) -> JmapClient<C>
Create a new JMAP client.
Sourcepub async fn discover_session_url(
client: C,
scheme: Scheme,
domain: String,
) -> Result<Uri, DiscoverError>
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.
Sourcepub fn session_context_url(&self) -> &Uri
pub fn session_context_url(&self) -> &Uri
Returns the URL for the JMAP session resource.
Sourcepub async fn get_session_resource(&self) -> Result<SessionResource>
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.
Sourcepub async fn create_collection<T: RecordType>(
&self,
name: &str,
) -> Result<Record>
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.
Sourcepub async fn create_record<T: RecordType>(
&self,
calendar_id: &str,
record: &JsonValue,
if_state: Option<&str>,
) -> Result<Record>
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.
Sourcepub async fn update_record<T: RecordType>(
&self,
record_id: &str,
calendar_id: &str,
record: &JsonValue,
if_state: Option<&str>,
) -> Result<Record>
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.
Sourcepub async fn delete_collection<T: RecordType>(
&self,
collection_id: &str,
if_state: Option<&str>,
) -> Result<String>
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.
Sourcepub async fn delete_record<T: RecordType>(
&self,
record_id: &str,
if_state: Option<&str>,
) -> Result<String>
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.
Sourcepub async fn get_collections<T>(&self) -> Result<Vec<T>>where
T: RecordType,
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.
Sourcepub async fn get_records<T: RecordType>(
&self,
calendar_id: &str,
) -> Result<Vec<Record>>
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.
Sourcepub async fn changes<T: RecordType>(
&self,
since_state: &str,
max_changes: Option<u32>,
) -> Result<ChangesResponse>
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.
Sourcepub async fn changed_since<T: RecordType>(
&self,
id: &str,
old_state: &str,
) -> Result<(ChangeStatus, String)>
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.