use serde::Serialize; #[derive(Debug, Serialize)] pub struct CohostWebfingerResource { subject: String, aliases: Vec, links: Vec, } #[derive(Debug, Serialize)] pub struct CohostWebfingerProfileLink { rel: String, #[serde(rename = "type")] t_type: String, href: String, } impl CohostWebfingerResource { pub fn new, T: AsRef>(project_id: S, domain: T) -> Self { Self { subject: format!("acct:{}@{}", project_id.as_ref(), domain.as_ref()), aliases: vec![format!("acct:{}@cohost.org", project_id.as_ref())], links: vec![CohostWebfingerProfileLink::new(project_id)], } } } impl CohostWebfingerProfileLink { pub fn new>(project_id: S) -> Self { Self { rel: "http://webfinger.net/rel/profile-page".into(), t_type: "text/html".into(), href: format!("https://cohost.org/{}", project_id.as_ref()), } } } #[test] fn serialize_webfinger_resource() -> Result<(), Box> { let expected_json = include_str!("../samples/corobel/.well-known/webfinger"); let resource: CohostWebfingerResource = CohostWebfingerResource::new("noracodes", "example.com"); let actual_json = serde_json::to_string_pretty(&resource)?; println!("{}", actual_json); assert_eq!(&expected_json, &actual_json); Ok(()) }