astreams
: Parse Link.href as Node
https://www.w3.org/ns/activitystreams
This commit is contained in:
parent
ffe5c3cc03
commit
ea126d11f4
1 changed files with 24 additions and 1 deletions
|
@ -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<AResult<String>>;
|
||||
fn get_multiple_str(&self, id: &Iri) -> impl Iterator<Item = AResult<String>>;
|
||||
fn get_one_mediatype(&self, id: &Iri) -> Option<AResult<MediaType>>;
|
||||
fn get_node_str(&self, id: &Iri) -> Option<AResult<String>>;
|
||||
}
|
||||
|
||||
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<AResult<String>> {
|
||||
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<AResult<String>> {
|
||||
self.get_one_str(
|
||||
self.get_node_str(
|
||||
iri!("https://www.w3.org/ns/activitystreams#href")
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue