mirror of
https://codeberg.org/icewind/steam-resolve-vanity.git
synced 2026-06-03 09:04:11 +02:00
cargo updates
This commit is contained in:
parent
539d878a7c
commit
bd689f3141
4 changed files with 580 additions and 471 deletions
1023
Cargo.lock
generated
1023
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
17
Cargo.toml
17
Cargo.toml
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "steam-resolve-vanity"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||
edition = "2018"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
|
@ -9,16 +9,11 @@ description = "Resolve steam vanity urls"
|
|||
rust-version = "1.82.0"
|
||||
|
||||
[dependencies]
|
||||
steamid-ng = "1.0.0"
|
||||
reqwest = { version = "0.12.18", default-features = false, features = ["json"] }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
thiserror = "2.0.12"
|
||||
|
||||
[features]
|
||||
default = ["default-tls"]
|
||||
default-tls = ["reqwest/default-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
steamid-ng = "3.0.0"
|
||||
reqwest = { version = "0.13.2", features = ["json", "query"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
thiserror = "2.0.18"
|
||||
|
||||
[dev-dependencies]
|
||||
dotenvy = "0.15.7"
|
||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
||||
tokio = { version = "1.50", features = ["macros", "rt-multi-thread"] }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use std::convert::TryFrom;
|
||||
use std::env::args;
|
||||
use std::str::FromStr;
|
||||
use steam_resolve_vanity::get_vanity_url;
|
||||
use steamid_ng::SteamID;
|
||||
|
||||
|
|
@ -9,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(SteamID::try_from(steam_id.as_str())?).await? {
|
||||
if let Some(vanity) = get_vanity_url(SteamID::from_str(steam_id.as_str())?).await? {
|
||||
println!("{}", vanity);
|
||||
} else {
|
||||
println!("No vanity found for steamid");
|
||||
|
|
|
|||
23
src/lib.rs
23
src/lib.rs
|
|
@ -1,7 +1,9 @@
|
|||
use reqwest::header::LOCATION;
|
||||
use reqwest::redirect::Policy;
|
||||
use reqwest::{Client, ClientBuilder, StatusCode};
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Deserializer, de::Error as _};
|
||||
use std::borrow::Cow;
|
||||
use std::str::FromStr;
|
||||
pub use steamid_ng::SteamID;
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
@ -12,11 +14,20 @@ struct SteamApiResponse {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
struct VanityUrlResponse {
|
||||
#[serde(default)]
|
||||
#[serde(default, deserialize_with = "des_steam_id")]
|
||||
steamid: Option<SteamID>,
|
||||
success: u8,
|
||||
}
|
||||
|
||||
fn des_steam_id<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Option<SteamID>, D::Error> {
|
||||
let opt_str = <Option<Cow<str>>>::deserialize(deserializer)?;
|
||||
opt_str
|
||||
.as_deref()
|
||||
.map(SteamID::from_str)
|
||||
.transpose()
|
||||
.map_err(D::Error::custom)
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error("Invalid api key")]
|
||||
|
|
@ -24,7 +35,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::SteamIDError),
|
||||
SteamId(#[from] steamid_ng::SteamIDParseError),
|
||||
}
|
||||
|
||||
/// Resolve a steam vanity url to a steam id
|
||||
|
|
@ -76,7 +87,7 @@ pub async fn get_vanity_url(steam_id: SteamID) -> Result<Option<String>, Error>
|
|||
async fn test_valid() {
|
||||
let key = dotenvy::var("STEAM_API_KEY").unwrap();
|
||||
assert_eq!(
|
||||
Some(SteamID::from(76561198024494988)),
|
||||
Some(SteamID::from_steam64(76561198024494988).unwrap()),
|
||||
resolve_vanity_url("icewind1991", &key).await.unwrap()
|
||||
)
|
||||
}
|
||||
|
|
@ -107,7 +118,7 @@ async fn test_not_found() {
|
|||
async fn test_get_vanity() {
|
||||
assert_eq!(
|
||||
Some("icewind1991".to_string()),
|
||||
get_vanity_url(SteamID::from(76561198024494988))
|
||||
get_vanity_url(SteamID::from_steam64(76561198024494988).unwrap())
|
||||
.await
|
||||
.unwrap()
|
||||
)
|
||||
|
|
@ -118,7 +129,7 @@ async fn test_get_vanity() {
|
|||
async fn test_get_vanity_not_found() {
|
||||
assert_eq!(
|
||||
None,
|
||||
get_vanity_url(SteamID::from(76561198024494987))
|
||||
get_vanity_url(SteamID::from_steam64(76561198024494987).unwrap())
|
||||
.await
|
||||
.unwrap()
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue