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

source

pub fn from(api_key: String) -> Self

Returns a new SteamClient instance carrying a developer API token

source

pub fn new() -> Self

Return a SteamClient without a Steam API token

source§

impl SteamClient

source

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

source

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

source

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

source

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§

source§

impl Default for SteamClient

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more