-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
107 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2022 Yuki Kishimoto | ||
// Distributed under the MIT software license | ||
|
||
pub struct Auth { | ||
username: String, | ||
password: String, | ||
} | ||
|
||
impl Auth { | ||
pub fn new<S>(username: S, password: S) -> Self | ||
where | ||
S: Into<String>, | ||
{ | ||
Self { | ||
username: username.into(), | ||
password: password.into(), | ||
} | ||
} | ||
|
||
pub fn as_base64(&self) -> String { | ||
base64::encode(format!("{}:{}", self.username, self.password)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2022 Yuki Kishimoto | ||
// Distributed under the MIT software license | ||
|
||
use crate::priority::{self, Priority}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Payload { | ||
pub topic: String, | ||
pub message: String, | ||
#[serde(with = "priority")] | ||
pub priority: Priority, | ||
pub title: Option<String>, | ||
} | ||
|
||
impl Payload { | ||
/// Create new payload | ||
pub fn new(topic: &str, message: &str) -> Self { | ||
Self { | ||
topic: topic.into(), | ||
message: message.into(), | ||
priority: Priority::default(), | ||
title: None, | ||
} | ||
} | ||
|
||
/// Set priority | ||
pub fn priority(self, priority: Priority) -> Self { | ||
Self { priority, ..self } | ||
} | ||
|
||
/// Set title | ||
pub fn title(self, title: &str) -> Self { | ||
Self { | ||
title: Some(title.into()), | ||
..self | ||
} | ||
} | ||
} |