Skip to content

Commit

Permalink
feat: reorganize exports and expose necessary stuff from lib.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanjpg committed Jan 22, 2024
1 parent 069246e commit a4dc115
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion examples/simple_sender.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// cargo run --example simple_sender -- -t <device_token>

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]
Expand Down
4 changes: 2 additions & 2 deletions src/android/android_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/android/android_fcm_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions src/android/android_notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/android/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/android/light_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/apns/apns_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value>,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/apns/apns_fcm_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

Expand All @@ -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,
Expand Down
22 changes: 19 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
4 changes: 2 additions & 2 deletions src/message/fcm_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down
9 changes: 5 additions & 4 deletions src/message/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod fcm_options;
pub mod target;

#[cfg(test)]
mod tests;

Expand All @@ -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<S>(target: &Target, s: S) -> Result<S::Ok, S::Error>
Expand All @@ -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<Value>,
Expand Down Expand Up @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion src/message/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{notification::Notification, target::Target, Message};
use crate::{message::Target, notification::Notification, Message};
use serde_json::json;

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/notification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/web/webpush_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value>,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/web/webpush_fcm_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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,
Expand Down

0 comments on commit a4dc115

Please sign in to comment.