Skip to main content

uni_sdk/
services.rs

1use serde::Serialize;
2
3use crate::{
4    SendMessageData, SendMessageRequest, SendOtpRequest, UniClient, UniMessage, UniResponse,
5    VerifyOtpData, VerifyOtpRequest,
6};
7
8#[derive(Clone, Copy)]
9/// Asynchronous SMS message operations.
10pub struct MessageService<'a> {
11    client: &'a UniClient,
12}
13
14impl<'a> MessageService<'a> {
15    pub(crate) fn new(client: &'a UniClient) -> Self {
16        Self { client }
17    }
18
19    /// Sends an SMS message.
20    pub async fn send(
21        &self,
22        params: &SendMessageRequest,
23    ) -> crate::Result<UniResponse<SendMessageData>> {
24        self.client.request("sms.message.send", params).await
25    }
26
27    /// Sends a custom serializable payload and returns custom response data.
28    pub async fn send_with<T, P>(&self, params: &P) -> crate::Result<UniResponse<T>>
29    where
30        T: serde::de::DeserializeOwned,
31        P: Serialize + ?Sized,
32    {
33        self.client.request("sms.message.send", params).await
34    }
35}
36
37#[derive(Clone, Copy)]
38/// Asynchronous one-time passcode operations.
39pub struct OtpService<'a> {
40    client: &'a UniClient,
41}
42
43impl<'a> OtpService<'a> {
44    pub(crate) fn new(client: &'a UniClient) -> Self {
45        Self { client }
46    }
47
48    /// Sends a one-time passcode.
49    pub async fn send(&self, params: &SendOtpRequest) -> crate::Result<UniResponse<UniMessage>> {
50        self.client.request("otp.send", params).await
51    }
52
53    /// Verifies a one-time passcode.
54    pub async fn verify(
55        &self,
56        params: &VerifyOtpRequest,
57    ) -> crate::Result<UniResponse<VerifyOtpData>> {
58        self.client.request("otp.verify", params).await
59    }
60}