From c597a20311b03ffaf8d3ba2ff2f0f22d592a312b Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Wed, 3 Jan 2024 20:06:08 -0500 Subject: [PATCH] Add websockets URL to parsing --- src/utils.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/utils.rs b/src/utils.rs index d7dd91d..ccd9463 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -311,6 +311,7 @@ pub struct Post { pub gallery: Vec, pub awards: Awards, pub nsfw: bool, + pub ws_url: String, } impl Post { @@ -413,6 +414,7 @@ impl Post { gallery, awards, nsfw: post["data"]["over_18"].as_bool().unwrap_or_default(), + ws_url: val(post, "websocket_url"), }); } @@ -739,6 +741,7 @@ pub async fn parse_post(post: &serde_json::Value) -> Post { gallery, awards, nsfw: post["data"]["over_18"].as_bool().unwrap_or_default(), + ws_url: val(post, "websocket_url"), } } @@ -1138,3 +1141,12 @@ async fn test_fetching_nsfw_subreddit() { assert!(subreddit.is_ok()); assert!(!subreddit.unwrap().0.is_empty()); } + +#[tokio::test(flavor = "multi_thread")] +async fn test_fetching_ws() { + let subreddit = Post::fetch("/r/popular", false).await; + assert!(subreddit.is_ok()); + for post in subreddit.unwrap().0 { + assert!(post.ws_url.starts_with("wss://k8s-lb.wss.redditmedia.com/link/")); + } +}