am_api/resource/
history.rs1use crate::error::Error;
4use crate::primitive::TrackType;
5use crate::request::builder::MusicRequestBuilder;
6use crate::request::paginated::paginate;
7use crate::resource::Resource;
8use crate::ApiClient;
9use futures::Stream;
10
11pub struct History;
13
14impl History {
15 pub fn get<'a>() -> HistoryGetRequestBuilder<'a> {
17 HistoryGetRequestBuilder::default()
18 }
19}
20
21pub struct HistoryRequestBuilder;
23
24pub type HistoryGetRequestBuilder<'a> = MusicRequestBuilder<'a, HistoryRequestBuilder>;
26
27impl<'a> HistoryGetRequestBuilder<'a> {
28 pub async fn heavy_rotation(
38 mut self,
39 client: &ApiClient,
40 limit: usize,
41 offset: usize,
42 ) -> impl Stream<Item = Result<Resource, Error>> {
43 let mut request_context = self.get_request_context_drain(client);
44 request_context
45 .query
46 .push((String::from("limit"), limit.to_string()));
47
48 paginate(
49 client.clone(),
50 String::from("/v1/me/history/heavy-rotation"),
51 request_context,
52 offset,
53 )
54 }
55
56 pub async fn recently_played(
66 mut self,
67 client: &ApiClient,
68 limit: usize,
69 offset: usize,
70 ) -> impl Stream<Item = Result<Resource, Error>> {
71 let mut request_context = self.get_request_context_drain(client);
72 request_context
73 .query
74 .push((String::from("limit"), limit.to_string()));
75
76 paginate(
77 client.clone(),
78 String::from("/v1/me/recent/played"),
79 request_context,
80 offset,
81 )
82 }
83
84 pub async fn recently_played_tracks(
94 mut self,
95 client: &ApiClient,
96 tracks: &[TrackType],
97 limit: usize,
98 offset: usize,
99 ) -> impl Stream<Item = Result<Resource, Error>> {
100 let mut request_context = self.get_request_context_drain(client);
101 request_context
102 .query
103 .push((String::from("limit"), limit.to_string()));
104 request_context.query.push((
105 String::from("types"),
106 tracks
107 .iter()
108 .map(|e| e.to_string())
109 .collect::<Vec<_>>()
110 .join(","),
111 ));
112
113 paginate(
114 client.clone(),
115 String::from("/v1/me/recent/played/tracks"),
116 request_context,
117 offset,
118 )
119 }
120
121 pub async fn recently_played_stations(
131 mut self,
132 client: &ApiClient,
133 limit: usize,
134 offset: usize,
135 ) -> impl Stream<Item = Result<Resource, Error>> {
136 let mut request_context = self.get_request_context_drain(client);
137 request_context
138 .query
139 .push((String::from("limit"), limit.to_string()));
140
141 paginate(
142 client.clone(),
143 String::from("/v1/me/recent/radio-stations"),
144 request_context,
145 offset,
146 )
147 }
148
149 pub async fn recently_added_to_library(
158 mut self,
159 client: &ApiClient,
160 limit: usize,
161 offset: usize,
162 ) -> impl Stream<Item = Result<Resource, Error>> {
163 let mut request_context = self.get_request_context_drain(client);
164 request_context
165 .query
166 .push((String::from("limit"), limit.to_string()));
167
168 paginate(
169 client.clone(),
170 String::from("/v1/me/library/recently-added"),
171 request_context,
172 offset,
173 )
174 }
175}