mirror of
https://codeberg.org/icewind/steam-resolve-vanity.git
synced 2026-06-03 17:14:06 +02:00
steamid-ng 1.0
This commit is contained in:
parent
edf195a72c
commit
461c5c70c5
3 changed files with 20 additions and 16 deletions
17
Cargo.toml
17
Cargo.toml
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
15
src/lib.rs
15
src/lib.rs
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue