modio/request/games/
get_games.rs1use std::future::IntoFuture;
2
3use crate::client::Client;
4use crate::request::{Filter, Output, RequestBuilder, Route};
5use crate::response::ResponseFuture;
6use crate::types::games::Game;
7use crate::types::List;
8use crate::util::{Paginate, Paginator};
9
10pub struct GetGames<'a> {
12 http: &'a Client,
13 show_hidden_tags: Option<bool>,
14 filter: Option<Filter>,
15}
16
17impl<'a> GetGames<'a> {
18 pub(crate) const fn new(http: &'a Client) -> Self {
19 Self {
20 http,
21 show_hidden_tags: None,
22 filter: None,
23 }
24 }
25
26 pub const fn show_hidden_tags(mut self, value: bool) -> Self {
28 self.show_hidden_tags = Some(value);
29 self
30 }
31
32 pub fn filter(mut self, filter: Filter) -> Self {
36 self.filter = Some(filter);
37 self
38 }
39}
40
41impl IntoFuture for GetGames<'_> {
42 type Output = Output<List<Game>>;
43 type IntoFuture = ResponseFuture<List<Game>>;
44
45 fn into_future(self) -> Self::IntoFuture {
46 let route = Route::GetGames {
47 show_hidden_tags: self.show_hidden_tags,
48 };
49 let mut builder = RequestBuilder::from_route(&route);
50 if let Some(filter) = self.filter {
51 builder = builder.filter(filter);
52 }
53 match builder.empty() {
54 Ok(req) => self.http.request(req),
55 Err(err) => ResponseFuture::failed(err),
56 }
57 }
58}
59
60impl<'a> Paginate<'a> for GetGames<'a> {
61 type Output = Game;
62
63 fn paged(&'a self) -> Paginator<'a, Self::Output> {
64 let route = Route::GetGames {
65 show_hidden_tags: self.show_hidden_tags,
66 };
67 Paginator::new(self.http, route, self.filter.clone())
68 }
69}