pub struct FcmService {
pub credential_file: String,
}Fields§
§credential_file: StringImplementations§
Source§impl FcmService
Service for sending Firebase Cloud Messaging (FCM) notifications using the v1 API.
impl FcmService
Service for sending Firebase Cloud Messaging (FCM) notifications using the v1 API.
This service uses a Google Cloud service account credential file to authenticate and send notifications to FCM.
§Examples
use fcm_service::{FcmService, FcmMessage, FcmNotification, Target};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let service = FcmService::new("path/to/service-account.json");
let mut message = FcmMessage::new();
let mut notification = FcmNotification::new();
notification.set_title("Hello".to_string());
notification.set_body("World".to_string());
notification.set_image(None);
message.set_notification(Some(notification));
message.set_target(Target::Token("device-token".to_string()));
service.send_notification(message).await?;
Ok(())
}Sourcepub async fn send_notification(
&self,
message: FcmMessage,
) -> Result<(), Box<dyn Error>>
pub async fn send_notification( &self, message: FcmMessage, ) -> Result<(), Box<dyn Error>>
Sends an FCM notification asynchronously.
§Errors
Returns an error if:
- The credential file cannot be read or parsed
- Authentication with GCP fails
- The HTTP request to FCM fails
- The FCM API returns an unsuccessful status
Auto Trait Implementations§
impl Freeze for FcmService
impl RefUnwindSafe for FcmService
impl Send for FcmService
impl Sync for FcmService
impl Unpin for FcmService
impl UnwindSafe for FcmService
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
Mutably borrows from an owned value. Read more