aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-10-08 10:14:24 +0200
committerHarald Eilertsen <haraldei@anduin.net>2018-10-08 10:14:24 +0200
commit8d20318f22fa0344fa8804e15263b7736c6eff15 (patch)
tree8bc0d577c5010402fa7047e6919d1d4e02fd68f1
parentf9f58140c86857da04ee1147d0b4b9c3c2734f23 (diff)
downloadrust-zotapi-8d20318f22fa0344fa8804e15263b7736c6eff15.tar.gz
rust-zotapi-8d20318f22fa0344fa8804e15263b7736c6eff15.tar.bz2
rust-zotapi-8d20318f22fa0344fa8804e15263b7736c6eff15.zip
Differ between different type of tags in channel_stream example.
-rw-r--r--examples/channel_stream.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/examples/channel_stream.rs b/examples/channel_stream.rs
index 38b0ee4..a278244 100644
--- a/examples/channel_stream.rs
+++ b/examples/channel_stream.rs
@@ -74,10 +74,18 @@ fn get_object_type(item: &serde_json::Value) -> &str {
.unwrap_or("unknown object")
}
-fn get_hashtags(item: &serde_json::Value) -> String {
+fn get_tags(item: &serde_json::Value) -> String {
match item["tags"] {
serde_json::Value::Array(ref v) => {
- v.iter().map(|t| get_str(&t["tag"])).collect::<Vec<_>>().join(", ")
+ v.iter().map(|t| {
+ let prefix = match get_str(&t["type"]) {
+ "hashtag" => "#",
+ "forum" => "!",
+ "mention" => "@",
+ _ => "",
+ };
+ format!("{}{}", prefix, get_str(&t["tag"]))
+ }).collect::<Vec<_>>().join(", ")
},
serde_json::Value::Null => {
String::new()
@@ -96,6 +104,6 @@ fn print_item(item: &serde_json::Value) {
println!("URL: {}", get_str(&author["url"]));
println!("Proto: {}", get_str(&author["network"]));
println!("Title: {}", get_str(&item["title"]));
- println!("Tags : {}", get_hashtags(&item));
+ println!("Tags : {}", get_tags(&item));
println!("Message:\n{}", get_str(&item["body"]));
}