tmdb_rs/endpoints/
account.rs1use serde::Deserialize;
2use strum::Display;
3use time::Date;
4
5use crate::common::{MediaType, StatusResponse};
6use crate::endpoints::list::ListShort;
7use crate::endpoints::movie::MovieShort;
8use crate::endpoints::tv::TvShort;
9use crate::{CountryCode, Language, Page, Profile, SessionId, Still};
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Display)]
13pub enum AccountSort {
14 #[strum(serialize = "created_at.asc")]
15 CreatedAtAsc,
16 #[strum(serialize = "created_at.desc")]
17 CreatedAtDesc,
18}
19
20#[derive(Debug, Clone, Deserialize)]
21#[serde(from = "RawAvatar")]
22pub struct Avatar {
23 pub gravatar_hash: String,
24 pub path: Option<Profile>,
25}
26
27#[derive(Deserialize)]
28struct RawAvatar {
29 gravatar: RawGravatar,
30 tmdb: RawTmdbAvatar,
31}
32
33#[derive(Deserialize)]
34struct RawGravatar {
35 hash: String,
36}
37
38#[derive(Deserialize)]
39struct RawTmdbAvatar {
40 avatar_path: Option<Profile>,
41}
42
43impl From<RawAvatar> for Avatar {
44 fn from(raw: RawAvatar) -> Self {
45 Avatar {
46 gravatar_hash: raw.gravatar.hash,
47 path: raw.tmdb.avatar_path,
48 }
49 }
50}
51
52#[derive(Debug, Clone, Deserialize)]
53pub struct AccountDetails {
54 pub id: u64,
55 pub name: String,
56 pub username: String,
57 #[serde(rename = "iso_639_1")]
58 pub language: Language,
59 #[serde(rename = "iso_3166_1")]
60 pub country: CountryCode,
61 pub include_adult: bool,
62 pub avatar: Avatar,
63}
64
65#[derive(Debug, Clone, Deserialize)]
67pub struct RatedEpisode {
68 pub id: u64,
69 pub name: String,
70 pub episode_number: u32,
71 pub season_number: u32,
72 pub show_id: Option<u64>,
73 #[serde(default, deserialize_with = "crate::common::opt_date")]
74 pub air_date: Option<Date>,
75 #[serde(rename = "still_path")]
76 pub still: Option<Still>,
77 pub vote_average: f64,
78 pub rating: f64,
79}
80
81#[derive(Debug, Clone, Deserialize)]
83pub struct AccountWatchProviders {
84 pub id: u64,
85 pub watch_region: Option<String>,
86 pub watch_provider_ids: Vec<u64>,
87}
88
89endpoint! {
90 account(session_id: SessionId): GET "/account" => AccountDetails
92}
93
94endpoint! {
95 favorite_movies(account_id: u64, session_id: SessionId): GET "/account/{account_id}/favorite/movies" => Page<MovieShort> {
97 params { language: Language, page: u32, sort_by: AccountSort }
98 }
99}
100
101endpoint! {
102 favorite_tv(account_id: u64, session_id: SessionId): GET "/account/{account_id}/favorite/tv" => Page<TvShort> {
104 params { language: Language, page: u32, sort_by: AccountSort }
105 }
106}
107
108endpoint! {
109 mark_favorite(account_id: u64, session_id: SessionId): POST "/account/{account_id}/favorite" => StatusResponse {
111 body { media_type: MediaType, media_id: u64, favorite: bool }
112 }
113}
114
115endpoint! {
116 rated_movies(account_id: u64, session_id: SessionId): GET "/account/{account_id}/rated/movies" => Page<MovieShort> {
118 params { language: Language, page: u32, sort_by: AccountSort }
119 }
120}
121
122endpoint! {
123 rated_tv(account_id: u64, session_id: SessionId): GET "/account/{account_id}/rated/tv" => Page<TvShort> {
125 params { language: Language, page: u32, sort_by: AccountSort }
126 }
127}
128
129endpoint! {
130 rated_episodes(account_id: u64, session_id: SessionId): GET "/account/{account_id}/rated/episodes" => Page<RatedEpisode> {
132 params { language: Language, page: u32, sort_by: AccountSort }
133 }
134}
135
136endpoint! {
137 watchlist_movies(account_id: u64, session_id: SessionId): GET "/account/{account_id}/watchlist/movies" => Page<MovieShort> {
139 params { language: Language, page: u32, sort_by: AccountSort }
140 }
141}
142
143endpoint! {
144 watchlist_tv(account_id: u64, session_id: SessionId): GET "/account/{account_id}/watchlist/tv" => Page<TvShort> {
146 params { language: Language, page: u32, sort_by: AccountSort }
147 }
148}
149
150endpoint! {
151 set_watchlist(account_id: u64, session_id: SessionId): POST "/account/{account_id}/watchlist" => StatusResponse {
153 body { media_type: MediaType, media_id: u64, watchlist: bool }
154 }
155}
156
157endpoint! {
158 account_lists(account_id: u64, session_id: SessionId): GET "/account/{account_id}/lists" => Page<ListShort> {
160 params { language: Language, page: u32 }
161 }
162}
163
164endpoint! {
165 account_watch_providers(session_id: SessionId): GET "/account/watch/providers" => AccountWatchProviders {
167 params { watch_region: CountryCode }
168 }
169}