Implemented first two endpoints
This commit is contained in:
parent
c9c30b7720
commit
628874f4e9
|
@ -8,3 +8,6 @@ edition = "2021"
|
|||
[dependencies]
|
||||
reqwest = { version = "0.11", features = ["json"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
base64 = "0.21.5"
|
||||
|
|
31
README.md
31
README.md
|
@ -1,2 +1,33 @@
|
|||
# Purple Cello Mojang API Interface
|
||||
Purple Cello interface for the Mojang API in rust
|
||||
|
||||
## Implemented endpoints
|
||||
|
||||
[ ] ~~API Status (Removed)~~
|
||||
[x] Username to UUID
|
||||
[ ] Usernames to UUIDs
|
||||
[ ] ~~UUID to Name History (Removed)~~
|
||||
[x] UUID to Profile and Skin/Cape
|
||||
[ ] Blocked Servers
|
||||
[ ] Statistics
|
||||
[ ] Profile Information
|
||||
[ ] Player Attributes
|
||||
[ ] Player Blocklist
|
||||
[ ] Player Certificates
|
||||
[ ] Profile Name Change Information
|
||||
[ ] Check Product Voucher
|
||||
[ ] Name Availability
|
||||
[ ] Change Name
|
||||
[ ] Change Skin
|
||||
[ ] Upload Skin
|
||||
[ ] Reset Skin
|
||||
[ ] Hide Cape
|
||||
[ ] Show Cape
|
||||
[ ] Verify Security Location
|
||||
[ ] Get Security Questions
|
||||
[ ] Send Security Answers
|
||||
[ ] Get Account Migration Information
|
||||
[ ] Account Migration OTP
|
||||
[ ] Verify Account Migration OTP
|
||||
[ ] Submit Migration Token
|
||||
[ ] Connect Xbox Live
|
||||
|
|
174
src/lib.rs
174
src/lib.rs
|
@ -1,14 +1,170 @@
|
|||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
// Yeahbut January 2024
|
||||
|
||||
use reqwest;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use base64::{Engine as _, engine::general_purpose};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct UsernameToUuid {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub id: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub legacy: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub demo: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub path: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub errorMessage: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
pub async fn username_to_uuid(username: &str)
|
||||
-> Result<UsernameToUuid, Box<dyn std::error::Error>>
|
||||
{
|
||||
let url = format!(
|
||||
"https://api.mojang.com/users/profiles/minecraft/{}",
|
||||
username
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
let resp = reqwest::get(url)
|
||||
.await?
|
||||
.json::<UsernameToUuid>()
|
||||
.await?;
|
||||
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ProfileTextureMetadata {
|
||||
pub model: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ProfileTexture {
|
||||
pub url: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub metadata: Option<ProfileTextureMetadata>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ProfileTextures {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub SKIN: Option<ProfileTexture>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub CAPE: Option<ProfileTexture>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ProfileValue {
|
||||
pub timestamp: i64,
|
||||
pub profileId: String,
|
||||
pub profileName: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub signatureRequired: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub textures: Option<ProfileTextures>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ProfileProperty {
|
||||
pub name: String,
|
||||
pub value: ProfileValue,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub signature: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct ProfilePropertyPrivate {
|
||||
pub name: String,
|
||||
pub value: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub signature: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct UUIDToProfile {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub properties: Vec<ProfileProperty>,
|
||||
pub profileActions: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub legacy: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub demo: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub path: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub errorMessage: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct UUIDToProfilePrivate {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub properties: Vec<ProfilePropertyPrivate>,
|
||||
pub profileActions: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub legacy: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub demo: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub path: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub errorMessage: Option<String>,
|
||||
}
|
||||
|
||||
fn get_profile_value(properties: Vec<ProfilePropertyPrivate>)
|
||||
-> Result<Vec<ProfileProperty>, Box<dyn std::error::Error>>
|
||||
{
|
||||
let mut output: Vec<ProfileProperty> = Vec::new();
|
||||
|
||||
for property in properties {
|
||||
output.push(ProfileProperty {
|
||||
name: property.name,
|
||||
value: serde_json::from_slice(
|
||||
&general_purpose::STANDARD_NO_PAD.decode(property.value)?
|
||||
)?,
|
||||
signature: property.signature,
|
||||
})
|
||||
}
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
pub async fn uuid_to_profile(uuid: &str)
|
||||
-> Result<UUIDToProfile, Box<dyn std::error::Error>>
|
||||
{
|
||||
let url = format!(
|
||||
"https://sessionserver.mojang.com/session/minecraft/profile/{}",
|
||||
uuid
|
||||
);
|
||||
|
||||
let resp = reqwest::get(url)
|
||||
.await?
|
||||
.json::<UUIDToProfilePrivate>()
|
||||
.await?;
|
||||
|
||||
let output = UUIDToProfile {
|
||||
id: resp.id,
|
||||
name: resp.name,
|
||||
properties: get_profile_value(resp.properties)?,
|
||||
profileActions: resp.profileActions,
|
||||
legacy: resp.legacy,
|
||||
demo: resp.demo,
|
||||
path: resp.path,
|
||||
error: resp.error,
|
||||
errorMessage: resp.errorMessage,
|
||||
};
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue