Struct steamr::client::SteamClient
source · pub struct SteamClient { /* private fields */ }
Expand description
This struct holds the blocking reqwest client and is used to interact with the API.
Implementations§
source§impl SteamClient
impl SteamClient
source§impl SteamClient
impl SteamClient
sourcepub fn get_friends(&self, steam_id: &str) -> Result<Vec<Friend>, SteamError>
pub fn get_friends(&self, steam_id: &str) -> Result<Vec<Friend>, SteamError>
Gets all friends from the user with the provided Steam ID.
Example:
fn main() -> Result<(), SteamError> {
let steam_client = SteamClient::from("an-api-key".to_string());
let steam_friends = steam_client.get_friends("some-steam-ID")?;
// Print friends
steam_friends.iter().for_each(|f| println!("{}", f));
Ok(())
}
The standard format of “friends since” is the UNIX timestamp, you might want to get a
more intuitive time format. You could use the chrono
crate for this:
ⓘ
let steam_friends = steam_client.get_friends("some-steam-ID")?;
steam_friends.iter().for_each(|f| {
println!(
"me and {} are friends since {}",
f.steam_id,
chrono::NaiveDateTime::from_timestamp(f.friend_since, 0)
)
});
source§impl SteamClient
impl SteamClient
sourcepub fn get_library(&self, steam_id: &str) -> Result<Library, SteamError>
pub fn get_library(&self, steam_id: &str) -> Result<Library, SteamError>
Gets all games that are owned by the user with the given Steam ID.
Example:
fn main() -> Result<(), SteamError> {
let steam_client = SteamClient::from("an-api-key".to_string());
let steam_id = "some-steam-id";
let steam_lib = steam_client.get_library(&steam_id)?;
// Print out games that were played for more than an hour.
steam_lib.games.iter()
.filter(|g| g.playtime_forever > 60)
.for_each(|g| println!("{}", g.name));
Ok(())
}
source§impl SteamClient
impl SteamClient
sourcepub fn get_game_news(
&self,
app_id: &str,
news_count: u16,
max_length: u16
) -> Result<GameNews, SteamError>
pub fn get_game_news( &self, app_id: &str, news_count: u16, max_length: u16 ) -> Result<GameNews, SteamError>
Returns the news for a game.
You can control both the number of news that you want to fetch and the maximum length of the news content (although this does not work strictly, for example when it contains hyperlinks, so this is not a number to rely on!)
This endpoint doesn’t necessarily require an API key.
Example:
fn main() -> Result<(), SteamError> {
let steam_client = SteamClient::from("an-api-key".to_string());
let app_id ="10"; // This is CS:GO
let news = steam_client.get_game_news(app_id, 5, 100)?;
news.game_news.iter()
.for_each(|n| println!("The article '{}' was written by '{}'", n.title, n.author));
Ok(())
}
source§impl SteamClient
impl SteamClient
sourcepub fn get_player_stats(
&self,
steam_id: &str,
app_id: &str
) -> Result<PlayerStats, SteamError>
pub fn get_player_stats( &self, steam_id: &str, app_id: &str ) -> Result<PlayerStats, SteamError>
Returns the stats of a given player and app ID.
Example:
fn main() -> Result<(), SteamError> {
let steam_client = SteamClient::from("an-api-key".to_string());
let player_stats = steam_client.get_player_stats("some-steam-ID", "some-app-ID")?;
println!("Showing stats for the game '{}'", &player_stats.game_name);
player_stats.achievements.iter().for_each(|a| println!("Achievement: {}", a.name));
player_stats.stats.iter().for_each(|s| println!("Stat: {}, Value: {}", s.name, s.value));
Ok(())
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SteamClient
impl !RefUnwindSafe for SteamClient
impl Send for SteamClient
impl Sync for SteamClient
impl Unpin for SteamClient
impl !UnwindSafe for SteamClient
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more