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
impl PushManager
sourcepub fn new(config: PushConfiguration) -> ApiResult<Self>
pub fn new(config: PushConfiguration) -> ApiResult<Self>
Creates a new PushManager
object, not subscribed to any
channels
§Arguments
config
:PushConfiguration
the configuration for this instance of PushManager
§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
sourcepub fn subscribe(
&self,
scope: &str,
server_key: &Option<String>,
) -> ApiResult<SubscriptionResponse>
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
sourcepub fn get_subscription(
&self,
scope: &str,
) -> ApiResult<Option<SubscriptionResponse>>
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
sourcepub fn unsubscribe(&self, channel_id: &str) -> ApiResult<bool>
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
sourcepub fn unsubscribe_all(&self) -> ApiResult<()>
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
sourcepub fn update(&self, new_token: &str) -> ApiResult<()>
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
sourcepub fn verify_connection(
&self,
force_verify: bool,
) -> ApiResult<Vec<PushSubscriptionChanged>>
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
sourcepub fn decrypt(
&self,
payload: HashMap<String, String>,
) -> ApiResult<DecryptResponse>
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 messageencoding
- 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§
impl !Freeze for PushManager
impl RefUnwindSafe for PushManager
impl Send for PushManager
impl Sync for PushManager
impl Unpin for PushManager
impl UnwindSafe for PushManager
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Read more