rustybook-messenger 0.2.1

Messenger client for Rustybook
Documentation
use serde_json::Value;

use crate::gateway::lightspeed::op::{
    RespOp,
    parse_operations,
};

#[derive(Debug, Clone)]
pub struct RespPayload {
    pub name: Option<String>,
    pub step: Value,
    pub operations: Vec<RespOp>,
    pub raw: Value,
}

impl RespPayload {
    pub fn parse(value: Value) -> Option<Self> {
        let name = value
            .get("name")
            .and_then(Value::as_str)
            .map(ToString::to_string);
        let step = value.get("step")?.clone();
        let operations = parse_operations(&step);

        Some(Self {
            name,
            step,
            operations,
            raw: value,
        })
    }
}