diff --git a/examples/simple_sender.rs b/examples/simple_sender.rs index fb7cedc28..934b24e99 100644 --- a/examples/simple_sender.rs +++ b/examples/simple_sender.rs @@ -1,7 +1,7 @@ // cargo run --example simple_sender -- -t use argparse::{ArgumentParser, Store}; -use fcm::{fcm_options::FcmOptions, target::Target, Client, Message, Notification}; +use fcm::{Client, FcmOptions, Message, Notification, Target}; use serde_json::json; #[tokio::main] diff --git a/src/android/android_config.rs b/src/android/android_config.rs index 800a840e5..de9c213ef 100644 --- a/src/android/android_config.rs +++ b/src/android/android_config.rs @@ -9,7 +9,7 @@ use super::{ #[derive(Serialize, Debug)] //https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#androidconfig -pub struct AndroidConfigInternal { +pub(crate) struct AndroidConfigInternal { // An identifier of a group of messages that can be collapsed, so that only the last message gets // sent when delivery can be resumed. #[serde(skip_serializing_if = "Option::is_none")] @@ -58,7 +58,7 @@ pub struct AndroidConfig { } impl AndroidConfig { - pub fn finalize(self) -> AndroidConfigInternal { + pub(crate) fn finalize(self) -> AndroidConfigInternal { AndroidConfigInternal { collapse_key: self.collapse_key, priority: self.priority, diff --git a/src/android/android_fcm_options.rs b/src/android/android_fcm_options.rs index 81a32de7a..830e12b56 100644 --- a/src/android/android_fcm_options.rs +++ b/src/android/android_fcm_options.rs @@ -2,7 +2,7 @@ use serde::Serialize; #[derive(Serialize, Debug)] //https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#androidconfig -pub struct AndroidFcmOptionsInternal { +pub(crate) struct AndroidFcmOptionsInternal { // Label associated with the message's analytics data. analytics_label: String, } @@ -13,7 +13,7 @@ pub struct AndroidFcmOptions { } impl AndroidFcmOptions { - pub fn finalize(self) -> AndroidFcmOptionsInternal { + pub(crate) fn finalize(self) -> AndroidFcmOptionsInternal { AndroidFcmOptionsInternal { analytics_label: self.analytics_label, } diff --git a/src/android/android_notification.rs b/src/android/android_notification.rs index 0656c13fe..7bf4546be 100644 --- a/src/android/android_notification.rs +++ b/src/android/android_notification.rs @@ -8,7 +8,7 @@ use super::{ #[derive(Serialize, Debug)] // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#androidnotification -pub struct AndroidNotificationInternal { +pub(crate) struct AndroidNotificationInternal { // The notification's title. #[serde(skip_serializing_if = "Option::is_none")] title: Option, @@ -202,7 +202,7 @@ pub struct AndroidNotification { } impl AndroidNotification { - pub fn finalize(self) -> AndroidNotificationInternal { + pub(crate) fn finalize(self) -> AndroidNotificationInternal { AndroidNotificationInternal { title: self.title, body: self.body, diff --git a/src/android/color.rs b/src/android/color.rs index 9520607f3..d9096cab3 100644 --- a/src/android/color.rs +++ b/src/android/color.rs @@ -2,7 +2,7 @@ use serde::Serialize; #[derive(Serialize, Debug)] // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#Color -pub struct ColorInternal { +pub(crate) struct ColorInternal { // The amount of red in the color as a value in the interval [0, 1]. red: f32, @@ -32,7 +32,7 @@ pub struct Color { } impl Color { - pub fn finalize(self) -> ColorInternal { + pub(crate) fn finalize(self) -> ColorInternal { ColorInternal { red: self.red, green: self.green, diff --git a/src/android/light_settings.rs b/src/android/light_settings.rs index 43cd7b01b..0b991b312 100644 --- a/src/android/light_settings.rs +++ b/src/android/light_settings.rs @@ -4,7 +4,7 @@ use super::color::{Color, ColorInternal}; #[derive(Serialize, Debug)] // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#LightSettings -pub struct LightSettingsInternal { +pub(crate) struct LightSettingsInternal { // Set color of the LED with google.type.Color. color: ColorInternal, @@ -33,7 +33,7 @@ pub struct LightSettings { } impl LightSettings { - pub fn finalize(self) -> LightSettingsInternal { + pub(crate) fn finalize(self) -> LightSettingsInternal { LightSettingsInternal { color: self.color.finalize(), light_on_duration: self.light_on_duration, diff --git a/src/apns/apns_config.rs b/src/apns/apns_config.rs index 6d2b6b8e8..294ed670b 100644 --- a/src/apns/apns_config.rs +++ b/src/apns/apns_config.rs @@ -5,7 +5,7 @@ use super::apns_fcm_options::{ApnsFcmOptions, ApnsFcmOptionsInternal}; #[derive(Serialize, Debug)] // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#apnsconfig -pub struct ApnsConfigInternal { +pub(crate) struct ApnsConfigInternal { // HTTP request headers defined in Apple Push Notification Service. #[serde(skip_serializing_if = "Option::is_none")] headers: Option, @@ -27,7 +27,7 @@ pub struct ApnsConfig { } impl ApnsConfig { - pub fn finalize(self) -> ApnsConfigInternal { + pub(crate) fn finalize(self) -> ApnsConfigInternal { ApnsConfigInternal { headers: self.headers, payload: self.payload, diff --git a/src/apns/apns_fcm_options.rs b/src/apns/apns_fcm_options.rs index 841fa6412..c680eaceb 100644 --- a/src/apns/apns_fcm_options.rs +++ b/src/apns/apns_fcm_options.rs @@ -2,7 +2,7 @@ use serde::Serialize; #[derive(Serialize, Debug)] // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#apnsfcmoptions -pub struct ApnsFcmOptionsInternal { +pub(crate) struct ApnsFcmOptionsInternal { // Label associated with the message's analytics data. analytics_label: Option, @@ -20,7 +20,7 @@ pub struct ApnsFcmOptions { } impl ApnsFcmOptions { - pub fn finalize(self) -> ApnsFcmOptionsInternal { + pub(crate) fn finalize(self) -> ApnsFcmOptionsInternal { ApnsFcmOptionsInternal { analytics_label: self.analytics_label, image: self.image, diff --git a/src/lib.rs b/src/lib.rs index 58461c143..5a6247968 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,15 +61,31 @@ //! ``` mod message; +pub use crate::message::fcm_options::*; +pub use crate::message::target::*; pub use crate::message::*; mod notification; pub use crate::notification::*; + mod android; +pub use crate::android::android_config::*; +pub use crate::android::android_fcm_options::*; +pub use crate::android::android_message_priority::*; +pub use crate::android::android_notification::*; +pub use crate::android::color::*; +pub use crate::android::light_settings::*; +pub use crate::android::notification_priority::*; +pub use crate::android::visibility::*; + mod apns; -mod client; -mod web; +pub use crate::apns::apns_config::*; +pub use crate::apns::apns_fcm_options::*; -pub use crate::client::*; +mod web; +pub use crate::web::webpush_config::*; +pub use crate::web::webpush_fcm_options::*; +mod client; pub use crate::client::response::FcmError as Error; +pub use crate::client::*; diff --git a/src/message/fcm_options.rs b/src/message/fcm_options.rs index 8aa0cc7dc..0b26aeb47 100644 --- a/src/message/fcm_options.rs +++ b/src/message/fcm_options.rs @@ -2,7 +2,7 @@ use serde::Serialize; #[derive(Serialize, Debug)] // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#fcmoptions -pub struct FcmOptionsInternal { +pub(crate) struct FcmOptionsInternal { // Label associated with the message's analytics data. analytics_label: String, } @@ -13,7 +13,7 @@ pub struct FcmOptions { } impl FcmOptions { - pub fn finalize(self) -> FcmOptionsInternal { + pub(crate) fn finalize(self) -> FcmOptionsInternal { FcmOptionsInternal { analytics_label: self.analytics_label, } diff --git a/src/message/mod.rs b/src/message/mod.rs index 9abb1bcaf..a3a2801fd 100644 --- a/src/message/mod.rs +++ b/src/message/mod.rs @@ -1,5 +1,6 @@ pub mod fcm_options; pub mod target; + #[cfg(test)] mod tests; @@ -12,13 +13,13 @@ use crate::android::android_config::AndroidConfig; use crate::android::android_config::AndroidConfigInternal; use crate::apns::apns_config::ApnsConfig; use crate::apns::apns_config::ApnsConfigInternal; -use crate::fcm_options::FcmOptions; -use crate::fcm_options::FcmOptionsInternal; use crate::notification::Notification; use crate::notification::NotificationInternal; use crate::web::webpush_config::WebpushConfig; use crate::web::webpush_config::WebpushConfigInternal; +use self::fcm_options::FcmOptions; +use self::fcm_options::FcmOptionsInternal; use self::target::Target; fn output_target(target: &Target, s: S) -> Result @@ -36,7 +37,7 @@ where #[derive(Serialize, Debug)] // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#resource:-message -pub struct MessageInternal { +pub(crate) struct MessageInternal { // Arbitrary key/value payload, which must be UTF-8 encoded. #[serde(skip_serializing_if = "Option::is_none")] data: Option, @@ -91,7 +92,7 @@ pub struct Message { impl Message { /// Complete the build and get a `Message` instance - pub fn finalize(self) -> MessageInternal { + pub(crate) fn finalize(self) -> MessageInternal { MessageInternal { data: self.data, notification: self.notification.map(|n| n.finalize()), diff --git a/src/message/tests.rs b/src/message/tests.rs index 0773b3433..143ec9edc 100644 --- a/src/message/tests.rs +++ b/src/message/tests.rs @@ -1,4 +1,4 @@ -use crate::{notification::Notification, target::Target, Message}; +use crate::{message::Target, notification::Notification, Message}; use serde_json::json; #[test] diff --git a/src/notification/mod.rs b/src/notification/mod.rs index 7be580c22..e61441d6e 100644 --- a/src/notification/mod.rs +++ b/src/notification/mod.rs @@ -8,7 +8,7 @@ use serde::Serialize; /// this notification instance when sending a FCM message. #[derive(Serialize, Debug, PartialEq)] // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#notification -pub struct NotificationInternal { +pub(crate) struct NotificationInternal { // The notification's title. #[serde(skip_serializing_if = "Option::is_none")] title: Option, @@ -43,7 +43,7 @@ pub struct Notification { impl Notification { /// Complete the build and get a `Notification` instance - pub fn finalize(self) -> NotificationInternal { + pub(crate) fn finalize(self) -> NotificationInternal { NotificationInternal { title: self.title, body: self.body, diff --git a/src/web/webpush_config.rs b/src/web/webpush_config.rs index e78bfd345..1486518d8 100644 --- a/src/web/webpush_config.rs +++ b/src/web/webpush_config.rs @@ -5,7 +5,7 @@ use super::webpush_fcm_options::{WebpushFcmOptions, WebpushFcmOptionsInternal}; #[derive(Serialize, Debug)] // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#webpushconfig -pub struct WebpushConfigInternal { +pub(crate) struct WebpushConfigInternal { // HTTP headers defined in webpush protocol. #[serde(skip_serializing_if = "Option::is_none")] headers: Option, @@ -33,7 +33,7 @@ pub struct WebpushConfig { } impl WebpushConfig { - pub fn finalize(self) -> WebpushConfigInternal { + pub(crate) fn finalize(self) -> WebpushConfigInternal { WebpushConfigInternal { headers: self.headers, data: self.data, diff --git a/src/web/webpush_fcm_options.rs b/src/web/webpush_fcm_options.rs index 45b78c673..b9b239549 100644 --- a/src/web/webpush_fcm_options.rs +++ b/src/web/webpush_fcm_options.rs @@ -2,7 +2,7 @@ use serde::Serialize; #[derive(Serialize, Debug)] // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#webpushfcmoptions -pub struct WebpushFcmOptionsInternal { +pub(crate) struct WebpushFcmOptionsInternal { // The link to open when the user clicks on the notification. link: String, @@ -21,7 +21,7 @@ pub struct WebpushFcmOptions { } impl WebpushFcmOptions { - pub fn finalize(self) -> WebpushFcmOptionsInternal { + pub(crate) fn finalize(self) -> WebpushFcmOptionsInternal { WebpushFcmOptionsInternal { link: self.link, analytics_label: self.analytics_label,