diff --git a/src/commands/feed.rs b/src/commands/feed.rs new file mode 100644 index 0000000..cd8014e --- /dev/null +++ b/src/commands/feed.rs @@ -0,0 +1,25 @@ +use anyhow::Result; +use serde_json::Value; + +use super::auth; +use crate::lexicons::app_bsky_feed; +use crate::xrpc::XrpcClient; + +/// Get timeline (JSON output) +pub async fn timeline(limit: u32) -> Result<()> { + let session = auth::refresh_session().await?; + let pds = session.pds.as_deref().unwrap_or("bsky.social"); + let client = XrpcClient::new(pds); + let limit_str = limit.to_string(); + + let body: Value = client + .query_auth( + &app_bsky_feed::GET_TIMELINE, + &[("limit", &limit_str)], + &session.access_jwt, + ) + .await?; + + println!("{}", serde_json::to_string_pretty(&body)?); + Ok(()) +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index a8cef8c..ae1453c 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -16,3 +16,4 @@ pub mod oauth; pub mod setup; pub mod twofa; pub mod chat_post; +pub mod feed; diff --git a/src/main.rs b/src/main.rs index 705686c..e84b9bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -197,6 +197,13 @@ enum Commands { #[command(alias = "v")] Version, + /// Feed commands + #[command(alias = "f")] + Feed { + #[command(subcommand)] + command: FeedCommands, + }, + /// Notification commands #[command(alias = "n")] Notify { @@ -268,6 +275,17 @@ enum TwoFaCommands { }, } +#[derive(Subcommand)] +enum FeedCommands { + /// Get timeline (JSON) + #[command(alias = "tl")] + Timeline { + /// Max number of posts + #[arg(short, long, default_value = "25")] + limit: u32, + }, +} + #[derive(Subcommand)] enum NotifyCommands { /// List notifications (JSON) @@ -412,6 +430,13 @@ async fn main() -> Result<()> { Commands::Version => { println!("{}", env!("CARGO_PKG_VERSION")); } + Commands::Feed { command } => { + match command { + FeedCommands::Timeline { limit } => { + commands::feed::timeline(limit).await?; + } + } + } Commands::Notify { command } => { match command { NotifyCommands::List { limit } => {