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
use chrono::{
DateTime,
TimeZone,
Utc
};
use serde::{
Deserialize,
Serialize,
};
use crate::{
entrant::*,
event::*,
page_info::*,
user::*,
};
#[derive(Clone, Default, Serialize, Deserialize)]
pub struct GGParticipantConnection {
pub nodes: Vec<GGParticipant>,
pub page_info: Option<Box<GGPageInfo>>,
}
impl GGParticipantConnection {
/// 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 Participant.
///
/// 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.
#[derive(Clone, Default, Serialize, Deserialize)]
pub struct GGParticipant {
#[serde(rename(serialize = "checkedIn", deserialize = "checkedIn"))]
pub checked_in: Option<bool>,
#[serde(rename(serialize = "checkedInAt", deserialize = "checkedInAt"))]
pub checked_in_at: Option<i64>,
// pub connected_accounts: JSON,
// pub contact_info: Option<GGContactInfo>,
pub email: Option<String>,
pub entrants: Option<Vec<GGEntrant>>,
pub events: Option<Vec<GGEvent>>,
#[serde(rename(serialize = "gamerTag", deserialize = "gamerTag"))]
pub gamer_tag: Option<String>,
pub id: Option<i64>,
// pub images: Option<Vec<GGImage>>,
// pub player: Option<GGPlayer>,
pub prefix: Option<String>,
// pub required_connections: Option<GGProfileAuthorization>,
pub user: Option<Box<GGUser>>,
pub verified: Option<bool>,
}
impl GGParticipant {
/// Returns if the participant is checked in.
///
/// Returns false if not set or wasn't queried.
pub fn checked_in(&self) -> bool {
let mut result: bool = false;
if self.checked_in.is_some() {
result = self.checked_in.unwrap().clone();
}
return result;
}
/// Returns the time the participant checked in at.
///
/// Returns zero if not set or wasn't queried.
pub fn checked_in_at(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.checked_in_at.is_some() {
result = self.checked_in_at.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the email of the participant.
///
/// Returns an empty string if not set or wasn't queried.
pub fn email(&self) -> String {
let mut result: String = "".to_string();
if self.email.is_some() {
result = self.email.clone().unwrap().clone();
}
return result;
}
/// Returns the entrants associated with the participant.
///
/// Returns an empty vector if not set or wasn't queried.
pub fn entrants(&self) -> Vec<GGEntrant> {
let mut result: Vec<GGEntrant> = Vec::new();
if self.entrants.is_some() {
for entrant in self.entrants.as_ref().unwrap() {
result.push(entrant.clone());
}
}
return result;
}
/// Returns the events associated with the participant.
///
/// 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 the gamer tag of the participant.
///
/// Returns an empty string if not set or wasn't queried.
pub fn gamer_tag(&self) -> String {
let mut result: String = "".to_string();
if self.gamer_tag.is_some() {
result = self.gamer_tag.clone().unwrap().clone();
}
return result;
}
/// Returns the id of the participant.
///
/// Returns zero if not set or wasn't queried.
pub fn id(&self) -> i64 {
let mut result: i64 = 0;
if self.id.is_some() {
result = self.id.unwrap().clone();
}
return result;
}
/// Returns the prefix of the participant.
///
/// Returns an empty string if not set or wasn't queried.
pub fn prefix(&self) -> String {
let mut result: String = "".to_string();
if self.prefix.is_some() {
result = self.prefix.clone().unwrap().clone();
}
return result;
}
/// Returns the user of the participant.
///
/// Returns an empty tournament if not set or wasn't queried.
pub fn user(&self) -> GGUser {
let mut result: GGUser = Default::default();
if self.user.is_some() {
result = *self.user.as_ref().unwrap().clone();
}
return result;
}
/// Returns if the participant is verified.
///
/// Returns false if not set or wasn't queried.
pub fn verified(&self) -> bool {
let mut result: bool = false;
if self.verified.is_some() {
result = self.verified.unwrap().clone();
}
return result;
}
}