diff options
Diffstat (limited to 'src/stream/tag.rs')
-rw-r--r-- | src/stream/tag.rs | 47 |
1 files changed, 47 insertions, 0 deletions
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); + } +} |