aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2024-01-13 20:35:13 +0100
committerHarald Eilertsen <haraldei@anduin.net>2024-01-13 20:35:13 +0100
commit04b1504e8715ee6acf498a4261775f3b9d6d6daa (patch)
treed49610047948765a0f08ddfb1a83531599e2d06f /src
parent1c4839d7449fd85734bb1335a303fc377cab1a04 (diff)
downloadrust-zotapi-04b1504e8715ee6acf498a4261775f3b9d6d6daa.tar.gz
rust-zotapi-04b1504e8715ee6acf498a4261775f3b9d6d6daa.tar.bz2
rust-zotapi-04b1504e8715ee6acf498a4261775f3b9d6d6daa.zip
Add stream Actor and Tag structs and complete StreamItem.
Diffstat (limited to 'src')
-rw-r--r--src/stream.rs7
-rw-r--r--src/stream/actor.rs51
-rw-r--r--src/stream/streamitem.rs16
-rw-r--r--src/stream/tag.rs47
4 files changed, 121 insertions, 0 deletions
diff --git a/src/stream.rs b/src/stream.rs
index 0348822..c717a17 100644
--- a/src/stream.rs
+++ b/src/stream.rs
@@ -11,16 +11,23 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
+mod actor;
mod datetime;
mod streamitem;
+mod tag;
mod verb;
+pub use actor::Actor;
pub use datetime::DateTime;
pub use streamitem::{
StreamItem,
StreamItemEncoding,
StreamItemType,
};
+pub use tag::{
+ Tag,
+ TagType,
+};
pub use verb::Verb;
use std::{
diff --git a/src/stream/actor.rs b/src/stream/actor.rs
new file mode 100644
index 0000000..88090cf
--- /dev/null
+++ b/src/stream/actor.rs
@@ -0,0 +1,51 @@
+/**
+ * Representation of Actors in the activitystream.
+ *
+ * SPDX-FileCopyrightText: 2023 Eilertsens Kodeknekkeri
+ * SPDX-FileCopyrightText: 2023 Harald Eilertsen <haraldei@anduin.net>
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+use serde::Deserialize;
+use url::Url;
+
+#[derive(Debug, Deserialize, PartialEq)]
+pub struct Actor {
+ name: String,
+ address: String,
+ url: Url,
+ id: String,
+ id_sig: String,
+ key: String,
+}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ #[test]
+ fn test_parsing_actor_from_json() {
+ let json = r#"
+ {
+ "name": "Benjamin Franklin",
+ "address": "ben@example.com",
+ "url": "https://example.com/channel/ben",
+ "network": "zot6",
+ "photo": {
+ "mimetype": "image/jpeg",
+ "src": "https://example.com/photo/profile/m/2"
+ },
+ "id": "rUpgk2qbvnWLoKIXOlZlwlqI5vk8C4NgudFNjbcmnOBjFSXU34TObkZEClaPSfKnpFZpg87tANtko7WGs7QRvA",
+ "id_sig": "sha256.ZD8uwYmUEG_d02Y...",
+ "key": "-----BEGIN PUBLIC KEY-----\n....\n-----END PUBLIC KEY-----\n"
+ }"#;
+
+ let actor: Actor = serde_json::from_str(&json).unwrap();
+
+ assert_eq!("Benjamin Franklin", actor.name);
+ assert_eq!("ben@example.com", actor.address);
+ assert_eq!("https://example.com/channel/ben", actor.url.to_string());
+ assert_eq!("rUpgk2qbvnWLoKIXOlZlwlqI5vk8C4NgudFNjbcmnOBjFSXU34TObkZEClaPSfKnpFZpg87tANtko7WGs7QRvA", actor.id);
+ }
+}
diff --git a/src/stream/streamitem.rs b/src/stream/streamitem.rs
index d30be9e..3040dea 100644
--- a/src/stream/streamitem.rs
+++ b/src/stream/streamitem.rs
@@ -7,7 +7,9 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
+use super::actor::Actor;
use super::datetime::DateTime;
+use super::Tag;
use super::verb::Verb;
use serde::Deserialize;
@@ -26,6 +28,12 @@ pub enum StreamItemEncoding {
Zot,
}
+#[derive(Debug, Deserialize, PartialEq)]
+pub enum StreamItemFlag {
+ #[serde(rename="thread_parent")]
+ ThreadParent,
+}
+
/**
* Represents an item as returned by the stream API's.
*/
@@ -56,6 +64,13 @@ pub struct StreamItem {
pub title: String,
pub summary: String,
pub body: String,
+
+ pub owner: Actor,
+ pub author: Actor,
+
+ pub signature: String,
+ pub flags: Vec<StreamItemFlag>,
+ pub tags: Vec<Tag>,
}
impl StreamItem {
@@ -163,5 +178,6 @@ mod test {
assert_eq!("2023-12-12 17:00:42", &item.edited.to_string());
assert_eq!("0000-00-00 00:00:00", &item.expires.to_string());
assert_eq!("2023-12-19 09:01:15", &item.commented.to_string());
+ assert_eq!(StreamItemFlag::ThreadParent, item.flags[0]);
}
}
diff --git a/src/stream/tag.rs b/src/stream/tag.rs
new file mode 100644
index 0000000..0d2ee23
--- /dev/null
+++ b/src/stream/tag.rs
@@ -0,0 +1,47 @@
+/**
+ * Representation of a Tag
+ *
+ * SPDX-FileCopyrightText: 2023 Eilertsens Kodeknekkeri
+ * SPDX-FileCopyrightText: 2023 Harald Eilertsen <haraldei@anduin.net>
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+use serde::Deserialize;
+use url::Url;
+
+#[derive(Debug, Deserialize, PartialEq)]
+pub enum TagType {
+ #[serde(rename = "hashtag")]
+ Hashtag,
+}
+
+#[derive(Debug, Deserialize, PartialEq)]
+pub struct Tag {
+ tag: String,
+ url: Url,
+
+ #[serde(rename = "type")]
+ tag_type: TagType,
+}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ #[test]
+ fn test_parsing_tag_from_json() {
+ let json = r#"
+ {
+ "tag": "hubzilla",
+ "url": "https://example.com/search?tag=hubzilla",
+ "type": "hashtag"
+ }
+ "#;
+
+ let tag: Tag = serde_json::from_str(json).unwrap();
+ assert_eq!("hubzilla", tag.tag);
+ assert_eq!("https://example.com/search?tag=hubzilla", tag.url.to_string());
+ assert_eq!(TagType::Hashtag, tag.tag_type);
+ }
+}