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
use serde::{
Deserialize,
Serialize,
};
use crate::{
event::*,
player::*,
tournament::*,
};
/// Equivalent for start.gg User.
///
/// 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 tournaments()) 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 GGUser {
// pub authorizations: Option<Vec<GGProfileAuthorization>>
pub bio: Option<String>,
pub birthday: Option<String>,
pub discriminator: Option<String>,
pub email: Option<String>,
pub events: Option<GGEventConnection>,
#[serde(rename(serialize = "genderPronoun", deserialize = "genderPronoun"))]
pub gender_pronoun: Option<String>,
pub id: Option<i64>,
// pub images: Option<Vec<Image>>
// pub leagues: Option<GGLeagues>
// pub location: Option<GGAddress>
pub name: Option<String>,
pub player: Option<Box<GGPlayer>>,
pub slug: Option<String>,
pub tournaments: Option<GGTournamentConnection>,
}
impl GGUser {
/// Returns the bio of the user.
///
/// Returns an empty string if not set or wasn't queried.
pub fn bio(&self) -> String {
let mut result: String = "".to_string();
if self.bio.is_some() {
result = self.bio.clone().unwrap().clone();
}
return result;
}
/// Returns the birthday of the user.
///
/// Returns an empty string if not set or wasn't queried.
pub fn birthday(&self) -> String {
let mut result: String = "".to_string();
if self.birthday.is_some() {
result = self.birthday.clone().unwrap().clone();
}
return result;
}
/// Returns the discriminator of the user.
///
/// Returns an empty string if not set or wasn't queried.
pub fn discriminator(&self) -> String {
let mut result: String = "".to_string();
if self.discriminator.is_some() {
result = self.discriminator.clone().unwrap().clone();
}
return result;
}
/// Returns the email of the user.
///
/// 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 events the user has competed in.
///
/// 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().nodes {
result.push(event.clone());
}
}
return result;
}
/// Returns the gender pronoun of the user.
///
/// Returns an empty string if not set or wasn't queried.
pub fn gender_pronoun(&self) -> String {
let mut result: String = "".to_string();
if self.gender_pronoun.is_some() {
result = self.gender_pronoun.clone().unwrap().clone();
}
return result;
}
/// Returns the id of the user.
///
/// 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 name of the user.
///
/// 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 player of the user.
///
/// Returns an empty player if not set or wasn't queried.
pub fn player(&self) -> GGPlayer {
let mut result: GGPlayer = Default::default();
if self.player.is_some() {
result = *self.player.as_ref().unwrap().clone();
}
return result;
}
/// Returns the slug of the user.
///
/// 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 tournaments the user has competed in.
///
/// Returns an empty vector if not set or wasn't queried.
pub fn tournaments(&self) -> Vec<GGTournament> {
let mut result: Vec<GGTournament> = Vec::new();
if self.tournaments.is_some() {
for tournament in &self.tournaments.as_ref().unwrap().nodes {
result.push(tournament.clone());
}
}
return result;
}
}