Skip to content

Commit

Permalink
feat: Added methods to make update listeners onto the client
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Deprecated warframe-macros and changed project structure
  • Loading branch information
Mettwasser authored and TobiTenno committed Mar 5, 2024
1 parent 9948bca commit 16bd7be
Show file tree
Hide file tree
Showing 52 changed files with 712 additions and 572 deletions.
2 changes: 1 addition & 1 deletion .releaserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ plugins:
- "@semantic-release-cargo/semantic-release-cargo"
- "@semantic-release/github"
- - "@semantic-release/git"
- assets: ["CHANGELOG.md", "./warframe.rs/Cargo.toml"]
- assets: ["CHANGELOG.md", "Cargo.toml"]
branches:
- master
38 changes: 37 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
[package]
name = "warframe"
version = "3.1.1"
edition = "2021"
description = "An async crate to wrap Warframe's Worldstate API."
readme = "./README.md"
documentation = "https://docs.rs/warframe"
homepage = "https://docs.rs/warframe"
repository = "https://github.com/Mettwasser/warframe.rs"
license = "MIT"


[features]
default = ["worldstate"]

worldstate = []
multilangual = ["worldstate"]
worldstate_listeners = ["worldstate"]
worldstate_full = ["worldstate", "multilangual", "worldstate_listeners"]

[dev-dependencies]
clippy = "0.0.302"
rustfmt = "0.10.0"

[dependencies]
tokio = { version = "1.34.0", features = ["full"]}
reqwest = { version = "0.11.22", features = ["json"] }
chrono = { version = "0.4.31", features = ["serde", "clock"] }
serde = { version = "1.0.190", features = ["derive"] }
serde_json = { version = "1.0.108" }
serde_flat_path = "0.1.2"
serde_repr = "0.1.18"
futures = "0.3.30"
log = "0.4.20"
env_logger = "0.11.1"

[workspace]
members = ["warframe.rs", "warframe-macros", "examples/*"]
members = [ "examples/*"]
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[package]
name = "example-listener-object"
name = "listen_to_nested_updates"
version = "0.1.0"
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
warframe = { path = "../../warframe.rs/", features = ["worldstate", "macros"] }
warframe = { path = "../../", features = ["worldstate", "worldstate_listeners"] }
tokio = { version = "1.34.0", features = ["full"] }
env_logger = "0.11.1"
tokio = "1.36.0"
log = "0.4.20"
29 changes: 29 additions & 0 deletions examples/listen_to_nested_updates/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::error::Error;

use warframe::worldstate::{listener::Change, prelude::*};

/// This function will be called once a fissure updates.
/// This will send a request to the corresponding endpoint once every 30s
/// and compare the results for changes.
async fn on_fissure_update(fissure: Change<'_, Fissure>) {
match fissure {
Change::Added(fissure) => println!("Fissure ADDED : {fissure:?}"),
Change::Removed(fissure) => println!("Fissure REMOVED : {fissure:?}"),
}
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Logging setup
env_logger::builder()
.filter_level(log::LevelFilter::Debug)
.init();

// initialize a client (included in the prelude)
let client = Client::new();

// Pass the function to the handler
// (will return a Future)
client.call_on_nested_update(on_fissure_update).await?;
Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[package]
name = "example-listener-array"
name = "listen_to_updates"
version = "0.1.0"
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
warframe = { path = "../../warframe.rs/", features = ["worldstate", "macros"]}
warframe = { path = "../../", features = ["worldstate", "worldstate_listeners"] }
tokio = { version = "1.34.0", features = ["full"] }
env_logger = "0.11.1"
tokio = "1.36.0"
log = "0.4.20"
20 changes: 20 additions & 0 deletions examples/listen_to_updates/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::error::Error;

use warframe::worldstate::prelude::*;

async fn on_cetus_update(before: &Cetus, after: &Cetus) {
println!("BEFORE : {before:?}");
println!("AFTER : {after:?}");
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
env_logger::builder()
.filter_level(log::LevelFilter::Debug)
.init();

let client = Client::new();

client.call_on_update(on_cetus_update).await?;
Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[package]
name = "example-listener-object-with-state"
name = "listen_to_updates_with_state"
version = "0.1.0"
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
warframe = { path = "../../warframe.rs/", features = ["worldstate", "macros"] }
warframe = { path = "../../", features = ["worldstate", "worldstate_listeners"] }
tokio = { version = "1.34.0", features = ["full"] }
env_logger = "0.11.1"
tokio = "1.36.0"
log = "0.4.20"
36 changes: 36 additions & 0 deletions examples/listen_to_updates_with_state/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use std::{error::Error, sync::Arc};

use warframe::worldstate::prelude::*;

// Define some state
#[derive(Debug)]
struct MyState {
_num: i32,
_s: String,
}

async fn on_cetus_update(state: Arc<MyState>, before: &Cetus, after: &Cetus) {
println!("STATE : {state:?}");
println!("BEFORE : {before:?}");
println!("AFTER : {after:?}");
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
env_logger::builder()
.filter_level(log::LevelFilter::Debug)
.init();

let client = Client::new();

// Note that the state will be cloned into the handler, so Arc is preferred
let state = Arc::new(MyState {
_num: 69,
_s: "My ginormous ass".into(),
});

client
.call_on_update_with_state(on_cetus_update, state)
.await?;
Ok(())
}
22 changes: 0 additions & 22 deletions examples/listener_array/src/main.rs

This file was deleted.

21 changes: 0 additions & 21 deletions examples/listener_object/src/main.rs

This file was deleted.

38 changes: 0 additions & 38 deletions examples/listener_object_with_state/src/main.rs

This file was deleted.

12 changes: 0 additions & 12 deletions examples/simple/Cargo.toml

This file was deleted.

18 changes: 0 additions & 18 deletions examples/simple/src/main.rs

This file was deleted.

Loading

0 comments on commit 16bd7be

Please sign in to comment.