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
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::{Authentication, ClientExecutor, RequestBuilder};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Guild {
pub id: String,
pub name: String,
pub tag: String,
pub emblem: GuildEmblem,
// Avaliable with leader token.
pub level: Option<u8>,
pub motd: Option<String>,
pub influence: Option<u64>,
pub aetherium: Option<u64>,
pub favor: Option<u64>,
pub member_count: Option<u16>,
pub member_capacity: Option<u16>,
}
impl Guild {
/// Returns the guild with the given `id`.
pub fn get<C>(client: &C, id: &str) -> C::Result
where
C: ClientExecutor<Self>,
{
let uri = format!("/v2/guild/{}", id);
client.send(RequestBuilder::new(uri))
}
/// Returns a list of guild ids matching the searched `name`. If no matches are found this
/// returns an empty [`Vec`].
///
/// # Examples
///
/// ```no_run
/// # use gw2api_rs::{Client, Result};
/// # use gw2api_rs::v2::guild::Guild;
/// #
/// # async fn run() -> Result<()> {
/// let client = Client::new();
/// let guilds = Guild::search(&client, "Covenant Of The Just").await?;
/// println!("{:?}", guilds);
/// # Ok(())
/// # }
/// ```
///
/// Using the [`blocking`] client:
///
/// ```no_run
/// # use gw2api_rs::Result;
/// # use gw2api_rs::blocking::Client;
/// # use gw2api_rs::v2::guild::Guild;
/// #
/// # fn run() -> Result<()> {
/// let client = Client::new();
/// let guilds = Guild::search(&client, "Covenant Of The Just")?;
/// println!("{:?}", guilds);
/// # Ok(())
/// # }
/// ```
///
/// [`blocking`]: crate::blocking
pub fn search<C>(client: &C, name: &str) -> C::Result
where
C: ClientExecutor<Vec<String>>,
{
let uri = format!("/v2/guild/search?name={}", name);
client.send(RequestBuilder::new(uri))
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GuildEmblem {
pub background: GuildEmblemSection,
pub foreground: GuildEmblemSection,
pub flags: Vec<GuildEmblemFlag>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GuildEmblemSection {
pub id: u64,
pub colors: Vec<u64>,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub enum GuildEmblemFlag {
FlipBackgroundHorizontal,
FlipBackgroundVertical,
FlipForegroundHorizontal,
FlipForegroundVertical,
}
/// A list of [`GuildMember`]s.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(transparent)]
pub struct GuildMembers(pub Vec<GuildMember>);
impl GuildMembers {
/// Returns a list of all members in the guild with the provided `guild_id`.
///
/// Note that the current access token must be a guild leader of the provided `guild_id`.
///
/// # Authentication
///
/// This endpoint requires authentication and returns an [`Error`] if no access token is set.
/// If the account of the current access token is not a guild leader of the guild, an [`Error`]
/// is returned.
///
/// # Examples
///
/// ```no_run
/// # use gw2api_rs::{Client, Result};
/// # use gw2api_rs::v2::guild::GuildMembers;
/// #
/// # async fn run() -> Result<()> {
/// # let token = "";
/// # let guild = "";
/// let client: Client = Client::builder().access_token(token).into();
/// let members = GuildMembers::get(&client, guild).await?;
/// println!("{:?}", members);
/// # Ok(())
/// # }
/// ```
///
/// Using the [`blocking`] client:
///
/// ```no_run
/// # use gw2api_rs::Result;
/// # use gw2api_rs::blocking::Client;
/// # use gw2api_rs::v2::guild::GuildMembers;
/// #
/// # fn run() -> Result<()> {
/// # let token = "";
/// # let guild = "";
/// let client: Client = Client::builder().access_token(token).into();
/// let members = GuildMembers::get(&client, guild)?;
/// println!("{:?}", members);
/// # Ok(())
/// # }
/// ```
///
/// [`Error`]: struct@crate::Error
/// [`blocking`]: crate::blocking
pub fn get<C>(client: &C, guild_id: &str) -> C::Result
where
C: ClientExecutor<Self>,
{
let uri = format!("/v2/guild/{}/members", guild_id);
client.send(RequestBuilder::new(uri).authenticated(Authentication::Required))
}
}
/// A member in a guild.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GuildMember {
/// The account name of the member.
pub name: String,
/// The rank of the member.
pub rank: String,
/// The date the member joined the guild.
pub joined: DateTime<Utc>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(transparent)]
pub struct GuildRanks(Vec<GuildRank>);
impl GuildRanks {
/// Returns a list of ranks in the guild with the provided `guild_id`.
///
/// Note that the current access token must be a guild leader of the provided `guild_id`.
///
/// # Authentication
///
/// This endpoint requires authentication and returns an [`Error`] if no access token is set.
/// If the account of the current access token is not a guild leader of the guild, an [`Error`]
/// is returned.
///
/// # Examples
///
/// ```no_run
/// # use gw2api_rs::{Client, Result};
/// # use gw2api_rs::v2::guild::GuildRanks;
/// #
/// # async fn run() -> Result<()> {
/// # let token = "";
/// # let guild = "";
/// let client: Client = Client::builder().access_token(token).into();
/// let ranks = GuildRanks::get(&client, guild).await?;
/// println!("{:?}", ranks);
/// # Ok(())
/// # }
/// ```
///
/// Using the [`blocking`] client:
///
/// ```no_run
/// # use gw2api_rs::Result;
/// # use gw2api_rs::blocking::Client;
/// # use gw2api_rs::v2::guild::GuildRanks;
/// #
/// # fn run() -> Result<()> {
/// # let token = "";
/// # let guild = "";
/// let client: Client = Client::builder().access_token(token).into();
/// let ranks = GuildRanks::get(&client, guild)?;
/// println!("{:?}", ranks);
/// # Ok(())
/// # }
/// ```
///
/// [`Error`]: struct@crate::Error
/// [`blocking`]: crate::blocking
pub fn get<C>(client: &C, guild_id: &str) -> C::Result
where
C: ClientExecutor<Self>,
{
let uri = format!("/v2/guild/{}/ranks", guild_id);
client.send(RequestBuilder::new(uri).authenticated(Authentication::Required))
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GuildRank {
/// The unique name of the rank.
pub id: String,
/// The sorting order of the rank. A lower order is a higher rank.
pub order: u64,
/// A list of permissions granted to this rank.
pub permissions: Vec<String>,
/// A url pointing to the icon of the rank.
pub icon: String,
}