Skip to main content

app_store_server_library/models/
realtime_url_request.rs

1use serde::{Deserialize, Serialize};
2
3const MAXIMUM_REALTIME_URL_LENGTH: usize = 256;
4
5/// The request body for configuring the URL of your Get Retention Message endpoint.
6///
7/// [RealtimeUrlRequest](https://developer.apple.com/documentation/retentionmessaging/realtimeurlrequest)
8#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq)]
9pub struct RealtimeUrlRequest {
10    /// A string that contains the URL of your Get Retention Message endpoint for configuration.
11    ///
12    /// [realtimeURL](https://developer.apple.com/documentation/retentionmessaging/realtimeurl)
13    #[serde(rename = "realtimeURL")]
14    pub realtime_url: String,
15}
16
17impl RealtimeUrlRequest {
18    /// Creates a new `RealtimeUrlRequest`, validating the URL length.
19    ///
20    /// # Errors
21    ///
22    /// Returns `RealtimeUrlRequestValidationError::RealtimeUrlTooLong` if the URL
23    /// exceeds 256 characters.
24    pub fn new(realtime_url: String) -> Result<Self, RealtimeUrlRequestValidationError> {
25        if realtime_url.chars().count() > MAXIMUM_REALTIME_URL_LENGTH {
26            return Err(RealtimeUrlRequestValidationError::RealtimeUrlTooLong);
27        }
28        Ok(Self { realtime_url })
29    }
30}
31
32#[derive(Debug, Clone, PartialEq, Eq)]
33pub enum RealtimeUrlRequestValidationError {
34    RealtimeUrlTooLong,
35}
36
37impl std::fmt::Display for RealtimeUrlRequestValidationError {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        match self {
40            RealtimeUrlRequestValidationError::RealtimeUrlTooLong => write!(
41                f,
42                "Realtime URL exceeds maximum length of {} characters",
43                MAXIMUM_REALTIME_URL_LENGTH
44            ),
45        }
46    }
47}
48
49impl std::error::Error for RealtimeUrlRequestValidationError {}