new-home-application 0.1.3

New Home iot application framework. Meant to build application for the New Home Core
Documentation
use new_home_application::application::app_error::AppError;
use new_home_application::application::application::ApplicationInfo;
use new_home_application::application::application_framework::{Application, ApplicationFramework, BootApplication};
use new_home_application::method::method_callable::MethodCallableClosure;
use new_home_application::method::method_manager::MethodManager;
use new_home_application::method::method_structure::{Method, MethodArgument};
use new_home_application::method::response_formatter::{JsonResponseFormatter, ResponseFormatter};

struct ExampleApplication {}

impl ApplicationFramework for ExampleApplication {
    fn get_application_port(&self) -> i16 {
        4221
    }

    fn get_application_ip(&self) -> String {
        String::from("[::]")
    }

    fn get_application_info(&self) -> ApplicationInfo {
        ApplicationInfo {
            name: String::from("example-application"),
            description: String::from("This is an example application which should show you, what this crate can do"),
            authors: String::from("Yannik_Sc"),
            version: String::from("example"),
        }
    }

    fn setup_method_manager(&self, method_manager: &mut Box<dyn MethodManager>) {
        method_manager.add_method(Method {
            name: String::from("example_method"),
            description: String::new(),
            help: String::new(),
            arguments: vec![
                MethodArgument {
                    name: String::from("my_arg"),
                    description: String::new(),
                    help: String::new(),
                    value: None,
                    required: true,
                }
            ],
        }, Box::new(MethodCallableClosure::new(|args| {
            let arg = args.get_argument(&String::from("my_arg")).unwrap();

            let mut formatter = JsonResponseFormatter::new();
            formatter.add_info(&format!("You send {}", arg.as_str().unwrap()));

            formatter.as_result(0)
        })));
    }
}

fn main() -> Result<(), AppError> {
    let mut app = Application::new(Box::new(ExampleApplication {}));
    app.boot()?;
    app.multi_run(4)?;

    Ok(())
}