use crate::{Client, RoboatError};
use reqwest::header;
use serde::{Deserialize, Serialize};
const CLIENT_SETTINGS_V2_API: &str = "https://clientsettings.roblox.com/v2";
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[allow(missing_docs)]
pub struct ClientVersion {
pub version: String,
#[serde(rename = "clientVersionUpload")]
pub upload: String,
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[allow(missing_docs)]
pub struct UserChannel {
#[serde(rename = "channelName")]
pub name: String,
pub token: Option<String>,
}
impl Client {
pub async fn client_version(
&self,
binary_type: String,
) -> Result<ClientVersion, RoboatError> {
let formatted_url = format!("{}/client-version/{}", CLIENT_SETTINGS_V2_API, binary_type);
let request_result = self.reqwest_client.get(&formatted_url).send().await;
let response = Self::validate_request_result(request_result).await?;
Self::parse_to_raw::<ClientVersion>(response).await
}
pub async fn client_version_for_channel(
&self,
binary_type: String,
channel_name: String,
) -> Result<ClientVersion, RoboatError> {
let formatted_url = format!(
"{}/client-version/{}/channel/{}",
CLIENT_SETTINGS_V2_API, binary_type, channel_name
);
let request_result = self.reqwest_client.get(&formatted_url).send().await;
let response = Self::validate_request_result(request_result).await?;
Self::parse_to_raw::<ClientVersion>(response).await
}
pub async fn user_channel(
&self,
binary_type: Option<String>,
) -> Result<UserChannel, RoboatError> {
let cookie_string = self.cookie_string()?;
let mut formatted_url = format!("{}/user-channel", CLIENT_SETTINGS_V2_API);
if let Some(bt) = binary_type {
formatted_url.push_str(&format!("?binaryType={}", bt));
}
let request_result = self
.reqwest_client
.get(&formatted_url)
.header(header::COOKIE, cookie_string)
.send()
.await;
let response = Self::validate_request_result(request_result).await?;
Self::parse_to_raw::<UserChannel>(response).await
}
}