steamid-ng 1.0

This commit is contained in:
Robin Appelman 2021-02-27 16:04:17 +01:00
commit 461c5c70c5
3 changed files with 20 additions and 16 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "steam-resolve-vanity"
version = "0.3.0"
version = "0.4.0"
authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2018"
license = "MIT OR Apache-2.0"
@ -8,11 +8,16 @@ repository = "https://github.com/icewind1991/steam-resolve-vanity"
description = "Resolve steam vanity urls"
[dependencies]
steamid-ng = "0.3.4"
reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
steamid-ng = "1"
reqwest = { version = "0.11", default-features = false, features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
thiserror = "1"
[features]
default = ["default-tls"]
default-tls = ["reqwest/default-tls"]
rustls-tls = ["reqwest/rustls-tls"]
[dev-dependencies]
dotenv = "0.15"

View file

@ -1,5 +1,7 @@
use std::convert::TryFrom;
use std::env::args;
use steam_resolve_vanity::get_vanity_url;
use steamid_ng::SteamID;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -7,7 +9,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let binary = args.next().unwrap(); // first argument is binary
if let Some(steam_id) = args.next() {
if let Some(vanity) = get_vanity_url(steam_id.parse()?).await? {
if let Some(vanity) = get_vanity_url(SteamID::try_from(steam_id.as_str())?).await? {
println!("{}", vanity);
} else {
println!("No vanity found for steamid");

View file

@ -13,7 +13,7 @@ struct SteamApiResponse {
#[derive(Deserialize)]
struct VanityUrlResponse {
#[serde(default)]
steamid: String,
steamid: Option<SteamID>,
success: u8,
}
@ -24,7 +24,7 @@ pub enum Error {
#[error("Error while making request to steam api")]
Request(#[from] reqwest::Error),
#[error("Received malformed steam id")]
SteamId(#[from] steamid_ng::SteamIDParseError),
SteamId(#[from] steamid_ng::SteamIDError),
}
/// Resolve a steam vanity url to a steam id
@ -41,13 +41,10 @@ pub async fn resolve_vanity_url(url: &str, api_key: &str) -> Result<Option<Steam
let api_response: SteamApiResponse = response.json().await?;
if api_response.response.success == 1 {
let steam_id: SteamID = api_response.response.steamid.parse()?;
Ok(Some(steam_id))
} else {
Ok(None)
}
Ok(api_response
.response
.steamid
.filter(|_| api_response.response.success == 1))
}
pub async fn get_vanity_url(steam_id: SteamID) -> Result<Option<String>, Error> {