rtdlib/types/
web_page.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Describes a web page preview
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct WebPage {
12  #[doc(hidden)]
13  #[serde(rename(serialize = "@type", deserialize = "@type"))]
14  td_name: String,
15  #[doc(hidden)]
16  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
17  extra: Option<String>,
18  /// Original URL of the link
19  url: String,
20  /// URL to display
21  display_url: String,
22  /// Type of the web page. Can be: article, photo, audio, video, document, profile, app, or something else
23  #[serde(rename(serialize = "type", deserialize = "type"))] type_: String,
24  /// Short name of the site (e.g., Google Docs, App Store)
25  site_name: String,
26  /// Title of the content
27  title: String,
28  /// Describes a web page preview
29  description: FormattedText,
30  /// Image representing the content; may be null
31  photo: Option<Photo>,
32  /// URL to show in the embedded preview
33  embed_url: String,
34  /// MIME type of the embedded preview, (e.g., text/html or video/mp4)
35  embed_type: String,
36  /// Width of the embedded preview
37  embed_width: i64,
38  /// Height of the embedded preview
39  embed_height: i64,
40  /// Duration of the content, in seconds
41  duration: i64,
42  /// Author of the content
43  author: String,
44  /// Preview of the content as an animation, if available; may be null
45  animation: Option<Animation>,
46  /// Preview of the content as an audio file, if available; may be null
47  audio: Option<Audio>,
48  /// Preview of the content as a document, if available; may be null
49  document: Option<Document>,
50  /// Preview of the content as a sticker for small WEBP files, if available; may be null
51  sticker: Option<Sticker>,
52  /// Preview of the content as a video, if available; may be null
53  video: Option<Video>,
54  /// Preview of the content as a video note, if available; may be null
55  video_note: Option<VideoNote>,
56  /// Preview of the content as a voice note, if available; may be null
57  voice_note: Option<VoiceNote>,
58  /// Version of instant view, available for the web page (currently, can be 1 or 2), 0 if none
59  instant_view_version: i64,
60  
61}
62
63impl RObject for WebPage {
64  #[doc(hidden)] fn td_name(&self) -> &'static str { "webPage" }
65  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
66  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
67}
68
69
70
71impl WebPage {
72  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
73  pub fn builder() -> RTDWebPageBuilder {
74    let mut inner = WebPage::default();
75    inner.td_name = "webPage".to_string();
76    inner.extra = Some(Uuid::new_v4().to_string());
77    RTDWebPageBuilder { inner }
78  }
79
80  pub fn url(&self) -> &String { &self.url }
81
82  pub fn display_url(&self) -> &String { &self.display_url }
83
84  pub fn type_(&self) -> &String { &self.type_ }
85
86  pub fn site_name(&self) -> &String { &self.site_name }
87
88  pub fn title(&self) -> &String { &self.title }
89
90  pub fn description(&self) -> &FormattedText { &self.description }
91
92  pub fn photo(&self) -> &Option<Photo> { &self.photo }
93
94  pub fn embed_url(&self) -> &String { &self.embed_url }
95
96  pub fn embed_type(&self) -> &String { &self.embed_type }
97
98  pub fn embed_width(&self) -> i64 { self.embed_width }
99
100  pub fn embed_height(&self) -> i64 { self.embed_height }
101
102  pub fn duration(&self) -> i64 { self.duration }
103
104  pub fn author(&self) -> &String { &self.author }
105
106  pub fn animation(&self) -> &Option<Animation> { &self.animation }
107
108  pub fn audio(&self) -> &Option<Audio> { &self.audio }
109
110  pub fn document(&self) -> &Option<Document> { &self.document }
111
112  pub fn sticker(&self) -> &Option<Sticker> { &self.sticker }
113
114  pub fn video(&self) -> &Option<Video> { &self.video }
115
116  pub fn video_note(&self) -> &Option<VideoNote> { &self.video_note }
117
118  pub fn voice_note(&self) -> &Option<VoiceNote> { &self.voice_note }
119
120  pub fn instant_view_version(&self) -> i64 { self.instant_view_version }
121
122}
123
124#[doc(hidden)]
125pub struct RTDWebPageBuilder {
126  inner: WebPage
127}
128
129impl RTDWebPageBuilder {
130  pub fn build(&self) -> WebPage { self.inner.clone() }
131
132   
133  pub fn url<T: AsRef<str>>(&mut self, url: T) -> &mut Self {
134    self.inner.url = url.as_ref().to_string();
135    self
136  }
137
138   
139  pub fn display_url<T: AsRef<str>>(&mut self, display_url: T) -> &mut Self {
140    self.inner.display_url = display_url.as_ref().to_string();
141    self
142  }
143
144   
145  pub fn type_<T: AsRef<str>>(&mut self, type_: T) -> &mut Self {
146    self.inner.type_ = type_.as_ref().to_string();
147    self
148  }
149
150   
151  pub fn site_name<T: AsRef<str>>(&mut self, site_name: T) -> &mut Self {
152    self.inner.site_name = site_name.as_ref().to_string();
153    self
154  }
155
156   
157  pub fn title<T: AsRef<str>>(&mut self, title: T) -> &mut Self {
158    self.inner.title = title.as_ref().to_string();
159    self
160  }
161
162   
163  pub fn description<T: AsRef<FormattedText>>(&mut self, description: T) -> &mut Self {
164    self.inner.description = description.as_ref().clone();
165    self
166  }
167
168   
169  pub fn photo<T: AsRef<Photo>>(&mut self, photo: T) -> &mut Self {
170    self.inner.photo = Some(photo.as_ref().clone());
171    self
172  }
173
174   
175  pub fn embed_url<T: AsRef<str>>(&mut self, embed_url: T) -> &mut Self {
176    self.inner.embed_url = embed_url.as_ref().to_string();
177    self
178  }
179
180   
181  pub fn embed_type<T: AsRef<str>>(&mut self, embed_type: T) -> &mut Self {
182    self.inner.embed_type = embed_type.as_ref().to_string();
183    self
184  }
185
186   
187  pub fn embed_width(&mut self, embed_width: i64) -> &mut Self {
188    self.inner.embed_width = embed_width;
189    self
190  }
191
192   
193  pub fn embed_height(&mut self, embed_height: i64) -> &mut Self {
194    self.inner.embed_height = embed_height;
195    self
196  }
197
198   
199  pub fn duration(&mut self, duration: i64) -> &mut Self {
200    self.inner.duration = duration;
201    self
202  }
203
204   
205  pub fn author<T: AsRef<str>>(&mut self, author: T) -> &mut Self {
206    self.inner.author = author.as_ref().to_string();
207    self
208  }
209
210   
211  pub fn animation<T: AsRef<Animation>>(&mut self, animation: T) -> &mut Self {
212    self.inner.animation = Some(animation.as_ref().clone());
213    self
214  }
215
216   
217  pub fn audio<T: AsRef<Audio>>(&mut self, audio: T) -> &mut Self {
218    self.inner.audio = Some(audio.as_ref().clone());
219    self
220  }
221
222   
223  pub fn document<T: AsRef<Document>>(&mut self, document: T) -> &mut Self {
224    self.inner.document = Some(document.as_ref().clone());
225    self
226  }
227
228   
229  pub fn sticker<T: AsRef<Sticker>>(&mut self, sticker: T) -> &mut Self {
230    self.inner.sticker = Some(sticker.as_ref().clone());
231    self
232  }
233
234   
235  pub fn video<T: AsRef<Video>>(&mut self, video: T) -> &mut Self {
236    self.inner.video = Some(video.as_ref().clone());
237    self
238  }
239
240   
241  pub fn video_note<T: AsRef<VideoNote>>(&mut self, video_note: T) -> &mut Self {
242    self.inner.video_note = Some(video_note.as_ref().clone());
243    self
244  }
245
246   
247  pub fn voice_note<T: AsRef<VoiceNote>>(&mut self, voice_note: T) -> &mut Self {
248    self.inner.voice_note = Some(voice_note.as_ref().clone());
249    self
250  }
251
252   
253  pub fn instant_view_version(&mut self, instant_view_version: i64) -> &mut Self {
254    self.inner.instant_view_version = instant_view_version;
255    self
256  }
257
258}
259
260impl AsRef<WebPage> for WebPage {
261  fn as_ref(&self) -> &WebPage { self }
262}
263
264impl AsRef<WebPage> for RTDWebPageBuilder {
265  fn as_ref(&self) -> &WebPage { &self.inner }
266}
267
268
269