1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
use std::{borrow::Cow, collections::BTreeSet, fmt::Display};
use http::Method;
use serde::{Deserialize, Serialize};
use super::{endpoint::Endpoint, games::GameId, runs::RunEmbeds, Direction, Pageable};
#[derive(Debug, Serialize, Clone, Copy)]
#[serde(rename_all = "kebab-case")]
pub enum UsersSorting {
#[serde(rename = "name.int")]
NameInternational,
#[serde(rename = "name.jap")]
NameJapanese,
Signup,
Role,
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
pub struct UserId<'a>(Cow<'a, str>);
impl<'a> UserId<'a> {
pub fn new<T>(id: T) -> Self
where
T: Into<Cow<'a, str>>,
{
Self(id.into())
}
}
impl<'a, T> From<T> for UserId<'a>
where
T: Into<Cow<'a, str>>,
{
fn from(value: T) -> Self {
Self::new(value)
}
}
impl Display for UserId<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.0)
}
}
#[derive(Default, Debug, Builder, Serialize, Clone)]
#[builder(default, setter(into, strip_option))]
#[serde(rename_all = "kebab-case")]
pub struct Users<'a> {
#[doc = r"Performs a case-insensitive exact-match search for `lookup` across all user names, URLs and social profiles. Cannot be specified with any other filters."]
lookup: Option<Cow<'a, str>>,
#[doc = r"Only return users whose name/URL contain `name`. The comparison is case-insensitive."]
name: Option<Cow<'a, str>>,
#[doc = r"Search Twitch usernames"]
twitch: Option<Cow<'a, str>>,
#[doc = r"Search Hitbox usernames"]
hitbox: Option<Cow<'a, str>>,
#[doc = r"Search Twitter usernames"]
twitter: Option<Cow<'a, str>>,
#[doc = r"Search SpeedRunsLive usernames"]
speedrunslive: Option<Cow<'a, str>>,
#[doc = r"Sorting options for results."]
orderby: Option<UsersSorting>,
#[doc = r"Sort direction."]
direction: Option<Direction>,
}
#[derive(Debug, Builder, Clone)]
#[builder(setter(into, strip_option))]
pub struct User<'a> {
#[doc = r"User ID or username. Using an ID is recommended over a username, because usernames can change."]
id: UserId<'a>,
}
#[derive(Debug, Builder, Serialize, Clone)]
#[builder(setter(into, strip_option))]
#[serde(rename_all = "kebab-case")]
pub struct UserPersonalBests<'a> {
#[doc = r"User ID or username. Using an ID is recommended over a username, because usernames can change."]
#[serde(skip)]
id: UserId<'a>,
#[doc = r"Only return PBs with a place equal or better than `top` (e.g. a value of `1` will return all world records for the given user)"]
#[builder(default)]
top: Option<i64>,
#[doc = r"Series ID or abbreviation. When given, restricts results to that games and romhacks in that series."]
#[builder(default)]
series: Option<Cow<'a, str>>,
#[doc = r"Game ID or abbreviation. When given, restricts results to that game"]
#[builder(default)]
game: Option<GameId<'a>>,
#[builder(setter(name = "_embed"), private, default)]
#[serde(serialize_with = "super::utils::serialize_as_csv")]
#[serde(skip_serializing_if = "BTreeSet::is_empty")]
embed: BTreeSet<RunEmbeds>,
}
impl<'a> Users<'a> {
pub fn builder() -> UsersBuilder<'a> {
UsersBuilder::default()
}
}
impl<'a> User<'a> {
pub fn builder() -> UserBuilder<'a> {
UserBuilder::default()
}
}
impl<'a> UserPersonalBests<'a> {
pub fn builder() -> UserPersonalBestsBuilder<'a> {
UserPersonalBestsBuilder::default()
}
}
impl<'a> UserPersonalBestsBuilder<'a> {
pub fn embed(&mut self, embed: RunEmbeds) -> &mut Self {
self.embed.get_or_insert_with(BTreeSet::new).insert(embed);
self
}
pub fn embeds<I>(&mut self, iter: I) -> &mut Self
where
I: Iterator<Item = RunEmbeds>,
{
self.embed.get_or_insert_with(BTreeSet::new).extend(iter);
self
}
}
impl Default for UsersSorting {
fn default() -> Self {
Self::NameInternational
}
}
impl Endpoint for Users<'_> {
fn method(&self) -> http::Method {
Method::GET
}
fn endpoint(&self) -> Cow<'static, str> {
"/users".into()
}
fn query_parameters(&self) -> Result<Cow<'static, str>, super::error::BodyError> {
Ok(serde_urlencoded::to_string(self)?.into())
}
}
impl Endpoint for User<'_> {
fn method(&self) -> Method {
Method::GET
}
fn endpoint(&self) -> Cow<'static, str> {
format!("/users/{}", self.id).into()
}
}
impl Endpoint for UserPersonalBests<'_> {
fn method(&self) -> Method {
Method::GET
}
fn endpoint(&self) -> Cow<'static, str> {
format!("/users/{}/personal-bests", self.id).into()
}
fn query_parameters(&self) -> Result<Cow<'static, str>, super::error::BodyError> {
Ok(serde_urlencoded::to_string(self)?.into())
}
}
impl Pageable for Users<'_> {}