Add methods for remaining streams
This commit is contained in:
parent
c5141972e4
commit
334e620d3c
|
@ -440,8 +440,7 @@ macro_rules! paged_routes_with_id {
|
|||
}
|
||||
|
||||
macro_rules! streaming {
|
||||
{$($stream:ident@$fn_name:ident ($desc:tt),)*} => {
|
||||
$(
|
||||
($stream:literal@$fn_name:ident ($desc:tt), $($rest:tt)*) => {
|
||||
doc_comment! {
|
||||
concat!(
|
||||
$desc,
|
||||
|
@ -479,6 +478,51 @@ tokio_test::block_on(async {
|
|||
Ok(event_stream(response.error_for_status()?, url))
|
||||
}
|
||||
}
|
||||
)*
|
||||
streaming! { $($rest)* }
|
||||
};
|
||||
($stream:literal($param:ident: $param_type:ty, like $param_doc_val:literal)@$fn_name:ident ($desc:tt), $($rest:tt)*) => {
|
||||
doc_comment! {
|
||||
concat!(
|
||||
$desc,
|
||||
"\n\nExample:\n\n",
|
||||
"
|
||||
use elefren::prelude::*;
|
||||
use elefren::entities::event::Event;
|
||||
use futures_util::{pin_mut, StreamExt, TryStreamExt};
|
||||
|
||||
tokio_test::block_on(async {
|
||||
let data = Data::default();
|
||||
let client = Mastodon::from(data);
|
||||
let stream = client.",
|
||||
stringify!($fn_name),
|
||||
"(",
|
||||
$param_doc_val,
|
||||
").await.unwrap();
|
||||
stream.try_for_each(|event| async move {
|
||||
match event {
|
||||
Event::Update(ref status) => { /* .. */ },
|
||||
Event::Notification(ref notification) => { /* .. */ },
|
||||
Event::Delete(ref id) => { /* .. */ },
|
||||
Event::FiltersChanged => { /* .. */ },
|
||||
}
|
||||
Ok(())
|
||||
}).await.unwrap();
|
||||
});"
|
||||
),
|
||||
pub async fn $fn_name(&self, $param: $param_type) -> Result<impl TryStream<Ok=Event, Error=Error>> {
|
||||
let mut url: Url = self.route(concat!("/api/v1/streaming/", stringify!($stream))).parse()?;
|
||||
url.query_pairs_mut().append_pair(stringify!($param), $param.as_ref());
|
||||
let url = url.to_string();
|
||||
let response = self.authenticated(self.client.get(url.as_str())).send().await?;
|
||||
debug!(
|
||||
status = log_serde!(response Status), url = as_debug!(url),
|
||||
headers = log_serde!(response Headers);
|
||||
"received API response"
|
||||
);
|
||||
Ok(event_stream(response.error_for_status()?, url))
|
||||
}
|
||||
}
|
||||
streaming! { $($rest)* }
|
||||
};
|
||||
() => {}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,18 @@ impl Mastodon {
|
|||
}
|
||||
|
||||
streaming! {
|
||||
user@stream_user ("returns events that are relevant to the authorized user, i.e. home timeline & notifications"),
|
||||
"user"@stream_user ("returns events that are relevant to the authorized user, i.e. home timeline & notifications"),
|
||||
"public"@stream_public ("All public posts known to the server. Analogous to the federated timeline."),
|
||||
"public:media"@stream_public_media ("All public posts known to the server, filtered for media attachments. Analogous to the federated timeline with 'only media' enabled."),
|
||||
"public:local"@stream_local ("All public posts originating from this server."),
|
||||
"public:local:media"@stream_local_media ("All public posts originating from this server, filtered for media attachments. Analogous to the local timeline with 'only media' enabled."),
|
||||
"public:remote"@stream_remote ("All public posts originating from other servers."),
|
||||
"public:remote:media"@stream_remote_media ("All public posts originating from other servers, filtered for media attachments."),
|
||||
"hashtag"(tag: impl AsRef<str>, like "#bots")@stream_hashtag ("All public posts using a certain hashtag."),
|
||||
"hashtag:local"(tag: impl AsRef<str>, like "#bots")@stream_local_hashtag ("All public posts using a certain hashtag, originating from this server."),
|
||||
"user:notification"@stream_notifications ("Notifications for the current user."),
|
||||
"list"(list: impl AsRef<str>, like "12345")@stream_list ("Updates to a specific list."),
|
||||
"direct"@stream_direct ("Updates to direct conversations."),
|
||||
}
|
||||
|
||||
/// Create a new Mastodon Client
|
||||
|
|
Loading…
Reference in New Issue