rship-sdk 0.1.2

rship sdk in rust
Documentation
//! # Example Executor
//! ```rust
//! use dotenv::dotenv;
//! use rship_sdk::{ActionArgs, EmitterArgs, InstanceArgs, SdkClient, TargetArgs};
//! use schemars::JsonSchema;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
//! pub struct MyActionData {
//!     pub data: String,
//! }
//! #[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
//! pub struct MyEmitterType {
//!     pub data: String,
//! }
//!
//! pub async fn start_client() {
//!     // Load the environment variables
//!     dotenv().ok();
//!     let address = std::env::var("RSHIP_ADDRESS").expect("RSHIP_ADDRESS must be set");
//!     let port = std::env::var("RSHIP_PORT").expect("RSHIP_PORT must be set");
//!     let url = format!("ws://{}:{}/myko", address, port);
//!     println!("Connecting to: {}", url);
//!
//!     // Create a new sdk client
//!     let sdk = SdkClient::init();
//!     sdk.set_address(url).await;
//!
//!     // Wait for the client to connect
//!     sdk.await_connection().await;
//!
//!     // Create an instance
//!     let instance = sdk
//!         .add_instance(InstanceArgs {
//!             name: "My Instance".into(),
//!             short_id: "my-instance".into(),
//!             code: "my-instance".into(),
//!             service_id: "my-service".into(),
//!             cluster_id: None,
//!             color: "#000000".into(),
//!             machine_id: "my-machine".into(),
//!             message: None,
//!             status: rship_entities::instance::InstanceStatus::Available,
//!         })
//!         .await;
//!
//!     // Create a target
//!     let mut target = instance
//!         .add_target(TargetArgs {
//!             name: "My Target".into(),
//!             short_id: "my-target".into(),
//!             category: "my-category".into(),
//!         })
//!         .await;
//!
//!     // Add an action to the target
//!     target
//!         .add_action(
//!             ActionArgs::<MyActionData>::new("My Action".into(), "my-action".into()),
//!             |action, data| {
//!                 println!("Received data: {:?}", data);
//!                 print!("Performed action: {:?}", action);
//!             },
//!         )
//!         .await;
//!
//!     // Add an emitter to the target
//!     let emitter = target
//!         .add_emitter(EmitterArgs::<MyEmitterType>::new(
//!             "My Emitter".into(),
//!             "my-emitter".into(),
//!         ))
//!         .await;
//!
//!     // Pulse the emitter
//!     emitter
//!         .pulse(MyEmitterType {
//!             data: "Hello rship!".into(),
//!         })
//!         .await
//!         .expect("Failed to pulse emitter");
//!
//!     // Keep the client running
//!     loop {
//!         tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
//!     }
//! }
//! ```

mod action;
mod client;
mod emitter;
mod instance;
mod target;
mod types;

pub use action::ActionArgs;
pub use client::SdkClient;
pub use emitter::EmitterArgs;
pub use instance::InstanceArgs;
pub use target::TargetArgs;