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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! A model for news streams.
use crate::{
client::{error::RspErr, param::news_stream::ToNewsStreamParam, Client},
model::{news::NewsItems, prelude::*, response::Response},
};
/// A news stream.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub struct NewsStream(String);
impl NewsStream {
/// Gets the latest news items in the stream.
/// Calls the [`Client::get_news_latest`](crate::client::Client::get_news_latest) method.
///
/// # Arguments
///
/// - `limit` - The amount of entries to return, between 1 and 100.
///
/// # Panics
///
/// Panics if the argument `limit` is not between 1 and 100.
///
/// # Errors
///
/// - A [`ResponseError::RequestErr`](crate::client::error::ResponseError::RequestErr) is returned,
/// if the request failed.
/// - A [`ResponseError::DeserializeErr`](crate::client::error::ResponseError::DeserializeErr) is returned,
/// if the response did not match the expected format but the HTTP request succeeded.
/// There may be defectives in this wrapper or the TETRA CHANNEL API document.
/// - A [`ResponseError::HttpErr`](crate::client::error::ResponseError::HttpErr) is returned,
/// if the HTTP request failed and the response did not match the expected format.
/// Even if the HTTP request failed,
/// it may be possible to deserialize the response containing an error message,
/// so the deserialization will be tried before returning this error.
pub async fn get_news_items(self, limit: u8) -> RspErr<Response<NewsItems>> {
Client::new().get_news_latest(self, limit).await
}
/// Whether the stream is the global news stream.
pub fn is_global_steam(&self) -> bool {
self.0 == "global"
}
/// Whether the stream is a news stream of a user.
pub fn is_user_steam(&self) -> bool {
self.0.starts_with("user_")
}
}
impl AsRef<NewsStream> for NewsStream {
fn as_ref(&self) -> &Self {
self
}
}
impl fmt::Display for NewsStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl ToNewsStreamParam for NewsStream {
fn to_param(&self) -> String {
self.0.clone()
}
}