diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-07-19 17:33:59 +0200 |
---|---|---|
committer | Paul Woolcock <paul@woolcock.us> | 2020-09-25 12:06:55 -0400 |
commit | 632a00f13793f35fbb7f873c694ec8939e0c7ab2 (patch) | |
tree | 0bdbf8f24caea38b756c41c4dbbda5df04fd287c | |
parent | 5b4be01eee9611c20782f7cdbad2a30afa323696 (diff) |
Add MastodonUnauth::streaming_public()
This is the simple implementation copied from the
Mastodon::streaming_public() code.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/lib.rs | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -802,6 +802,23 @@ impl<H: HttpSend> MastodonUnauth<H> { fn send(&self, req: RequestBuilder) -> Result<Response> { Ok(self.http_sender.send(&self.client, req)?) } + + /// Get a stream of the public timeline + pub fn streaming_public(&self) -> Result<EventReader<WebSocket>> { + 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<H: HttpSend> MastodonUnauthenticated<H> for MastodonUnauth<H> { |