push

Struct PushManager

source
pub struct PushManager { /* private fields */ }
Expand description

Object representing the PushManager used to manage subscriptions

The PushManager object is the main interface provided by this crate it allow consumers to manage push subscriptions. It exposes methods that interact with the autopush server and persists state representing subscriptions.

Implementations§

source§

impl PushManager

source

pub fn new(config: PushConfiguration) -> ApiResult<Self>

Creates a new PushManager object, not subscribed to any channels

§Arguments
§Errors

Returns an error in the following cases:

  • PushManager is unable to open the database_path given
  • PushManager is unable to establish a connection to the autopush server
source

pub fn subscribe( &self, scope: &str, server_key: &Option<String>, ) -> ApiResult<SubscriptionResponse>

Subscribes to a new channel and gets the Subscription Info block

§Arguments
  • channel_id - Channel ID (UUID4) for new subscription, either pre-generated or “” and one will be created.
  • scope - Site scope string (defaults to “” for no site scope string).
  • server_key - optional VAPID public key to “lock” subscriptions (defaults to “” for no key)
§Returns

A Subscription response that includes the following:

  • A URL that can be used to deliver push messages
  • A cryptographic key that can be used to encrypt messages that would then be decrypted using the PushManager::decrypt function
§Errors

Returns an error in the following cases:

  • PushManager was unable to access its persisted storage
  • An error occurred sending a subscription request to the autopush server
  • An error occurred generating or deserializing the cryptographic keys
source

pub fn get_subscription( &self, scope: &str, ) -> ApiResult<Option<SubscriptionResponse>>

Retrieves an existing push subscription

§Arguments
  • scope - Site scope string
§Returns

A Subscription response that includes the following:

  • A URL that can be used to deliver push messages
  • A cryptographic key that can be used to encrypt messages that would then be decrypted using the PushManager::decrypt function
§Errors

Returns an error in the following cases:

  • PushManager was unable to access its persisted storage
  • An error occurred generating or deserializing the cryptographic keys
source

pub fn unsubscribe(&self, channel_id: &str) -> ApiResult<bool>

Unsubscribe from given channelID, ending that subscription for the user.

§Arguments
  • channel_id - Channel ID (UUID) for subscription to remove
§Returns

Returns a boolean. Boolean is False if the subscription was already terminated in the past.

§Errors

Returns an error in the following cases:

  • The PushManager does not contain a valid UAID
  • An error occurred sending an unsubscribe request to the autopush server
  • An error occurred accessing the PushManager’s persisted storage
source

pub fn unsubscribe_all(&self) -> ApiResult<()>

Unsubscribe all channels for the user

§Errors

Returns an error in the following cases:

  • The PushManager does not contain a valid UAID
  • An error occurred sending an unsubscribe request to the autopush server
  • An error occurred accessing the PushManager’s persisted storage
source

pub fn update(&self, new_token: &str) -> ApiResult<()>

Updates the Native OS push registration ID.

§Arguments:
  • new_token - the new Native OS push registration ID
§Errors

Return an error in the following cases:

  • The PushManager does not contain a valid UAID
  • An error occurred sending an update request to the autopush server
  • An error occurred accessing the PushManager’s persisted storage
source

pub fn verify_connection( &self, force_verify: bool, ) -> ApiResult<Vec<PushSubscriptionChanged>>

Verifies the connection state

NOTE: This does not resubscribe to any channels it only returns the list of channels that the client should re-subscribe to.

§Arguments
  • force_verify: Force verification and ignore the rate limiter
§Returns

Returns a list of PushSubscriptionChanged indicating the channels the consumer the client should re-subscribe to. If the list is empty, the client’s connection was verified successfully, and the client does not need to resubscribe

§Errors

Return an error in the following cases:

  • The PushManager does not contain a valid UAID
  • An error occurred sending an channel list retrieval request to the autopush server
  • An error occurred accessing the PushManager’s persisted storage
source

pub fn decrypt( &self, payload: HashMap<String, String>, ) -> ApiResult<DecryptResponse>

Decrypts a raw push message.

This accepts the content of a Push Message (from websocket or via Native Push systems).

§Arguments:
  • channel_id - the ChannelID (included in the envelope of the message)
  • body - The encrypted body of the message
  • encoding - The Content Encoding “enc” field of the message (defaults to “aes128gcm”)
  • salt - The “salt” field (if present in the raw message, defaults to “”)
  • dh - The “dh” field (if present in the raw message, defaults to “”)
§Returns

Decrypted message body as a signed byte array they byte array is signed to allow consumers (Kotlin only at the time of this documentation) to work easily with the message. (They can directly call .toByteArray on it)

§Errors

Returns an error in the following cases:

  • The PushManager does not contain a valid UAID
  • There are no records associated with the UAID the PushManager contains
  • An error occurred while decrypting the message
  • An error occurred accessing the PushManager’s persisted storage

Auto Trait Implementations§

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.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
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.
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T