diff --git a/acrate_astreams/src/activitystreams/jsonld.rs b/acrate_astreams/src/activitystreams/jsonld.rs index d623352..a4e2aef 100644 --- a/acrate_astreams/src/activitystreams/jsonld.rs +++ b/acrate_astreams/src/activitystreams/jsonld.rs @@ -2,6 +2,7 @@ use anyhow::{anyhow, Error}; use static_iref::iri; use anyhow::Result as AResult; use iref::Iri; +use json_ld::object::Any; use mediatype::MediaType; use crate::activitystreams::StreamsLink; @@ -9,6 +10,7 @@ pub trait StreamsJsonLD { fn get_one_str(&self, id: &Iri) -> Option>; fn get_multiple_str(&self, id: &Iri) -> impl Iterator>; fn get_one_mediatype(&self, id: &Iri) -> Option>; + fn get_node_str(&self, id: &Iri) -> Option>; } impl StreamsJsonLD for &json_ld::Node { @@ -80,11 +82,32 @@ impl StreamsJsonLD for &json_ld::Node { Some(Ok(mediatype)) } + + fn get_node_str(&self, id: &Iri) -> Option> { + let property = match self.properties.get_any(&id) { + None => return None, + Some(property) => property, + }; + + let node = match property.as_node() { + None => return Some(Err(anyhow!("Couldn't process property as JSON-LD node"))), + Some(value) => value, + }; + + let id = match node.id() { + None => return Some(Err(anyhow!("Couldn't process property's JSON-LD node @id"))), + Some(id) => id + }; + + let string = id.to_string(); + + Some(Ok(string)) + } } impl StreamsLink for &json_ld::Node { fn streams_href(&self) -> Option> { - self.get_one_str( + self.get_node_str( iri!("https://www.w3.org/ns/activitystreams#href") ) }