From 5e780bea1c9ce80a8c0add52705bd27e9d3d4a27 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 13 Nov 2023 22:20:50 +0100 Subject: [PATCH] Add login, instance examples --- examples/instance.rs | 16 ++++++++++++++++ examples/login.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 examples/instance.rs create mode 100644 examples/login.rs diff --git a/examples/instance.rs b/examples/instance.rs new file mode 100644 index 0000000..337482b --- /dev/null +++ b/examples/instance.rs @@ -0,0 +1,16 @@ +use chorus::instance::Instance; +use chorus::UrlBundle; + +#[tokio::main] +async fn main() { + let bundle = UrlBundle::new( + "https://example.com/api".to_string(), + "wss://example.com/".to_string(), + "https://example.com/cdn".to_string(), + ); + let instance = Instance::new(bundle, true) + .await + .expect("Failed to connect to the Spacebar server"); + dbg!(instance.instance_info); + dbg!(instance.limits_information); +} diff --git a/examples/login.rs b/examples/login.rs new file mode 100644 index 0000000..4595a06 --- /dev/null +++ b/examples/login.rs @@ -0,0 +1,30 @@ +use chorus::instance::Instance; +use chorus::types::LoginSchema; +use chorus::UrlBundle; + +#[tokio::main] +async fn main() { + let bundle = UrlBundle::new( + "https://example.com/api".to_string(), + "wss://example.com/".to_string(), + "https://example.com/cdn".to_string(), + ); + let instance = Instance::new(bundle, true) + .await + .expect("Failed to connect to the Spacebar server"); + // Assume, you already have an account created on this instance. Registering an account works + // the same way, but you'd use the Register-specific Structs and methods instead. + let login_schema = LoginSchema { + login: "user@example.com".to_string(), + password: "Correct-Horse-Battery-Staple".to_string(), + ..Default::default() + }; + // Each user connects to the Gateway. The Gateway connection lives on a seperate thread. Depending on + // the runtime feature you choose, this can potentially take advantage of all of your computers' threads. + let user = instance + .login_account(login_schema) + .await + .expect("An error occurred during the login process"); + dbg!(user.belongs_to); + dbg!(&user.object.read().unwrap().username); +}