From 632a00f13793f35fbb7f873c694ec8939e0c7ab2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 19 Jul 2020 17:33:59 +0200 Subject: [PATCH] Add MastodonUnauth::streaming_public() This is the simple implementation copied from the Mastodon::streaming_public() code. Signed-off-by: Matthias Beyer --- src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 5ea639c..747ebe6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -802,6 +802,23 @@ impl MastodonUnauth { fn send(&self, req: RequestBuilder) -> Result { Ok(self.http_sender.send(&self.client, req)?) } + + /// Get a stream of the public timeline + pub fn streaming_public(&self) -> Result> { + let mut url: url::Url = self.route("/api/v1/streaming/public/local")?; + url.query_pairs_mut().append_pair("stream", "public"); + let mut url: url::Url = reqwest::get(url.as_str())?.url().as_str().parse()?; + let new_scheme = match url.scheme() { + "http" => "ws", + "https" => "wss", + x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), + }; + url.set_scheme(new_scheme).map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; + + let client = tungstenite::connect(url.as_str())?.0; + + Ok(EventReader(WebSocket(client))) + } } impl MastodonUnauthenticated for MastodonUnauth {