2 unstable releases
0.2.0-alpha | Jul 20, 2024 |
---|---|
0.1.0-alpha | Mar 21, 2024 |
#944 in Web programming
21 downloads per month
39KB
893 lines
discloud-rs
A wrapper for Discloud's API made in Rust 🦀.
The crate has tracing for debug.
Routes
Click for usage example
- User
- Upload
- App
- Team Manager
- Team
- Manage (start, restart, stop, commit, status)
- Backup
- Logs
- Status
Usage
User
Get user info
use discloud_rs::Discloud;
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
let user = client.get_user_info().await.unwrap();
}
Set locale
use discloud_rs::{ Discloud, Locale };
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
client.set_locale(Locale::PtBR).await.unwrap(); // Set language to Brazilian Portuguese
}
App
Get app
use discloud_rs::{ Discloud };
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
client.get_all_apps().await.unwrap(); // Get all apps
client.get_app("APP_ID").await.unwrap(); // Get app by id
}
Get app status
use discloud_rs::{ Discloud };
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
client.get_all_apps_status().await.unwrap(); // Get all apps status
client.get_app_status("APP_ID").await.unwrap(); // Get app status by id
// Get status from app
let app = client.get_app("APP_ID").await.unwrap();
app.get_status(&client).await.unwrap();
}
Get app logs
use discloud_rs::{ Discloud };
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
client.get_all_apps_logs().await.unwrap(); // Get all apps logs (Be careful if you have many apps)
client.get_app_logs("APP_ID").await.unwrap(); // Get app logs by id
// Get logs from app
let app = client.get_app("APP_ID").await.unwrap();
app.get_logs(&client).await.unwrap();
}
Get app backup
use discloud_rs::{ Discloud };
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
client.get_all_apps_backup().await.unwrap(); // Get all apps backup (This may take a while)
client.get_app_backup("APP_ID").await.unwrap(); // Get app logs by id
// Get logs from app
let app = client.get_app("APP_ID").await.unwrap();
app.get_backup(&client).await.unwrap();
}
Manage App
Start
use discloud_rs::{ Discloud, AppStartError };
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
// Start all of your apps
let response = client.start_all_apps().await.unwrap();
// Start app by id
match client.start_app("APP_ID").await {
Ok(_) => { }, // App was started.
Err(error) => {
match error {
AppStartError::AlreadyStarted => { }, // App is already online
AppStartError::Other(e) => { } // discloud_rs::Error
}
}
};
// Start from app
let app = client.get_app("APP_ID").await.unwrap();
match app.start(&client).await {
Ok(_) => { }, // App was started.
Err(error) => {
match error {
AppStartError::AlreadyStarted => { }, // App is already online
AppStartError::Other(e) => { } // discloud_rs::Error
}
}
};
}
Restart
use discloud_rs::{ Discloud };
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
client.restart_all_apps().await.unwrap(); // Restart all of your apps
client.restart_app("APP_ID").await.unwrap(); // Restart app by id
// Restart from app
let app = client.get_app("APP_ID").await.unwrap();
app.restart(&client).await.unwrap();
}
Stop
use discloud_rs::{ Discloud, AppStopError };
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
// Stop all of your apps
client.stop_all_apps().await.unwrap();
// Stop app by id
match client.stop_app("APP_ID").await {
Ok(_) => { }, // App was stopped.
Err(error) => {
match error {
AppStopError::AlreadyStopped => { }, // App is already stopped
AppStopError::Other(e) => { } // discloud_rs::Error
}
}
};
// Stop from app
let app = client.get_app("APP_ID").await.unwrap();
match app.stop(&client).await {
Ok(_) => { }, // App was stopped.
Err(error) => {
match error {
AppStopError::AlreadyStopped => { }, // App is already stopped
AppStopError::Other(e) => { } // discloud_rs::Error
}
}
};
}
Set RAM
use discloud_rs::{ Discloud, AppRamError };
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
// Set app ram (in MB)
match client.set_app_ram("APP_ID", 100).await {
Ok(_) => { }, // App ram was changed
Err(error) => {
match error {
AppRamError::ForbiddenQuantity(message) => { }, // Forbidden quantity (Not enough memory or minimum required)
AppRamError::Other(e) => { } // discloud_rs::Error
}
}
};
// Set ram from app
let app = client.get_app("APP_ID").await.unwrap();
match app.set_ram(&client, 100).await {
Ok(_) => { }, // App ram was changed
Err(error) => {
match error {
AppRamError::ForbiddenQuantity(message) => { }, // Forbidden quantity (Not enough memory or minimum required
AppRamError::Other(e) => { } // discloud_rs::Error
}
}
};
}
Delete
use discloud_rs::Discloud;
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
// Delete all apps
client.delete_all_apps().await.unwrap();
// Delete app
client.delete_app("APP_ID").await.unwrap();
// Delete from app
let app = client.get_app("APP_ID").await.unwrap();
app.delete(&client).await.unwrap();
}
Team Manage
Get app team
use discloud_rs::Discloud;
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
// Get app team using client
client.get_app_team("APP_ID").await.unwrap();
// Get app team using app
let app = client.get_app("APP_ID").await.unwrap();
app.get_team(&client).await.unwrap();
}
Add app mod
use discloud_rs::{Discloud, TeamPerms};
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
// Add app mod using client
client.add_app_mod("APP_ID", "MOD_ID", vec![TeamPerms::Start, TeamPerms::Stop]).await.unwrap();
// Add app mod using app
let app = client.get_app("APP_ID").await.unwrap();
app.add_mod(&client, "MOD_ID", vec![TeamPerms::Start, TeamPerms::Stop]).await.unwrap();
}
Edit app mod
use discloud_rs::{Discloud, TeamPerms};
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
// Edit mod permissions using client
client.edit_app_mod("APP_ID", "MOD_ID", vec![TeamPerms::Start, TeamPerms::Stop]).await.unwrap();
// Edit mod permissions using app
let app = client.get_app("APP_ID").await.unwrap();
app.edit_mod(&client, "MOD_ID", vec![TeamPerms::Start, TeamPerms::Stop]).await.unwrap();
// Edit mod permissions from mod
if let Some(mod) = app.get_team(&client).await.unwrap().first() {
mod.edit_perms(&client, vec![TeamPerms::Start, TeamPerms::Stop]).await.unwrap();
// Or add permissions to mod
mod.add_perms(&client, vec![TeamPerms::Start, TeamPerms::Stop]).await.unwrap();
};
}
Remove app mod
use discloud_rs::{Discloud, TeamPerms};
#[tokio::main]
async fn main() {
let client = Discloud::new("TOKEN");
// Remove mod using client
client.remove_app_mod("APP_ID", "MOD_ID").await.unwrap();
// Remove mod using app
let app = client.get_app("APP_ID").await.unwrap();
app.remove_mod(&client, "MOD_ID").await.unwrap();
// Remove from mod
if let Some(mod) = app.get_team(&client).await.unwrap().first() {
mod.remove(&client).await.unwrap();
};
}
Dependencies
~4–16MB
~204K SLoC