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
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use fume_core::{
player::get_steam_level::GetSteamLevel,
user::{
GroupId, Relationship, SteamId,
get_friend_list::GetFriendList,
get_player_summaries::{GetPlayerSummaries, PlayerSummary, SteamIds},
get_user_group_list::GetUserGroupList,
},
};
use crate::{Backend, error::Error, steam::SteamRef};
/// Represent a steam user friend
#[derive(Clone, Debug)]
pub struct Friend {
/// 64-bit steam user id
pub id: SteamId,
/// relationship: all or friend
pub relationship: Relationship,
/// became friend since when
pub since: SystemTime,
}
impl From<&fume_core::user::get_friend_list::Friend> for Friend {
fn from(value: &fume_core::user::get_friend_list::Friend) -> Self {
Self {
id: value.steamid,
relationship: value.relationship,
since: UNIX_EPOCH + Duration::from_secs(value.friend_since),
}
}
}
/// Represent a steam user
pub struct User<'s, B: Backend>(pub(crate) SteamRef<'s, B, SteamId>);
impl<'s, B: Backend> User<'s, B> {
/// returns the steamid of user
pub fn id(&self) -> SteamId {
self.0.value
}
/// request friend list, if a user's friend list is marked as private,
/// then this will return an HTTP 401 Unauthorized error.
/// ```rust,no_run
/// use fume::{Auth, ApiKey};
/// use fume_core::user::Relationship;
///
/// #[tokio::main]
/// async fn main() -> anyhow::Result<()> {
/// let key = ApiKey::new("STEAM_DUMMY_KEY");
/// let steam = key.with_client(reqwest::Client::new());
/// let user = steam.user(76561198335077947u64);
/// let friends = user.friends(Some(Relationship::Friend)).await?;
/// Ok(())
/// }
/// ```
pub async fn friends(
&self,
relationship: Option<Relationship>,
) -> Result<Vec<Friend>, Error<B>> {
let req = GetFriendList {
steamid: self.0.value,
relationship,
};
let resp = self.0.client.get(req).await?;
Ok(resp.friendslist.friends.iter().map(Into::into).collect())
}
/// request user group list
/// ```rust,no_run
/// use fume::{Auth, ApiKey};
///
/// #[tokio::main]
/// async fn main() -> anyhow::Result<()> {
/// let key = ApiKey::new("STEAM_DUMMY_KEY");
/// let steam = key.with_client(reqwest::Client::new());
/// let user = steam.user(76561198335077947u64);
/// let groups = user.groups().await?;
/// Ok(())
/// }
/// ```
pub async fn groups(&self) -> Result<Vec<GroupId>, Error<B>> {
let req = GetUserGroupList {
steamid: self.0.value,
};
let resp = self.0.client.get(req).await?;
Ok(resp.response.groups.iter().map(|group| group.gid).collect())
}
/// request player summary
/// ```rust,no_run
/// use fume::{Auth, ApiKey};
///
/// #[tokio::main]
/// async fn main() -> anyhow::Result<()> {
/// let key = ApiKey::new("STEAM_DUMMY_KEY");
/// let steam = key.with_client(reqwest::Client::new());
/// let user = steam.user(76561198335077947u64);
/// let summary = user.summary().await?;
/// Ok(())
/// }
/// ```
pub async fn summary(&self) -> Result<Option<PlayerSummary>, Error<B>> {
let req = GetPlayerSummaries {
steamids: SteamIds(vec![self.0.value]),
};
let resp = self.0.client.get(req).await?;
Ok(resp.response.players.into_iter().next())
}
/// get player steam level
/// ```rust,no_run
/// use fume::{Auth, ApiKey};
///
/// #[tokio::main]
/// async fn main() -> anyhow::Result<()> {
/// let key = ApiKey::new("STEAM_DUMMY_KEY");
/// let steam = key.with_client(reqwest::Client::new());
/// let user = steam.user(76561198335077947u64);
/// let level = user.level().await?;
/// Ok(())
/// }
/// ```
pub async fn level(&self) -> Result<u64, Error<B>> {
let req = GetSteamLevel {
steamid: self.0.value,
};
let resp = self.0.client.get(req).await?;
Ok(resp.response.player_level)
}
}
pub struct Users<'s, B: Backend>(pub(crate) SteamRef<'s, B, Vec<SteamId>>);
impl<'s, B: Backend> Users<'s, B> {
/// request player summaries
/// ```rust,no_run
/// use fume::{Auth, ApiKey};
///
/// #[tokio::main]
/// async fn main() -> anyhow::Result<()> {
/// let key = ApiKey::new("STEAM_DUMMY_KEY");
/// let steam = key.with_client(reqwest::Client::new());
/// let ids = vec![76561198335077947u64, 76561198335077948u64];
/// let users = steam.users(ids);
/// let summaries = users.summaries().await?;
/// Ok(())
/// }
/// ```
pub async fn summaries(&self) -> Result<Vec<PlayerSummary>, Error<B>> {
let req = GetPlayerSummaries {
steamids: SteamIds(self.0.value.clone()),
};
let resp = self.0.client.get(req).await?;
Ok(resp.response.players)
}
}