scaffold mastodon client
This commit is contained in:
parent
05ab839ed6
commit
287beed7d6
3 changed files with 67 additions and 0 deletions
|
@ -12,6 +12,7 @@ use std::thread;
|
||||||
|
|
||||||
mod bluesky;
|
mod bluesky;
|
||||||
mod cli;
|
mod cli;
|
||||||
|
mod mastodon;
|
||||||
|
|
||||||
//noinspection DuplicatedCode
|
//noinspection DuplicatedCode
|
||||||
/// Sets up a signal handler in a separate thread to handle SIGINT and SIGTERM signals.
|
/// Sets up a signal handler in a separate thread to handle SIGINT and SIGTERM signals.
|
||||||
|
|
34
bot/src/mastodon.rs
Normal file
34
bot/src/mastodon.rs
Normal file
|
@ -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<T>(&mut self, data: T) -> Result<PartialPostStatusResponse, anyhow::Error>
|
||||||
|
where
|
||||||
|
T: Into<PostStatusRequest>,
|
||||||
|
{
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn upload_media_by_url(
|
||||||
|
&mut self,
|
||||||
|
image_url: &str,
|
||||||
|
) -> Result<PartialMediaResponse, anyhow::Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
32
bot/src/mastodon/api.rs
Normal file
32
bot/src/mastodon/api.rs
Normal file
|
@ -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<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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,
|
||||||
|
}
|
Loading…
Reference in a new issue