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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#[derive(Clone, Default, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct ParticipantId(pub String);
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ParticipantType {
Team,
Single,
}
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct ParticipantLogo {
pub icon_large_square: String,
pub extra_small_square: String,
pub medium_small_square: String,
pub medium_large_square: String,
}
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub enum CustomFieldType {
#[serde(rename = "steam_player_id")]
SteamId,
#[serde(rename = "birth_date")]
Birthdate,
#[serde(rename = "facebook")]
Facebook,
#[serde(rename = "full_name")]
Fullname,
#[serde(rename = "instagram")]
Instagram,
#[serde(rename = "snapchat")]
Snapchat,
#[serde(rename = "text")]
Text,
#[serde(rename = "twitch")]
Twitch,
#[serde(rename = "twitter")]
Twitter,
#[serde(rename = "vimeo")]
Vimeo,
#[serde(rename = "website")]
Website,
#[serde(rename = "youtube")]
Youtube,
}
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct CustomField {
#[serde(rename = "type")]
pub field_type: CustomFieldType,
pub label: String,
pub value: String,
}
#[derive(Clone, Default, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct CustomFields(pub Vec<CustomField>);
#[derive(Clone, Default, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Participant {
pub id: Option<ParticipantId>,
pub name: String,
pub logo: Option<ParticipantLogo>,
pub lineup: Option<Participants>,
pub custom_fields: Option<CustomFields>,
pub country: Option<String>,
pub email: Option<String>,
pub check_in: Option<bool>,
pub custom_fields_private: Option<CustomFields>,
}
#[derive(Clone, Default, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Participants(pub Vec<Participant>);
#[cfg(test)]
mod tests {
use ::serde_json;
use ::{ Participants, CustomFieldType };
#[test]
fn test_participant_parse() {
let s = r#"
[
{
"id": "378426939508809728",
"name": "Evil Geniuses",
"logo": {
"icon_large_square": "http://api.toornament.com/id/icon_large_square",
"extra_small_square": "http://api.toornament.com/id/extra_small_square",
"medium_small_square": "http://api.toornament.com/id/medium_small_square",
"medium_large_square": "http://api.toornament.com/id/medium_large_square"
},
"country": "US",
"lineup": [
{
"name": "Storm Spirit",
"country": "US",
"custom_fields": [
{
"type": "steam_player_id",
"label": "Steam ID",
"value": "STEAM_0:1:1234567"
}
],
"email": "player@oxent.net",
"custom_fields_private": [
{
"type": "steam_player_id",
"label": "Steam ID",
"value": "STEAM_0:1:1234567"
}
]
}
],
"custom_fields": [
{
"type": "steam_player_id",
"label": "Steam ID",
"value": "STEAM_0:1:1234567"
}
],
"email": "contact@oxent.net",
"check_in": true,
"custom_fields_private": [
{
"type": "steam_player_id",
"label": "Steam ID",
"value": "STEAM_0:1:1234567"
}
]
}
]
"#;
let ps: Participants = serde_json::from_str(s).unwrap();
assert_eq!(ps.0.len(), 1);
let p = ps.0.iter().next().unwrap().clone();
assert_eq!(p.id.unwrap().0, "378426939508809728");
assert_eq!(p.name, "Evil Geniuses");
let logo = p.logo.unwrap();
assert_eq!(logo.icon_large_square, "http://api.toornament.com/id/icon_large_square");
assert_eq!(logo.extra_small_square, "http://api.toornament.com/id/extra_small_square");
assert_eq!(logo.medium_small_square, "http://api.toornament.com/id/medium_small_square");
assert_eq!(logo.medium_large_square, "http://api.toornament.com/id/medium_large_square");
assert_eq!(p.country, Some("US".to_owned()));
let lineup = p.lineup.unwrap().0;
assert_eq!(lineup.len(), 1);
let lp = lineup.iter().next().unwrap();
assert!(lp.id.is_none());
assert_eq!(lp.name, "Storm Spirit");
assert_eq!(lp.country, Some("US".to_owned()));
{
let lpcfs = lp.custom_fields.clone().unwrap().0;
assert_eq!(lpcfs.len(), 1);
let lpcf = lpcfs.iter().next().unwrap();
assert_eq!(lpcf.field_type, CustomFieldType::SteamId);
assert_eq!(lpcf.label, "Steam ID");
assert_eq!(lpcf.value, "STEAM_0:1:1234567");
}
assert_eq!(lp.email, Some("player@oxent.net".to_owned()));
{
let lpcfsp = lp.custom_fields_private.clone().unwrap().0;
assert_eq!(lpcfsp.len(), 1);
let lpcfp = lpcfsp.iter().next().unwrap();
assert_eq!(lpcfp.field_type, CustomFieldType::SteamId);
assert_eq!(lpcfp.label, "Steam ID");
assert_eq!(lpcfp.value, "STEAM_0:1:1234567");
}
assert_eq!(p.email, Some("contact@oxent.net".to_owned()));
assert_eq!(p.check_in, Some(true));
{
let pcfs = p.custom_fields.clone().unwrap().0;
assert_eq!(pcfs.len(), 1);
let pcf = pcfs.iter().next().unwrap();
assert_eq!(pcf.field_type, CustomFieldType::SteamId);
assert_eq!(pcf.label, "Steam ID");
assert_eq!(pcf.value, "STEAM_0:1:1234567");
}
{
let pcfsp = p.custom_fields_private.clone().unwrap().0;
assert_eq!(pcfsp.len(), 1);
let pcfp = pcfsp.iter().next().unwrap();
assert_eq!(pcfp.field_type, CustomFieldType::SteamId);
assert_eq!(pcfp.label, "Steam ID");
assert_eq!(pcfp.value, "STEAM_0:1:1234567");
}
}
}