nostralink 0.2.1

Linked data library for nostr
Documentation
#![allow(non_snake_case)]

use super::super::jsonld_serde::JLDAttr;
use super::super::NostraObject;
use serde::Serialize;
use serde_json::Value;

#[derive(Serialize, Debug, Clone)]
pub struct Thing {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alternateName: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
}

impl std::default::Default for Thing {
    fn default() -> Self {
        Self {
            alternateName: None,
            description: None,
        }
    }
}

#[derive(Serialize, Debug, Clone)]
pub struct ImageObject {
    #[serde(flatten)]
    pub ld: JLDAttr,

    pub contentUrl: String,
}

impl ImageObject {
    pub fn from_url(url: &str) -> Self {
        Self {
            ld: JLDAttr::for_schema_type("ImageObject").id(url),
            contentUrl: url.to_string(),
        }
    }
}

#[derive(Serialize, Debug, Clone)]
pub struct VideoObject {
    #[serde(flatten)]
    pub ld: JLDAttr,

    pub contentUrl: String,

    pub caption: Option<String>,
}

impl VideoObject {
    pub fn from_url(url: &str) -> Self {
        Self {
            ld: JLDAttr::for_schema_type("VideoObject").id(url),
            contentUrl: url.to_string(),
            caption: None,
        }
    }

    pub fn caption(mut self, caption: &str) -> Self {
        self.caption = Some(caption.to_string());
        self
    }
}

impl NostraObject for VideoObject {
    fn value(&mut self) -> Result<Value, serde_json::Error> {
        serde_json::to_value(self)
    }
}