29 个版本

0.2.10 2024年8月19日
0.2.9 2024年7月19日
0.2.6 2024年6月24日
0.0.4 2024年3月10日
0.0.0 2023年7月12日

#1819 in 网络编程

Download history 234/week @ 2024-04-27 905/week @ 2024-05-04 20/week @ 2024-05-11 85/week @ 2024-05-18 425/week @ 2024-05-25 192/week @ 2024-06-01 177/week @ 2024-06-08 711/week @ 2024-06-15 163/week @ 2024-06-22 11/week @ 2024-06-29 6/week @ 2024-07-06 195/week @ 2024-07-13 199/week @ 2024-07-20 353/week @ 2024-07-27 13/week @ 2024-08-03 6/week @ 2024-08-10

687 每月下载量

MIT 许可证

135KB
3.5K SLoC

Valorant API

这个包是对游戏内 Valorant API 的封装。

使用方法

1. 认证

要使用此包,您需要通过您的 Riot Games 账户进行认证。目前,唯一的认证方式是使用用户名和密码(不支持双因素认证)。

use valorant_api::utils::credentials_manager::CredentialsManager;
use valorant_api::utils::network::http_client::SimpleHttpClient;

#[tokio::main]
async fn main() {
    let http_client = SimpleHttpClient::new();
    let mut credentials_manager = valorant_api::utils::credentials_manager::CredentialsManager::new();
    let result = credentials_manager
        .authenticate(&http_client, "username", "password")
        .await;
    match result {
        Ok(_) => println!("Authenticated"),
        Err(_) => println!("Error while authenticating"),
    }
}

2. 使用 API

use valorant_api::enums::region::Region;
use uuid::Uuid;
use std::collections::HashMap;

let puuid = Uuid::parse_str("ee89b4d9-13d0-5832-8dd7-eb5d8806d918").expect("Invalid UUID");
let region = Region::EU;
let queries = HashMap::new();
let result = valorant_api::get_competitve_updates_v1(credentials_manager, &http_client, region, &puuid, queries).await;
println!("Result: {:#?}", result);

端点

竞技更新 V1

函数: get_competitive_updates_v1

结果类型: CompetitveUpdatesV1

比赛详情 V1

函数: get_match_details_v1

结果类型: MatchDetailsV1

比赛历史 V1

函数: get_match_history_v1

结果类型: MatchHistoryV1

MMRV1

函数: get_mmr_details_v1

结果类型: MMRDetailsV1

排行榜 V1

函数: get_leaderboard_v1

结果类型: LeaderboardV1

内容 V3

函数: get_content_v3

结果类型: ContentV3

商店优惠 V1

功能: get_store_offers_v1

结果类型: StoreOffersV1

商店界面 V2

功能: get_store_front_v2

结果类型: StoreFrontV2

获取玩家比赛历史

参数

  • credentials_manager - 凭证管理器
  • region - 玩家的地区
  • puuid - 玩家的 puuid
  • query_args - 查询参数

示例

let puuid = Uuid::parse_str("ee89b4d9-13d0-5832-8dd7-eb5d8806d918").expect("Invalid UUID");
let region = Region::EU;
let queries = HashMap::new();
let result = valorant_api::get_match_history_v1(credentials_manager, &http_client, region, &puuid, queries).await;
println!("Result: {:#?}", result);

获取比赛详情

参数

  • credentials_manager - 凭证管理器
  • region - 比赛的地区
  • match_id - 比赛的 ID

示例

let match_id = Uuid::parse_str("3100c02b-17d2-4adb-97b5-e45dee67d292").expect("Invalid UUID");
let region = Region::EU;
let result = valorant_api::get_match_details_v1(credentials_manager, &http_client, region, &match_id).await;
println!("Result: {:#?}", result);

获取玩家的 MMR

参数

  • credentials_manager - 凭证管理器
  • region - 玩家的地区
  • puuid - 玩家的 puuid

示例

