• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rj76 / fcm-rust / 8128893026

03 Mar 2024 08:21AM UTC coverage: 5.216% (+0.02%) from 5.2%
8128893026

Pull #4

github

web-flow
Merge 2128a958a into a8babd228
Pull Request #4: feat: build new api

621 of 32863 branches covered (1.89%)

Branch coverage included in aggregate %.

108 of 396 new or added lines in 21 files covered. (27.27%)

252 existing lines in 48 files now uncovered.

15129 of 269097 relevant lines covered (5.62%)

202.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.55
/src/message/mod.rs
1
pub mod fcm_options;
2
pub mod target;
3

4
#[cfg(test)]
5
mod tests;
6

7
use serde::ser::SerializeMap;
8
use serde::Serialize;
9
use serde::Serializer;
10
use serde_json::Value;
11

12
use crate::android::android_config::AndroidConfig;
13
use crate::android::android_config::AndroidConfigInternal;
14
use crate::apns::apns_config::ApnsConfig;
15
use crate::apns::apns_config::ApnsConfigInternal;
16
use crate::notification::Notification;
17
use crate::notification::NotificationInternal;
18
use crate::web::webpush_config::WebpushConfig;
19
use crate::web::webpush_config::WebpushConfigInternal;
20

21
use self::fcm_options::FcmOptions;
22
use self::fcm_options::FcmOptionsInternal;
23
use self::target::Target;
24

25
fn output_target<S>(target: &Target, s: S) -> Result<S::Ok, S::Error>
45✔
26
where
15✔
27
    S: Serializer,
15✔
28
{
15✔
29
    let mut map = s.serialize_map(Some(1))?;
45✔
30
    match target {
45!
31
        Target::Token(token) => map.serialize_entry("token", token.as_str())?,
27!
32
        Target::Topic(topic) => map.serialize_entry("topic", topic.as_str())?,
9!
33
        Target::Condition(condition) => map.serialize_entry("condition", condition.as_str())?,
39!
34
    }
35
    map.end()
45✔
36
}
45✔
37

38
#[derive(Serialize, Debug)]
153!
39
/// https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#resource:-message
40
pub(crate) struct MessageInternal {
41
    /// Arbitrary key/value payload, which must be UTF-8 encoded.
42
    #[serde(skip_serializing_if = "Option::is_none")]
43
    data: Option<Value>,
×
44

45
    /// Basic notification template to use across all platforms.
46
    #[serde(skip_serializing_if = "Option::is_none")]
NEW
47
    notification: Option<NotificationInternal>,
×
48

49
    /// Android specific options for messages sent through FCM connection server.
50
    #[serde(skip_serializing_if = "Option::is_none")]
NEW
51
    android: Option<AndroidConfigInternal>,
×
52

53
    /// Webpush protocol options.
54
    #[serde(skip_serializing_if = "Option::is_none")]
NEW
55
    webpush: Option<WebpushConfigInternal>,
×
56

57
    /// Apple Push Notification Service specific options.
58
    #[serde(skip_serializing_if = "Option::is_none")]
NEW
59
    apns: Option<ApnsConfigInternal>,
×
60

61
    /// Template for FCM SDK feature options to use across all platforms.
62
    #[serde(skip_serializing_if = "Option::is_none")]
NEW
63
    fcm_options: Option<FcmOptionsInternal>,
×
64

65
    /// Target to send a message to.
66
    #[serde(flatten, serialize_with = "output_target")]
67
    target: Target,
×
68
}
69

70
/// A `Message` instance is the main object to send to the FCM API.
71
/// https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#resource:-message
72
#[derive(Debug)]
×
73
pub struct Message {
74
    /// Arbitrary key/value payload, which must be UTF-8 encoded.
NEW
75
    pub data: Option<Value>,
×
76
    /// Basic notification template to use across all platforms.
NEW
77
    pub notification: Option<Notification>,
×
78
    /// Android specific options for messages sent through FCM connection server.
79
    pub target: Target,
80
    /// Webpush protocol options.
NEW
81
    pub android: Option<AndroidConfig>,
×
82
    /// Apple Push Notification Service specific options.
NEW
83
    pub webpush: Option<WebpushConfig>,
×
84
    /// Template for FCM SDK feature options to use across all platforms.
NEW
85
    pub apns: Option<ApnsConfig>,
×
86
    /// Target to send a message to.
NEW
87
    pub fcm_options: Option<FcmOptions>,
×
88
}
89

90
impl Message {
91
    /// Complete the build and get a `MessageInternal` instance
92
    pub(crate) fn finalize(self) -> MessageInternal {
63✔
93
        MessageInternal {
63✔
94
            data: self.data,
63✔
95
            notification: self.notification.map(|n| n.finalize()),
129✔
96
            android: self.android.map(|a| a.finalize()),
63✔
97
            webpush: self.webpush.map(|w| w.finalize()),
63✔
98
            apns: self.apns.map(|a| a.finalize()),
63✔
99
            fcm_options: self.fcm_options.map(|f| f.finalize()),
63✔
100
            target: self.target,
63✔
101
        }
21✔
102
    }
63✔
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc