diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2024-01-13 20:35:13 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2024-01-13 20:35:13 +0100 |
commit | 04b1504e8715ee6acf498a4261775f3b9d6d6daa (patch) | |
tree | d49610047948765a0f08ddfb1a83531599e2d06f /src/stream/actor.rs | |
parent | 1c4839d7449fd85734bb1335a303fc377cab1a04 (diff) | |
download | rust-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/stream/actor.rs')
-rw-r--r-- | src/stream/actor.rs | 51 |
1 files changed, 51 insertions, 0 deletions
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); + } +} |