Struct steamgriddb_api::client::Client [−][src]
pub struct Client { /* fields omitted */ }
Expand description
This Client provides a convenient way to interact with the SteamGrid API.
The client calls the API using the reqwest crate and parses the result using the serde crate.
Examples
Searching for a game and getting images for it:
use steamgriddb_api::client::Client;
use steamgriddb_api::query_parameters::QueryType::Grid;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new("my_auth_key");
let games = client.search("Celeste").await?;
let first_game = games.iter().next().ok_or("No games found")?;
assert_eq!("Celeste", first_game.name);
let images = client.get_images_for_id(first_game.id, &Grid(None)).await?;
Ok(())
}
Implementations
Creates a new client with the given auth key.
Examples
use steamgriddb_api::client::Client;
let client = Client::new("my_auth_key");
assert_eq!("my_auth_key", client.get_auth_key());
Sets the base url for the client.
The default url is https://www.steamgriddb.com/api/v2
Examples
use steamgriddb_api::client::Client;
let mut client = Client::new("my_auth_key");
client.set_base_url("https://localhost:8080/api/v2");
assert_eq!("https://localhost:8080/api/v2", client.base_url());
Gets the base url for the client.
The default url is https://www.steamgriddb.com/api/v2
Examples
use steamgriddb_api::client::Client;
let mut client = Client::new("my_auth_key");
assert_eq!("https://www.steamgriddb.com/api/v2", client.base_url());
Gets the auth key for the client.
Examples
use steamgriddb_api::client::Client;
let client = Client::new("my_auth_key");
assert_eq!("my_auth_key", client.get_auth_key());
Sets the auth key for the client.
Examples
use steamgriddb_api::client::Client;
let mut client = Client::new("my_auth_key");
client.set_auth_key("another_key");
assert_eq!("another_key", client.get_auth_key());
Fetches images given a game id and a query type.
Examples
The Query type decides which kind of images to fetch.
use steamgriddb_api::client::Client;
use steamgriddb_api::query_parameters::QueryType::*;
let mut client = Client::new("my_auth_key");
let grid_images = client.get_images_for_id(7993, &Grid(None)).await?;
let hero_images = client.get_images_for_id(7993, &Hero(None)).await?;
Query parameters can be given to specify which images to fetch.
use steamgriddb_api::client::Client;
use steamgriddb_api::query_parameters::GridDimentions::*;
use steamgriddb_api::query_parameters::QueryType::*;
use steamgriddb_api::query_parameters::GridQueryParameters;
let mut client = Client::new("my_auth_key");
let mut parameters = GridQueryParameters::default();
parameters.dimentions = Some(&[D600x900,D512x512]);
let filtered_grid_images = client.get_images_for_id(7993, &Grid(Some(parameters))).await?;
Fetches images given a list game id’s and a query type.
The resulting list will be a SteamGridDbResult
Examples
One image will be fetched for each id.
use steamgriddb_api::client::Client;
use steamgriddb_api::query_parameters::QueryType::*;
let mut client = Client::new("my_auth_key");
let ids = [7993,5153400];
let grid_images = client.get_images_for_ids(&ids, &Grid(None)).await?;
assert_eq!(ids.len(), grid_images.len());
Search for games given a search query.
The search query will be url encoded, so that it will be safe to use.
Examples
use steamgriddb_api::client::Client;
use steamgriddb_api::query_parameters::QueryType::*;
let mut client = Client::new("my_auth_key");
let search_results = client.search("Celeste").await?;
let first_result = search_results.iter().next().ok_or("None found")?;
assert_eq!(first_result.name, "Celeste");
Fetches images given a platform type, a platform specific game id and a query type.
Examples
use steamgriddb_api::client::Client;
use steamgriddb_api::query_parameters::Platform::*;
use steamgriddb_api::query_parameters::QueryType::*;
use steamgriddb_api::query_parameters::GridQueryParameters;
let mut client = Client::new("my_auth_key");
let platform = EpicGameStore;
let epic_games_images = client.get_images_for_platform_id(&platform, "Salt", &Grid(None)).await?;
Fetches images given a platform type, a platform specific game ids and a query type.
The resulting list will be a SteamGridDbResult
Examples
use steamgriddb_api::client::Client;
use steamgriddb_api::query_parameters::Platform::*;
use steamgriddb_api::query_parameters::QueryType::*;
use steamgriddb_api::query_parameters::GridQueryParameters;
let mut client = Client::new("my_auth_key");
let platform = EpicGameStore;
let ids = ["Salt", "Turkey"];
let epic_games_images = client.get_images_for_platform_ids(&platform, &ids, &Grid(None)).await?;
Fetch information about a game given a game id.
Examples
use steamgriddb_api::client::Client;
let mut client = Client::new("my_auth_key");
let game_info = client.get_game_info_for_id(13136).await?;
assert_eq!(game_info.name, "Celeste");
Fetch information about a game given a steam game id.
Examples
use steamgriddb_api::client::Client;
let mut client = Client::new("my_auth_key");
let game_info = client.get_game_by_steam_app_id(361420).await?;
assert_eq!(game_info.name, "Astroneer");
Get a SteamStaticUrls that contains the expected urls for the official Steam store images.
Get a SteamStaticUrls that contains the expected urls for the official Steam store images.
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more