diff --git a/bot/src/main.rs b/bot/src/main.rs index fcae3fe..9c19389 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -12,6 +12,7 @@ use std::thread; mod bluesky; mod cli; +mod mastodon; //noinspection DuplicatedCode /// Sets up a signal handler in a separate thread to handle SIGINT and SIGTERM signals. diff --git a/bot/src/mastodon.rs b/bot/src/mastodon.rs new file mode 100644 index 0000000..90a9c7f --- /dev/null +++ b/bot/src/mastodon.rs @@ -0,0 +1,34 @@ +use crate::mastodon::api::{PartialMediaResponse, PartialPostStatusResponse, PostStatusRequest}; + +mod api; + +/// The Mastodon client for interacting with the platform. +pub struct MastodonClient { + access_token: String, + client: reqwest::Client, +} + +impl MastodonClient { + /// Creates a new mastodon client from the given access token. + fn new(access_token: String) -> Self { + let client = reqwest::Client::new(); + MastodonClient { + access_token, + client, + } + } + + async fn post_status(&mut self, data: T) -> Result + where + T: Into, + { + unimplemented!() + } + + async fn upload_media_by_url( + &mut self, + image_url: &str, + ) -> Result { + unimplemented!() + } +} diff --git a/bot/src/mastodon/api.rs b/bot/src/mastodon/api.rs new file mode 100644 index 0000000..490e90d --- /dev/null +++ b/bot/src/mastodon/api.rs @@ -0,0 +1,32 @@ +use serde::{Deserialize, Serialize}; + +/// Is a truncated response from Mastodon's /api/v2/media endpoint. +/// See: https://docs.joinmastodon.org/methods/media/#v2 +#[derive(Serialize, Deserialize, Debug)] +pub struct PartialMediaResponse { + pub id: String, + #[serde(rename = "type")] + pub r#type: String, + pub url: String, +} + +/// PostStatusRequest is the request made to post a status on Mastodon. +/// See: https://docs.joinmastodon.org/methods/statuses/#create +#[derive(Serialize, Deserialize, Debug)] +pub struct PostStatusRequest { + pub status: String, + pub language: String, + pub visibility: String, + pub media_ids: Vec, +} + +/// Is a partial response from /api/v1/statuses route. +/// See: https://docs.joinmastodon.org/methods/statuses/#create +#[derive(Serialize, Deserialize, Debug)] +pub struct PartialPostStatusResponse { + pub id: String, + pub created_at: String, + pub visibility: String, + pub uri: String, + pub url: String, +}