twitch_api/helix/endpoints/teams/
get_teams.rs1use super::*;
35use helix::RequestGet;
36
37#[derive(PartialEq, Eq, Deserialize, Serialize, Clone, Debug)]
41#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
42#[must_use]
43#[non_exhaustive]
44pub struct GetTeamsRequest<'a> {
45 #[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
47 #[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
48 pub id: Option<Cow<'a, types::TeamIdRef>>,
49 #[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
51 #[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
52 pub name: Option<Cow<'a, str>>,
53}
54
55impl<'a> GetTeamsRequest<'a> {
56 pub fn id(id: impl types::IntoCow<'a, types::TeamIdRef> + 'a) -> Self {
58 Self {
59 id: Some(id.into_cow()),
60 name: None,
61 }
62 }
63
64 pub fn name(name: impl Into<Cow<'a, str>>) -> Self {
66 Self {
67 id: None,
68 name: Some(name.into()),
69 }
70 }
71}
72
73#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
77#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
78#[non_exhaustive]
79pub struct Team {
80 pub users: Vec<types::User>,
82 #[serde(flatten)]
84 pub team: TeamInformation,
85}
86
87impl Request for GetTeamsRequest<'_> {
88 type Response = Vec<Team>;
89
90 #[cfg(feature = "twitch_oauth2")]
91 const OPT_SCOPE: &'static [twitch_oauth2::Scope] = &[twitch_oauth2::Scope::UserReadEmail];
92 const PATH: &'static str = "teams";
93 #[cfg(feature = "twitch_oauth2")]
94 const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![];
95}
96
97impl RequestGet for GetTeamsRequest<'_> {}
98
99#[cfg(test)]
100#[test]
101fn test_request() {
102 use helix::*;
103 let req = GetTeamsRequest::id("6358");
104
105 let data = br#"
107 {
108 "data": [
109 {
110 "users": [
111 {
112 "user_id": "278217731",
113 "user_name": "mastermndio",
114 "user_login": "mastermndio"
115 },
116 {
117 "user_id": "41284990",
118 "user_name": "jenninexus",
119 "user_login": "jenninexus"
120 }
121 ],
122 "background_image_url": null,
123 "banner": null,
124 "created_at": "2019-02-11T12:09:22Z",
125 "updated_at": "2020-11-18T15:56:41Z",
126 "info": "<p>An outgoing and enthusiastic group of friendly channels that write code, teach about technology, and promote the technical community.</p>",
127 "thumbnail_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/team-livecoders-team_logo_image-bf1d9a87ca81432687de60e24ad9593d-600x600.png",
128 "team_name": "livecoders",
129 "team_display_name": "Live Coders",
130 "id": "6358"
131 }
132 ]
133 }
134"#
135 .to_vec();
136
137 let http_response = http::Response::builder().body(data).unwrap();
138
139 let uri = req.get_uri().unwrap();
140 assert_eq!(uri.to_string(), "https://api.twitch.tv/helix/teams?id=6358");
141
142 dbg!(GetTeamsRequest::parse_response(Some(req), &uri, http_response).unwrap());
143}
144
145#[cfg(test)]
146#[test]
147fn test_no_thumbnail() {
148 use helix::*;
149 let req = GetTeamsRequest::id("10920");
150
151 let data = br#"
153 {
154 "data": [
155 {
156 "background_image_url": null,
157 "banner": null,
158 "created_at": "2021-02-26T15:15:43Z",
159 "id": "10920",
160 "info": "info",
161 "team_display_name": "display",
162 "team_name": "partyanimals",
163 "thumbnail_url": null,
164 "updated_at": "2021-04-19T18:24:48Z",
165 "users": [
166 {
167 "user_id": "103198412",
168 "user_login": "findtherabbit",
169 "user_name": "FindTheRabbit"
170 },
171 {
172 "user_id": "126291224",
173 "user_login": "chri5py",
174 "user_name": "chri5py"
175 }
176 ]
177 }
178 ]
179 }
180"#
181 .to_vec();
182
183 let http_response = http::Response::builder().body(data).unwrap();
184
185 let uri = req.get_uri().unwrap();
186 assert_eq!(
187 uri.to_string(),
188 "https://api.twitch.tv/helix/teams?id=10920"
189 );
190
191 dbg!(GetTeamsRequest::parse_response(Some(req), &uri, http_response).unwrap());
192}