twitter_card/
player.rs

1use super::*;
2
3/// Create a player card.
4///
5/// Player cards allow rich media to be embedded on Twitter. This includes, but
6/// is not limited to, audio clips and videos.
7///
8/// [Read more](https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/player-card)
9#[derive(Debug, Clone)]
10pub struct Player {
11  strings: Vec<String>,
12}
13
14impl Player {
15  /// Create a new instance.
16  pub fn builder() -> Self {
17    Self {
18      strings: vec![create_card("summary")],
19    }
20  }
21
22  /// Title of content.
23  ///
24  /// ## Panics.
25  /// Panics if the description is more than 70 characters.
26  #[inline]
27  pub fn title(mut self, content: &str) -> Self {
28    self.strings.push(create_title(content));
29    self
30  }
31
32  /// @username of website. Either twitter:site or twitter:site:id is required.
33  #[inline]
34  pub fn site(mut self, site: &str) -> Self {
35    self.strings.push(create_site(site));
36    self
37  }
38
39  /// Same as twitter:site, but the user’s Twitter ID. Either twitter:site or
40  /// twitter:site:id is required.
41  #[inline]
42  pub fn site_id(mut self, content: &str) -> Self {
43    self.strings.push(create_site_id(content));
44    self
45  }
46
47  /// Twitter user ID of content creator.
48  #[inline]
49  pub fn creator_id(mut self, content: &str) -> Self {
50    self.strings.push(create_creator_id(content));
51    self
52  }
53
54  /// Description of content.
55  ///
56  /// ## Panics.
57  /// Panics if the description is more than 200 characters.
58  #[inline]
59  pub fn desc(mut self, content: &str) -> Self {
60    self.strings.push(create_desc(content));
61    self
62  }
63
64  /// URL of image to use in the card. Images must be less than 5MB in size.
65  /// JPG, PNG, WEBP and GIF formats are supported. Only the first frame of an
66  /// animated GIF will be used. SVG is not supported.
67  #[inline]
68  pub fn image(mut self, content: &str) -> Self {
69    self.strings.push(create_image(content));
70    self
71  }
72
73  /// A text description of the image conveying the essential nature of an image
74  /// to users who are visually impaired. Maximum 420 characters.
75  ///
76  /// ## Panics.
77  /// Panics if the description is more than 420 characters.
78  #[inline]
79  pub fn image_alt(mut self, content: &str) -> Self {
80    self.strings.push(create_image_alt(content));
81    self
82  }
83
84  /// HTTPS URL of player iframe
85  #[inline]
86  pub fn player(mut self, content: &str) -> Self {
87    self.strings.push(create_player(content));
88    self
89  }
90
91  /// Width of iframe in pixels.
92  #[inline]
93  pub fn player_width(mut self, content: &str) -> Self {
94    self.strings.push(create_player_width(content));
95    self
96  }
97
98  /// Height of iframe in pixels.
99  #[inline]
100  pub fn player_height(mut self, content: &str) -> Self {
101    self.strings.push(create_player_height(content));
102    self
103  }
104
105  /// URL to raw video or audio stream.
106  #[inline]
107  pub fn player_stream(mut self, content: &str) -> Self {
108    self.strings.push(create_player_stream(content));
109    self
110  }
111}
112
113impl TwitterCard for Player {
114  #[inline]
115  fn build(self) -> String {
116    self.strings.join("\n")
117  }
118}