Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:rj76/fcm-rust into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rj76 committed Jan 4, 2024
2 parents 6561079 + 09aa86e commit 1850ef5
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 41 deletions.
10 changes: 5 additions & 5 deletions src/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct AndroidConfig {

// If set to true, messages will be allowed to be delivered to the app while the device is in direct boot mode.
#[serde(skip_serializing_if = "Option::is_none")]
direct_boot_ok: Option<bool>
direct_boot_ok: Option<bool>,
}

#[derive(Serialize, Debug)]
Expand All @@ -52,7 +52,7 @@ pub struct Color {
blue: f32,

// The fraction of this color that should be applied to the pixel.
alpha: f32
alpha: f32,
}

#[derive(Serialize, Debug)]
Expand Down Expand Up @@ -184,7 +184,7 @@ pub struct AndroidNotification {
//https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#androidconfig
pub struct AndroidFcmOptions {
// Label associated with the message's analytics data.
analytics_label: String
analytics_label: String,
}

#[allow(dead_code)]
Expand All @@ -206,7 +206,7 @@ pub enum NotificationPriority {
PriorityLow,
PriorityDefault,
PriorityHigh,
PriorityMax
PriorityMax,
}

Check warning on line 210 in src/android/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

all variants have the same prefix: `Priority`

warning: all variants have the same prefix: `Priority` --> src/android/mod.rs:203:1 | 203 | / pub enum NotificationPriority { 204 | | PriorityUnspecified, 205 | | PriorityMin, 206 | | PriorityLow, ... | 209 | | PriorityMax, 210 | | } | |_^ | = help: remove the prefixes and use full paths to the variants instead of glob imports = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names = note: `#[warn(clippy::enum_variant_names)]` on by default

#[allow(dead_code)]
Expand All @@ -217,5 +217,5 @@ pub enum Visibility {
VisibilityUnspecified,

Check warning on line 217 in src/android/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variant name starts with the enum's name

warning: variant name starts with the enum's name --> src/android/mod.rs:217:5 | 217 | VisibilityUnspecified, | ^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names
Private,
Public,
Secret
Secret,
}
2 changes: 1 addition & 1 deletion src/apns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ pub struct ApnsFcmOptions {
analytics_label: String,

// Contains the URL of an image that is going to be displayed in a notification.
image: String
image: String,
}
12 changes: 4 additions & 8 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
pub(crate) mod response;

use gauth::serv_account::ServiceAccount;
use reqwest::{Body, StatusCode};
use reqwest::header::RETRY_AFTER;
use crate::client::response::{ErrorReason, FcmError, FcmResponse, RetryAfter};
use crate::Message;

use gauth::serv_account::ServiceAccount;
use reqwest::header::RETRY_AFTER;
use reqwest::{Body, StatusCode};

/// An async client for sending the notification payload.
pub struct Client {
Expand Down Expand Up @@ -115,10 +114,7 @@ impl Client {
};

// https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send
let url = format!(
"https://fcm.googleapis.com/v1/projects/{}/messages:send",
project_id
);
let url = format!("https://fcm.googleapis.com/v1/projects/{}/messages:send", project_id);

let request = self
.http_client
Expand Down
1 change: 0 additions & 1 deletion src/client/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ pub enum FcmError {
ProjectIdError(String),

AuthToken(String),

}

impl Error for FcmError {}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ mod message;
pub use crate::message::*;
mod notification;
pub use crate::notification::*;
mod client;
mod android;
mod web;
mod apns;
mod client;
mod web;

pub use crate::client::*;

Expand Down
30 changes: 12 additions & 18 deletions src/message/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use serde::{Serialize, Serializer};
use serde_json::Value;
use crate::android::AndroidConfig;
use crate::apns::ApnsConfig;
use crate::Notification;
use crate::web::WebpushConfig;
use crate::Notification;
use serde::{Serialize, Serializer};
use serde_json::Value;

#[cfg(test)]
mod tests;
Expand All @@ -13,23 +13,17 @@ mod tests;
pub enum Target {
Token(String),
Topic(String),
Condition(String)
Condition(String),
}

fn output_target<S>(target: &Target, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer
where
S: Serializer,
{
match target {
Target::Token(token) => {
s.serialize_newtype_struct("token", token.as_str())
},
Target::Topic(topic) => {
s.serialize_newtype_struct("topic", topic.as_str())
},
Target::Condition(condition) => {
s.serialize_newtype_struct("condition", condition.as_str())
},
Target::Token(token) => s.serialize_newtype_struct("token", token.as_str()),
Target::Topic(topic) => s.serialize_newtype_struct("topic", topic.as_str()),
Target::Condition(condition) => s.serialize_newtype_struct("condition", condition.as_str()),
}
}

Expand Down Expand Up @@ -62,7 +56,7 @@ pub struct Message {

// Target to send a message to.
#[serde(serialize_with = "output_target")]
target: Target
target: Target,
}

#[derive(Serialize, Debug)]
Expand All @@ -88,7 +82,7 @@ pub struct FcmOptions {
pub struct MessageBuilder {
data: Option<Value>,
notification: Option<Notification>,
target: Target
target: Target,
}

impl MessageBuilder {
Expand Down Expand Up @@ -150,7 +144,7 @@ impl MessageBuilder {
webpush: None,
apns: None,
fcm_options: None,
target: self.target
target: self.target,
}
}
}
6 changes: 2 additions & 4 deletions src/message/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ struct CustomData {
#[test]
fn should_create_new_message() {
let target = Target::Token("token".to_string());
let msg = MessageBuilder::new(target.clone())
.finalize();
let msg = MessageBuilder::new(target.clone()).finalize();

assert_eq!(msg.target, target);
}
Expand Down Expand Up @@ -61,8 +60,7 @@ fn should_be_able_to_render_a_full_message_to_json() {
let target = Target::Token("token".to_string());
let mut builder = MessageBuilder::new(target);

builder
.notification(NotificationBuilder::new().finalize());
builder.notification(NotificationBuilder::new().finalize());

let payload = serde_json::to_string(&builder.finalize()).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/notification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl NotificationBuilder {
Notification {
title: self.title,
body: self.body,
image: self.image
image: self.image,
}
}
}
2 changes: 1 addition & 1 deletion src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ pub struct WebpushFcmOptions {
link: String,

// Label associated with the message's analytics data.
analytics_label: String
analytics_label: String,
}

0 comments on commit 1850ef5

Please sign in to comment.