let puuid = Uuid::parse_str("ee89b4d9-13d0-5832-8dd7-eb5d8806d918").expect("Invalid UUID");
let region = Region::EU;
let result = valorant_api::get_mmr_details_v1(credentials_manager, &http_client, region, &puuid).await;
println!("Result: {:#?}", result);

获取玩家的竞技更新

参数

  • credentials_manager - 凭证管理器
  • region - 玩家的地区
  • puuid - 玩家的 puuid
  • query_args - 查询参数

示例

let puuid = Uuid::parse_str("ee89b4d9-13d0-5832-8dd7-eb5d8806d918").expect("Invalid UUID");
let region = Region::EU;
let queries = HashMap::new();
let result = valorant_api::get_competitve_updates_v1(credentials_manager, &http_client, region, &puuid, queries).await;
println!("Result: {:#?}", result);

获取游戏内容

参数

  • credentials_manager - 凭证管理器
  • region - 玩家的地区

示例

let region = Region::EU;
let result = valorant_api::get_content_v1(credentials_manager, &http_client, region).await;
println!("Result: {:#?}", result);

获取地区排行榜

参数

  • credentials_manager - 凭证管理器
  • region - 排行榜的地区
  • season - 排行榜的季节
  • query_args - 查询参数

错误

RequestError - 如果请求失败

示例

let season = Uuid::parse_str("34093c29-4306-43de-452f-3f944bde22be").expect("Invalid UUID");
let region = Region::EU;
let queries = HashMap::new();
let result = valorant_api::get_leaderboard_v1(credentials_manager, &http_client, region, &season, queries).await;
println!("Result: {:#?}", result);

获取地区的商店优惠

参数

  • credentials_manager - 凭证管理器
  • region - 排行榜的地区

错误

RequestError - 如果请求失败

示例

let season = Uuid::parse_str("34093c29-4306-43de-452f-3f944bde22be").expect("Invalid UUID");
let region = Region::EU;
let result = valorant_api::get_store_offers_v1(credentials_manager, &http_client, region).await;
println!("Result: {:#?}", result);

获取玩家的商店界面

参数

  • credentials_manager - 凭证管理器
  • region - 排行榜的地区
  • puuid - 玩家的 puuid

错误

RequestError - 如果请求失败

示例

let puuid = Uuid::parse_str("34093c29-4306-43de-452f-3f944bde22be").expect("Invalid UUID");
let region = Region::EU;
let result = valorant_api::get_store_front_v1(credentials_manager, &http_client, region, puuid).await;
println!("Result: {:#?}", result);

获取玩家的账号别名。这可以用来通过游戏名和/或标语搜索账号并获取他们的 puuid。

参数

  • credentials_manager - 凭证管理器
  • http_client - HTTP 客户端
  • cluster - 玩家的集群
  • game_name - 玩家的游戏名
  • tag_line - 玩家的标语

错误

RequestError - 如果请求失败

示例

let result = valorant_api::get_account_aliases(credentials_manager, &http_client, "eu", None, None).await;
println!("Result: {:#?}", result);

获取所有活跃的 Valorant 电子竞技联赛。

参数

  • credentials_manager - 凭证管理器
  • http_client - HTTP 客户端
  • locale - 联赛返回的本地化

错误

RequestError - 如果请求失败

示例

let result = valorant_api::get_esports_leagues(&credential_manager, &http_client, EsportsLocales::US).await;
println!("Result: {:#?}", result);

获取所有职业 Valorant 比赛的赛程。

参数

  • credentials_manager - 凭证管理器
  • http_client - HTTP 客户端
  • locale - 赛程返回的本地化

错误

RequestError - 如果请求失败

示例

let result = valorant_api::get_esports_schedule(&credential_manager, &http_client, EsportsLocales::US).await;
println!("Result: {:#?}", result);

获取每场比赛的 VOD 数据。

参数

  • credentials_manager - 凭证管理器
  • http_client - HTTP 客户端
  • locale - VOD 数据返回的本地化

错误

RequestError - 如果请求失败

示例

let result = valorant_api::get_esports_vods(&credential_manager, &http_client, EsportsLocales::US).await;
println!("Result: {:#?}", result);

依赖

~16–34MB
~616K SLoC