DEVELOPMENT ENVIRONMENT

~liljamo/canwa

ref: 45439cc45439d0050fb8dd130f48993bba82574f canwa/src/service/mod.rs -rw-r--r-- 1.1 KiB
45439cc4Jonni Liljamo feat: initial version 27 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Copyright (C) 2025 Jonni Liljamo <jonni@liljamo.com>
 *
 * This file is licensed under GPL-3.0-or-later, see NOTICE and LICENSE for
 * more information.
 */

use async_trait::async_trait;

use crate::config::ServiceConfig;

pub mod gotify;
pub mod matrix;

#[async_trait]
pub trait Service {
    async fn send(&self, title: &str, message: &str) -> Result<(), Box<dyn std::error::Error>>;
}

pub fn build(
    client: reqwest::Client,
    service_config: &dyn ServiceConfig,
) -> Box<dyn Service + Send + Sync> {
    match service_config.typetag_name() {
        "gotify" => Box::new(gotify::GotifyService::new(
            client,
            service_config
                .as_any()
                .downcast_ref::<gotify::GotifyConfig>()
                .expect("fuck")
                .clone(),
        )),
        "matrix" => Box::new(matrix::MatrixService::new(
            client,
            service_config
                .as_any()
                .downcast_ref::<matrix::MatrixConfig>()
                .expect("fuck")
                .clone(),
        )),
        _ => unreachable!(),
    }
}