steam_webapi_rust_sdk/util/
mod.rs1use std::collections::HashMap;
2use std::env;
3use std::time::{SystemTime, UNIX_EPOCH};
4
5pub fn get_steam_web_api_key() -> String {
6 let boxed_steam_web_api_key = env::var("STEAM_WEBAPI_KEY");
7 if boxed_steam_web_api_key.is_err() {
8 println!("To use this SDK please specify STEAM_WEBAPI_KEY environment variable");
9 return "".to_string();
10 }
11 let steam_web_api_key = boxed_steam_web_api_key.unwrap();
12 let _key = ["STEAM_WEB_API_KEY is ", &steam_web_api_key].join("");
13
14 return steam_web_api_key;
15}
16
17pub fn build_api_url(interface: &str, method: &str, version: &str, _parameters: HashMap<String, String>) -> String {
18 let slash_separator = "/";
19 let parameters_start = "?";
20 let parameter_equals = "=";
21 let key_parameter = "key";
22
23 let steam_api_url = "https://api.steampowered.com";
24
25 let steam_web_api_key = get_steam_web_api_key();
26
27 let url = [steam_api_url, slash_separator, interface, slash_separator, method, slash_separator, version, parameters_start, key_parameter, parameter_equals, &steam_web_api_key].join("");
28
29 return url
30}
31
32pub fn get_cache_dir_path() -> String {
33 ["steam-webapi-cache".to_string()].join("/")
34}
35
36pub fn as_unix_timestamp(system_time: SystemTime) -> u64 {
37 let since_the_epoch = system_time.duration_since(UNIX_EPOCH).expect("Time went backwards");
38 let unix_timestamp = since_the_epoch.as_secs() * 1000 + since_the_epoch.subsec_nanos() as u64 / 1_000_000;
39 unix_timestamp
40}
41
42pub fn get_json_filetype() -> String {
43 "json".to_string()
44}