steam_api/
functions.rs

1/// Generates a Steam API url
2///
3/// # Returns
4/// A string containing the URL
5///
6/// # Arguments
7/// * `method` - A string slice containing the desired method
8/// * `steamids` - A string slice containing the steamids
9/// * `api_key` - A string slice containing the API Key to use with the API.
10///
11/// # Panics
12/// `manage_api_url` will panic if an invalid/unsupported method is passed
13///
14/// # Example
15/// Single Steam ID
16/// ```
17/// let method = "GetSteamLevel";
18/// let steamids = "76561198421169032";
19/// let api_key = "XXXXXXXXXXX";
20///
21/// let url = steam_api::functions::manage_api_url(method, steamids, api_key);
22/// assert_eq!(url, "https://api.steampowered.com/IPlayerService/GetSteamLevel/v1/?key=XXXXXXXXXXX&steamid=76561198421169032");
23/// ```
24#[must_use]
25pub fn manage_api_url(method: &str, steamids: &str, api_key: &str) -> String {
26    let mut api: crate::structs::api::Api = crate::structs::api::Api::default();
27
28    // GetFriendList and GetSteamLevel don't work with multiple steamids
29    // Thanks valve
30    match method {
31        "GetPlayerSummaries" => {
32            api.interface = "ISteamUser";
33            api.version = "v2";
34            api.accepts_multiple_ids = true;
35        }
36        "GetFriendList" => {
37            api.interface = "ISteamUser";
38            api.version = "v1";
39            api.accepts_multiple_ids = false;
40        }
41        "GetPlayerBans" => {
42            api.interface = "ISteamUser";
43            api.version = "v1";
44            api.accepts_multiple_ids = true;
45        }
46        "GetSteamLevel" => {
47            api.interface = "IPlayerService";
48            api.version = "v1";
49            api.accepts_multiple_ids = false;
50        }
51        _ => panic!("Method not found!"),
52    }
53
54    if api.accepts_multiple_ids {
55        format!(
56            "https://api.steampowered.com/{}/{}/{}/?key={}&steamids={}",
57            api.interface, method, api.version, api_key, steamids
58        )
59    } else {
60        format!(
61            "https://api.steampowered.com/{}/{}/{}/?key={}&steamid={}",
62            api.interface, method, api.version, api_key, steamids
63        )
64    }
65}