Implemented first two endpoints
This commit is contained in:
parent
c9c30b7720
commit
628874f4e9
|
@ -8,3 +8,6 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = { version = "0.11", features = ["json"] }
|
reqwest = { version = "0.11", features = ["json"] }
|
||||||
tokio = { version = "1", features = ["full"] }
|
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 Mojang API Interface
|
||||||
Purple Cello interface for the Mojang API in rust
|
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 {
|
// Yeahbut January 2024
|
||||||
left + right
|
|
||||||
|
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)]
|
pub async fn username_to_uuid(username: &str)
|
||||||
mod tests {
|
-> Result<UsernameToUuid, Box<dyn std::error::Error>>
|
||||||
use super::*;
|
{
|
||||||
|
let url = format!(
|
||||||
|
"https://api.mojang.com/users/profiles/minecraft/{}",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
|
||||||
#[test]
|
let resp = reqwest::get(url)
|
||||||
fn it_works() {
|
.await?
|
||||||
let result = add(2, 2);
|
.json::<UsernameToUuid>()
|
||||||
assert_eq!(result, 4);
|
.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