Skip to main content

notify_core/
output.rs

1use serde::Serialize;
2
3use crate::{MessageFormat, NotifyError, Priority, provider::StoredAttachment};
4
5#[derive(Debug, Serialize)]
6pub struct SendOutput {
7    pub ok: bool,
8    pub channel: String,
9    #[serde(rename = "type")]
10    pub channel_type: String,
11    pub id: String,
12    pub sent: bool,
13    pub dry_run: bool,
14    pub attachments: Vec<StoredAttachment>,
15}
16
17#[derive(Debug, Serialize)]
18pub struct DryRunOutput {
19    pub ok: bool,
20    pub dry_run: bool,
21    pub channel: String,
22    #[serde(rename = "type")]
23    pub channel_type: String,
24    pub message: DryRunMessage,
25    pub attachments: Vec<DryRunAttachment>,
26}
27
28#[derive(Debug, Serialize)]
29pub struct DryRunMessage {
30    pub title: String,
31    pub body: Option<String>,
32    pub format: MessageFormat,
33    pub priority: Priority,
34    pub tags: Vec<String>,
35}
36
37#[derive(Debug, Serialize)]
38pub struct DryRunAttachment {
39    pub path: String,
40}
41
42#[derive(Debug, Serialize)]
43pub struct ErrorOutput {
44    pub ok: bool,
45    pub error: ErrorBody,
46}
47
48#[derive(Debug, Serialize)]
49pub struct ErrorBody {
50    pub code: String,
51    pub message: String,
52}
53
54impl From<&NotifyError> for ErrorOutput {
55    fn from(error: &NotifyError) -> Self {
56        Self {
57            ok: false,
58            error: ErrorBody {
59                code: error.code().to_string(),
60                message: error.to_string(),
61            },
62        }
63    }
64}