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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
use chrono::{
DateTime,
TimeZone,
Utc
};
use serde::{
Deserialize,
Serialize,
};
use crate::{
enums::*,
event::*,
image::*,
page_info::*,
participant::*,
user::*,
};
/// Equivalent for start.gg TournamentConnection.
#[derive(Clone, Default, Serialize, Deserialize)]
pub struct GGTournamentConnection {
pub nodes: Vec<GGTournament>,
pub page_info: Option<Box<GGPageInfo>>,
}
impl GGTournamentConnection {
/// Returns the page info of the connection.
///
/// Returns empty page info if not set or wasn't queried.
pub fn page_info(&self) -> GGPageInfo {
let mut result: GGPageInfo = Default::default();
if self.page_info.is_some() {
result = *self.page_info.as_ref().unwrap().clone();
}
return result;
}
}
/// Equivalent for start.gg Tournament.
///
/// Each element in the structure is optional, allowing a user to only query values they want.
/// Given each is an option and not a requirement, a method is included for each element with the same name.
/// These methods will unwrap and return the proper value without any unwrapping or references needed.
/// Certain methods (see participants()) will return a vector of the data type instead of a connection to a vector, done to simplify the API and make the start.gg api easier to work with.
#[derive(Clone, Default, Serialize, Deserialize)]
pub struct GGTournament {
#[serde(rename(serialize = "addrState", deserialize = "addrState"))]
pub addr_state: Option<String>,
pub admins: Option<Vec<GGUser>>,
pub city: Option<String>,
#[serde(rename(serialize = "countryCode", deserialize = "countryCode"))]
pub country_code: Option<String>,
#[serde(rename(serialize = "createdAt", deserialize = "createdAt"))]
pub created_at: Option<i64>,
pub currency: Option<String>,
#[serde(rename(serialize = "endAt", deserialize = "endAt"))]
pub end_at: Option<i64>,
#[serde(rename(serialize = "eventRegistrationClosesAt", deserialize = "eventRegistrationClosesAt"))]
pub event_registration_closes_at: Option<i64>,
pub events: Option<Vec<GGEvent>>,
#[serde(rename(serialize = "hasOfflineEvents", deserialize = "hasOfflineEvents"))]
pub has_offline_events: Option<bool>,
#[serde(rename(serialize = "hasOnlineEvents", deserialize = "hasOnlineEvents"))]
pub has_online_events: Option<bool>,
pub hashtag: Option<String>,
pub id: Option<GGID>,
pub images: Option<Vec<GGImage>>,
#[serde(rename(serialize = "isOnline", deserialize = "isOnline"))]
pub is_online: Option<bool>,
#[serde(rename(serialize = "isRegistrationOpen", deserialize = "isRegistrationOpen"))]
pub is_registration_open: Option<bool>,
pub lat: Option<f64>,
// pub links
pub lng: Option<f64>,
#[serde(rename(serialize = "mapsPlaceId", deserialize = "mapsPlaceId"))]
pub maps_place_id: Option<String>,
pub name: Option<String>,
#[serde(rename(serialize = "numAttendees", deserialize = "numAttendees"))]
pub num_attendees: Option<i64>,
pub owner: Option<Box<GGUser>>,
pub participants: Option<GGParticipantConnection>,
#[serde(rename(serialize = "postalCode", deserialize = "postalCode"))]
pub postal_code: Option<String>,
#[serde(rename(serialize = "primaryContact", deserialize = "primaryContact"))]
pub primary_contact: Option<String>,
#[serde(rename(serialize = "primaryContactType", deserialize = "primaryContactType"))]
pub primary_contact_type: Option<String>,
// publishing: JSON
#[serde(rename(serialize = "registrationClosesAt", deserialize = "registrationClosesAt"))]
pub registration_closes_at: Option<i64>,
pub rules: Option<String>,
#[serde(rename(serialize = "shortSlug", deserialize = "shortSlug"))]
pub short_slug: Option<String>,
pub slug: Option<String>,
#[serde(rename(serialize = "startAt", deserialize = "startAt"))]
pub start_at: Option<i64>,
pub state: Option<i64>,
// pub stations
// pub streamQueue
// pub streams
#[serde(rename(serialize = "teamCreationClosesAt", deserialize = "teamCreationClosesAt"))]
pub team_creation_closes_at: Option<i64>,
// pub teams
pub timezone: Option<String>,
#[serde(rename(serialize = "tournamentType", deserialize = "tournamentType"))]
pub tournament_type: Option<i64>,
#[serde(rename(serialize = "updatedAt", deserialize = "updatedAt"))]
pub updated_at: Option<i64>,
pub url: Option<String>,
#[serde(rename(serialize = "venueAddress", deserialize = "venueAddress"))]
pub venue_address: Option<String>,
#[serde(rename(serialize = "venueName", deserialize = "venueName"))]
pub venue_name: Option<String>,
// pub waves
}
impl GGTournament {
/// Returns the state address of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn addr_state(&self) -> String {
let mut result: String = "".to_string();
if self.addr_state.is_some() {
result = self.addr_state.clone().unwrap().clone();
}
return result;
}
/// Returns the admins of the tournament.
///
/// Returns an empty vector if not set or wasn't queried.
pub fn admins(&self) -> Vec<GGUser> {
let mut result: Vec<GGUser> = Vec::new();
if self.admins.is_some() {
for admin in self.admins.as_ref().unwrap() {
result.push(admin.clone());
}
}
return result;
}
/// Returns the city of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn city(&self) -> String {
let mut result: String = "".to_string();
if self.city.is_some() {
result = self.city.clone().unwrap().clone();
}
return result;
}
/// Returns the country code of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn country_code(&self) -> String {
let mut result: String = "".to_string();
if self.country_code.is_some() {
result = self.country_code.clone().unwrap().clone();
}
return result;
}
/// Returns the time the tournament was created.
///
/// Returns zero if not set or wasn't queried.
pub fn created_at(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.created_at.is_some() {
result = self.created_at.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the currency of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn currency(&self) -> String {
let mut result: String = "".to_string();
if self.currency.is_some() {
result = self.currency.clone().unwrap().clone();
}
return result;
}
/// Returns the end time of the tournament.
///
/// Returns zero if not set or wasn't queried.
pub fn end_at(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.end_at.is_some() {
result = self.end_at.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the event registration end time of the tournament.
///
/// Returns zero if not set or wasn't queried.
pub fn event_registration_closes_at(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.event_registration_closes_at.is_some() {
result = self.event_registration_closes_at.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the events in the tournament.
///
/// Returns an empty vector if not set or wasn't queried.
pub fn events(&self) -> Vec<GGEvent> {
let mut result: Vec<GGEvent> = Vec::new();
if self.events.is_some() {
for event in self.events.as_ref().unwrap() {
result.push(event.clone());
}
}
return result;
}
/// Returns if the tournament has offline events.
///
/// Returns false if not set or wasn't queried.
pub fn has_offline_events(&self) -> bool {
let mut result: bool = false;
if self.has_offline_events.is_some() {
result = self.has_offline_events.unwrap().clone();
}
return result;
}
/// Returns if the tournament has online events.
///
/// Returns false if not set or wasn't queried.
pub fn has_online_events(&self) -> bool {
let mut result: bool = false;
if self.has_online_events.is_some() {
result = self.has_online_events.unwrap().clone();
}
return result;
}
/// Returns the hashtag of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn hashtag(&self) -> String {
let mut result: String = "".to_string();
if self.hashtag.is_some() {
result = self.hashtag.clone().unwrap().clone();
}
return result;
}
/// Returns the id of the tournament.
///
/// Returns zero if not set or wasn't queried.
pub fn id(&self) -> GGID {
let mut result: GGID = GGID::Int(0);
if self.id.is_some() {
match self.id.clone().unwrap() {
GGID::Int(_) => result = self.id.as_ref().unwrap().clone(),
GGID::String(_) => result = self.id.as_ref().unwrap().clone(),
};
}
return result;
}
/// Returns the images of the tournament.
///
/// Returns an empty vector if not set or wasn't queried.
pub fn images(&self) -> Vec<GGImage> {
let mut result: Vec<GGImage> = Vec::new();
if self.images.is_some() {
for image in self.images.as_ref().unwrap() {
result.push(image.clone());
}
}
return result;
}
/// Returns if the tournament is online.
///
/// Returns false if not set or wasn't queried.
pub fn is_online(&self) -> bool {
let mut result: bool = false;
if self.is_online.is_some() {
result = self.is_online.unwrap().clone();
}
return result;
}
/// Returns if the tournament registration is open.
///
/// Returns false if not set or wasn't queried.
pub fn is_registration_open(&self) -> bool {
let mut result: bool = false;
if self.is_registration_open.is_some() {
result = self.is_registration_open.unwrap().clone();
}
return result;
}
/// Returns the latitude of the tournament.
///
/// Returns zero if not set or wasn't queried.
pub fn lat(&self) -> f64 {
let mut result: f64 = 0.0;
if self.lat.is_some() {
result = self.lat.unwrap().clone();
}
return result;
}
/// Returns the longitude of the tournament.
///
/// Returns zero if not set or wasn't queried.
pub fn lng(&self) -> f64 {
let mut result: f64 = 0.0;
if self.lng.is_some() {
result = self.lng.unwrap().clone();
}
return result;
}
/// Returns the maps place id of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn maps_place_id(&self) -> String {
let mut result: String = "".to_string();
if self.maps_place_id.is_some() {
result = self.maps_place_id.clone().unwrap().clone();
}
return result;
}
/// Returns the name of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn name(&self) -> String {
let mut result: String = "".to_string();
if self.name.is_some() {
result = self.name.clone().unwrap().clone();
}
return result;
}
/// Returns the number of attendees at the tournament.
///
/// Returns zero if not set or wasn't queried.
pub fn num_attendees(&self) -> i64 {
let mut result: i64 = 0;
if self.num_attendees.is_some() {
result = self.num_attendees.unwrap().clone();
}
return result;
}
/// Returns the owner of the tournament.
///
/// Returns an empty user if not set or wasn't queried.
pub fn owner(&self) -> GGUser {
let mut result: GGUser = Default::default();
if self.owner.is_some() {
result = *self.owner.as_ref().unwrap().clone();
}
return result;
}
/// Returns the participants in the tournament.
///
/// Returns an empty vector if not set or wasn't queried.
pub fn participants(&self) -> Vec<GGParticipant> {
let mut result: Vec<GGParticipant> = Vec::new();
if self.participants.is_some() {
for participant in &self.participants.as_ref().unwrap().nodes {
result.push(participant.clone());
}
}
return result;
}
/// Returns the postal code of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn postal_code(&self) -> String {
let mut result: String = "".to_string();
if self.postal_code.is_some() {
result = self.postal_code.clone().unwrap().clone();
}
return result;
}
/// Returns the primary contact of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn primary_contact(&self) -> String {
let mut result: String = "".to_string();
if self.primary_contact.is_some() {
result = self.primary_contact.clone().unwrap().clone();
}
return result;
}
/// Returns the primary contact type of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn primary_contact_type(&self) -> String {
let mut result: String = "".to_string();
if self.primary_contact_type.is_some() {
result = self.primary_contact_type.clone().unwrap().clone();
}
return result;
}
/// Returns the registration close date of the tournament.
///
/// Returns zero if not set or wasn't queried.
pub fn registration_closes_at(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.registration_closes_at.is_some() {
result = self.registration_closes_at.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the rules of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn rules(&self) -> String {
let mut result: String = "".to_string();
if self.rules.is_some() {
result = self.rules.clone().unwrap().clone();
}
return result;
}
/// Returns the short slug of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn short_slug(&self) -> String {
let mut result: String = "".to_string();
if self.short_slug.is_some() {
result = self.short_slug.clone().unwrap().clone();
}
return result;
}
/// Returns the slug of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn slug(&self) -> String {
let mut result: String = "".to_string();
if self.slug.is_some() {
result = self.slug.clone().unwrap().clone();
}
return result;
}
/// Returns the start time of the tournament.
///
/// Returns zero if not set or wasn't queried.
pub fn start_at(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.start_at.is_some() {
result = self.start_at.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the state of the tournament.
///
/// Returns zero if not set or wasn't queried.
pub fn state(&self) -> i64 {
let mut result: i64 = 0;
if self.state.is_some() {
result = self.state.unwrap().clone();
}
return result;
}
/// Returns the team creation end date of the tournament.
///
/// Returns zero if not set or wasn't queried.
pub fn team_creation_closes_at(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.team_creation_closes_at.is_some() {
result = self.team_creation_closes_at.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the timezone of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn timezone(&self) -> String {
let mut result: String = "".to_string();
if self.timezone.is_some() {
result = self.timezone.clone().unwrap().clone();
}
return result;
}
/// Returns the type of the tournament.
///
/// Returns zero if not set or wasn't queried.
pub fn tournament_type(&self) -> i64 {
let mut result: i64 = 0;
if self.tournament_type.is_some() {
result = self.tournament_type.unwrap().clone();
}
return result;
}
/// Returns the time the tournament was last updated.
///
/// Returns zero if not set or wasn't queried.
pub fn updated_at(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.updated_at.is_some() {
result = self.updated_at.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the url of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn url(&self) -> String {
let mut result: String = "".to_string();
if self.url.is_some() {
result = self.url.clone().unwrap().clone();
}
return result;
}
/// Returns the venue address of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn venue_address(&self) -> String {
let mut result: String = "".to_string();
if self.venue_address.is_some() {
result = self.venue_address.clone().unwrap().clone();
}
return result;
}
/// Returns the venue name of the tournament.
///
/// Returns an empty string if not set or wasn't queried.
pub fn venue_name(&self) -> String {
let mut result: String = "".to_string();
if self.venue_name.is_some() {
result = self.venue_name.clone().unwrap().clone();
}
return result;
}
}