#![deny(missing_debug_implementations)]
#![cfg_attr(docsrs, feature(doc_cfg))]
use std::{fmt, str::FromStr};
pub mod default;
pub mod detector;
pub mod entities;
pub mod error;
pub mod firefish;
pub mod friendica;
pub mod gotosocial;
pub mod mastodon;
pub mod megalodon;
pub mod oauth;
pub mod pixelfed;
pub mod pleroma;
pub mod response;
pub mod streaming;
pub use self::megalodon::Megalodon;
use crate::error::Error;
pub use detector::detector;
use serde::{Deserialize, Serialize};
pub use streaming::Streaming;
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub enum SNS {
Mastodon,
Pleroma,
Friendica,
Firefish,
Gotosocial,
Pixelfed,
}
impl fmt::Display for SNS {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SNS::Mastodon => write!(f, "mastodon"),
SNS::Pleroma => write!(f, "pleroma"),
SNS::Friendica => write!(f, "friendica"),
SNS::Firefish => write!(f, "firefish"),
SNS::Gotosocial => write!(f, "gotosocial"),
SNS::Pixelfed => write!(f, "pixelfed"),
}
}
}
impl FromStr for SNS {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"mastodon" => Ok(SNS::Mastodon),
"pleroma" => Ok(SNS::Pleroma),
"friendica" => Ok(SNS::Friendica),
"firefish" => Ok(SNS::Firefish),
"gotosocial" => Ok(SNS::Gotosocial),
"pixelfed" => Ok(SNS::Pixelfed),
&_ => Err(format!("Unknown sns: {}", s)),
}
}
}
pub fn generator(
sns: SNS,
base_url: String,
access_token: Option<String>,
user_agent: Option<String>,
) -> Result<Box<dyn Megalodon + Send + Sync>, Error> {
match sns {
SNS::Pleroma => {
let pleroma = pleroma::Pleroma::new(base_url, access_token, user_agent)?;
Ok(Box::new(pleroma))
}
SNS::Friendica => {
let friendica = friendica::Friendica::new(base_url, access_token, user_agent)?;
Ok(Box::new(friendica))
}
SNS::Mastodon => {
let mastodon = mastodon::Mastodon::new(base_url, access_token, user_agent)?;
Ok(Box::new(mastodon))
}
SNS::Firefish => {
let firefish = firefish::Firefish::new(base_url, access_token, user_agent)?;
Ok(Box::new(firefish))
}
SNS::Gotosocial => {
let gotosocial = gotosocial::Gotosocial::new(base_url, access_token, user_agent)?;
Ok(Box::new(gotosocial))
}
SNS::Pixelfed => {
let pixelfed = pixelfed::Pixelfed::new(base_url, access_token, user_agent)?;
Ok(Box::new(pixelfed))
}
}
}