Skip to content

Commit

Permalink
Add websockets URL to parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sigaloid committed Jan 4, 2024
1 parent 89ba46e commit c597a20
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ pub struct Post {
pub gallery: Vec<GalleryMedia>,
pub awards: Awards,
pub nsfw: bool,
pub ws_url: String,
}

impl Post {
Expand Down Expand Up @@ -413,6 +414,7 @@ impl Post {
gallery,
awards,
nsfw: post["data"]["over_18"].as_bool().unwrap_or_default(),
ws_url: val(post, "websocket_url"),
});
}

Expand Down Expand Up @@ -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"),
}
}

Expand Down Expand Up @@ -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/"));
}
}

0 comments on commit c597a20

Please sign in to comment.