mirror of
https://codeberg.org/icewind/steam-resolve-vanity.git
synced 2026-06-03 09:04:11 +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]
|
[package]
|
||||||
name = "steam-resolve-vanity"
|
name = "steam-resolve-vanity"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
@ -8,11 +8,16 @@ repository = "https://github.com/icewind1991/steam-resolve-vanity"
|
||||||
description = "Resolve steam vanity urls"
|
description = "Resolve steam vanity urls"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
steamid-ng = "0.3.4"
|
steamid-ng = "1"
|
||||||
reqwest = { version = "0.11", features = ["json"] }
|
reqwest = { version = "0.11", default-features = false, features = ["json"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1"
|
||||||
thiserror = "1.0"
|
thiserror = "1"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["default-tls"]
|
||||||
|
default-tls = ["reqwest/default-tls"]
|
||||||
|
rustls-tls = ["reqwest/rustls-tls"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
dotenv = "0.15"
|
dotenv = "0.15"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
|
use std::convert::TryFrom;
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
use steam_resolve_vanity::get_vanity_url;
|
use steam_resolve_vanity::get_vanity_url;
|
||||||
|
use steamid_ng::SteamID;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
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
|
let binary = args.next().unwrap(); // first argument is binary
|
||||||
|
|
||||||
if let Some(steam_id) = args.next() {
|
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);
|
println!("{}", vanity);
|
||||||
} else {
|
} else {
|
||||||
println!("No vanity found for steamid");
|
println!("No vanity found for steamid");
|
||||||
|
|
|
||||||
15
src/lib.rs
15
src/lib.rs
|
|
@ -13,7 +13,7 @@ struct SteamApiResponse {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct VanityUrlResponse {
|
struct VanityUrlResponse {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
steamid: String,
|
steamid: Option<SteamID>,
|
||||||
success: u8,
|
success: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ pub enum Error {
|
||||||
#[error("Error while making request to steam api")]
|
#[error("Error while making request to steam api")]
|
||||||
Request(#[from] reqwest::Error),
|
Request(#[from] reqwest::Error),
|
||||||
#[error("Received malformed steam id")]
|
#[error("Received malformed steam id")]
|
||||||
SteamId(#[from] steamid_ng::SteamIDParseError),
|
SteamId(#[from] steamid_ng::SteamIDError),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve a steam vanity url to a steam id
|
/// 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?;
|
let api_response: SteamApiResponse = response.json().await?;
|
||||||
|
|
||||||
if api_response.response.success == 1 {
|
Ok(api_response
|
||||||
let steam_id: SteamID = api_response.response.steamid.parse()?;
|
.response
|
||||||
|
.steamid
|
||||||
Ok(Some(steam_id))
|
.filter(|_| api_response.response.success == 1))
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_vanity_url(steam_id: SteamID) -> Result<Option<String>, Error> {
|
pub async fn get_vanity_url(steam_id: SteamID) -> Result<Option<String>, Error> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue