WIP: Create apub_inbox crate #8

Draft
steffo wants to merge 40 commits from feature/apub-inbox into main
3 changed files with 21 additions and 21 deletions
Showing only changes of commit 8c191cf9ae - Show all commits

View file

@ -7,14 +7,14 @@ use mediatype::MediaType;
use crate::activitystreams::StreamsLink; use crate::activitystreams::StreamsLink;
pub trait StreamsJsonLD { pub trait StreamsJsonLD {
fn get_one_str(&self, id: &Iri) -> Option<AResult<String>>; fn jsonld_any_value_string(&self, id: &Iri) -> Option<AResult<String>>;
fn get_multiple_str(&self, id: &Iri) -> impl Iterator<Item = AResult<String>>; fn jsonld_iter_value_string(&self, id: &Iri) -> impl Iterator<Item = AResult<String>>;
fn get_one_mediatype(&self, id: &Iri) -> Option<AResult<MediaType>>; fn jsonld_any_value_mediatype(&self, id: &Iri) -> Option<AResult<MediaType>>;
fn get_node_str(&self, id: &Iri) -> Option<AResult<String>>; fn jsonld_any_node_string(&self, id: &Iri) -> Option<AResult<String>>;
} }
impl StreamsJsonLD for &json_ld::Node { impl StreamsJsonLD for &json_ld::Node {
fn get_one_str(&self, id: &Iri) -> Option<AResult<String>> { fn jsonld_any_value_string(&self, id: &Iri) -> Option<AResult<String>> {
let property = match self.properties.get_any(&id) { let property = match self.properties.get_any(&id) {
None => return None, None => return None,
Some(property) => property, Some(property) => property,
@ -35,7 +35,7 @@ impl StreamsJsonLD for &json_ld::Node {
Some(Ok(string)) Some(Ok(string))
} }
fn get_multiple_str(&self, id: &Iri) -> impl Iterator<Item = AResult<String>> { fn jsonld_iter_value_string(&self, id: &Iri) -> impl Iterator<Item = AResult<String>> {
let properties = self.properties.get(&id); let properties = self.properties.get(&id);
let values = properties.map(|v| v let values = properties.map(|v| v
@ -59,7 +59,7 @@ impl StreamsJsonLD for &json_ld::Node {
strings strings
} }
fn get_one_mediatype(&self, id: &Iri) -> Option<AResult<MediaType>> { fn jsonld_any_value_mediatype(&self, id: &Iri) -> Option<AResult<MediaType>> {
let property = match self.properties.get_any(&id) { let property = match self.properties.get_any(&id) {
None => return None, None => return None,
Some(property) => property, Some(property) => property,
@ -83,7 +83,7 @@ impl StreamsJsonLD for &json_ld::Node {
Some(Ok(mediatype)) Some(Ok(mediatype))
} }
fn get_node_str(&self, id: &Iri) -> Option<AResult<String>> { fn jsonld_any_node_string(&self, id: &Iri) -> Option<AResult<String>> {
let property = match self.properties.get_any(&id) { let property = match self.properties.get_any(&id) {
None => return None, None => return None,
Some(property) => property, Some(property) => property,
@ -106,26 +106,26 @@ impl StreamsJsonLD for &json_ld::Node {
} }
impl StreamsLink for &json_ld::Node { impl StreamsLink for &json_ld::Node {
fn streams_href(&self) -> Option<AResult<String>> { fn activitystreams_href(&self) -> Option<AResult<String>> {
self.get_node_str( self.jsonld_any_node_string(
iri!("https://www.w3.org/ns/activitystreams#href") iri!("https://www.w3.org/ns/activitystreams#href")
) )
} }
fn streams_rel(&self) -> impl Iterator<Item = AResult<String>> { fn activitystreams_rel(&self) -> impl Iterator<Item = AResult<String>> {
self.get_multiple_str( self.jsonld_iter_value_string(
iri!("https://www.w3.org/ns/activitystreams#rel") iri!("https://www.w3.org/ns/activitystreams#rel")
) )
} }
fn streams_media_type(&self) -> Option<AResult<MediaType>> { fn activitystreams_mediatype(&self) -> Option<AResult<MediaType>> {
self.get_one_mediatype( self.jsonld_any_value_mediatype(
iri!("https://www.w3.org/ns/activitystreams#mediaType") iri!("https://www.w3.org/ns/activitystreams#mediaType")
) )
} }
/* /*
fn streams_name(&self) -> impl Iterator<Item=AResult<(Option<LanguageTag>, String)>> { fn activitystreams_name(&self) -> impl Iterator<Item=AResult<(Option<LanguageTag>, String)>> {
todo!() todo!()
} }
*/ */

View file

@ -23,12 +23,12 @@ pub trait StreamsObject {
/// Something that can be considered a `https://www.w3.org/ns/activitystreams#Link`. /// Something that can be considered a `https://www.w3.org/ns/activitystreams#Link`.
pub trait StreamsLink { pub trait StreamsLink {
fn streams_href(&self) -> Option<AResult<String>>; fn activitystreams_href(&self) -> Option<AResult<String>>;
// FIXME: This accepts any kind of string, and does not filter to HTML link relations // FIXME: This accepts any kind of string, and does not filter to HTML link relations
fn streams_rel(&self) -> impl Iterator<Item = AResult<String>>; fn activitystreams_rel(&self) -> impl Iterator<Item = AResult<String>>;
fn streams_media_type(&self) -> Option<AResult<MediaType>>; fn activitystreams_mediatype(&self) -> Option<AResult<MediaType>>;
/* /*
fn streams_name(&self) -> impl Iterator<Item = AResult<(LanguageTag, String)>>; fn streams_name(&self) -> impl Iterator<Item = AResult<(LanguageTag, String)>>;

View file

@ -215,7 +215,7 @@ async fn test_link_href() {
let href = { let href = {
use acrate_astreams::activitystreams::StreamsLink; use acrate_astreams::activitystreams::StreamsLink;
node.streams_href() node.activitystreams_href()
.expect("Property `href` was not found") .expect("Property `href` was not found")
.expect("Property `href` failed to process") .expect("Property `href` failed to process")
}; };
@ -233,7 +233,7 @@ async fn test_link_rel() {
let mut rels = { let mut rels = {
use acrate_astreams::activitystreams::StreamsLink; use acrate_astreams::activitystreams::StreamsLink;
node.streams_rel() node.activitystreams_rel()
.map(|v| v .map(|v| v
.expect("Property `rel` failed to process") .expect("Property `rel` failed to process")
) )
@ -260,7 +260,7 @@ async fn test_link_media_type() {
let href = { let href = {
use acrate_astreams::activitystreams::StreamsLink; use acrate_astreams::activitystreams::StreamsLink;
node.streams_media_type() node.activitystreams_mediatype()
.expect("Property `mediaType` was not found") .expect("Property `mediaType` was not found")
.expect("Property `mediaType` failed to process") .expect("Property `mediaType` failed to process")
}; };