1use super::{PostMethod, PostQuery, Query};
2use crate::auth::AuthToken;
3use crate::common::{UserChannelID, UserPlaylistsParams, UserVideosParams};
4use crate::parse::{GetUser, UserPlaylist, UserVideo};
5use serde_json::json;
6
7pub struct GetUserQuery<'a> {
8 user_channel_id: UserChannelID<'a>,
9}
10pub struct GetUserPlaylistsQuery<'a> {
11 user_channel_id: UserChannelID<'a>,
12 params: UserPlaylistsParams<'a>,
13}
14pub struct GetUserVideosQuery<'a> {
15 user_channel_id: UserChannelID<'a>,
16 params: UserVideosParams<'a>,
17}
18
19impl<'a> GetUserQuery<'a> {
20 pub fn new(user_channel_id: UserChannelID<'a>) -> Self {
21 Self { user_channel_id }
22 }
23}
24impl<'a> GetUserPlaylistsQuery<'a> {
25 pub fn new(user_channel_id: UserChannelID<'a>, params: UserPlaylistsParams<'a>) -> Self {
26 Self {
27 user_channel_id,
28 params,
29 }
30 }
31}
32impl<'a> GetUserVideosQuery<'a> {
33 pub fn new(user_channel_id: UserChannelID<'a>, params: UserVideosParams<'a>) -> Self {
34 Self {
35 user_channel_id,
36 params,
37 }
38 }
39}
40
41impl<A: AuthToken> Query<A> for GetUserQuery<'_> {
42 type Output = GetUser;
43 type Method = PostMethod;
44}
45impl PostQuery for GetUserQuery<'_> {
46 fn header(&self) -> serde_json::Map<String, serde_json::Value> {
47 FromIterator::from_iter([("browseId".to_string(), json!(self.user_channel_id))])
48 }
49 fn params(&self) -> Vec<(&str, std::borrow::Cow<'_, str>)> {
50 vec![]
51 }
52 fn path(&self) -> &str {
53 "browse"
54 }
55}
56impl<A: AuthToken> Query<A> for GetUserPlaylistsQuery<'_> {
57 type Output = Vec<UserPlaylist>;
58 type Method = PostMethod;
59}
60impl PostQuery for GetUserPlaylistsQuery<'_> {
61 fn header(&self) -> serde_json::Map<String, serde_json::Value> {
62 FromIterator::from_iter([
63 ("browseId".to_string(), json!(self.user_channel_id)),
64 ("params".to_string(), json!(self.params)),
65 ])
66 }
67 fn params(&self) -> Vec<(&str, std::borrow::Cow<'_, str>)> {
68 vec![]
69 }
70 fn path(&self) -> &str {
71 "browse"
72 }
73}
74impl<A: AuthToken> Query<A> for GetUserVideosQuery<'_> {
75 type Output = Vec<UserVideo>;
76 type Method = PostMethod;
77}
78impl PostQuery for GetUserVideosQuery<'_> {
79 fn header(&self) -> serde_json::Map<String, serde_json::Value> {
80 FromIterator::from_iter([
81 ("browseId".to_string(), json!(self.user_channel_id)),
82 ("params".to_string(), json!(self.params)),
83 ])
84 }
85 fn params(&self) -> Vec<(&str, std::borrow::Cow<'_, str>)> {
86 vec![]
87 }
88 fn path(&self) -> &str {
89 "browse"
90 }
91}