ceres: a small planet in a giant solar system
32
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 61 lines 1.7 kB view raw
1use anyhow::Context; 2use jacquard::IntoStatic; 3use jacquard::common::xrpc::XrpcEndpoint; 4use reqwest::Client; 5 6use crate::lexicons::blue_microcosm::links::get_backlink_dids::{ 7 GetBacklinkDidsOutput, GetBacklinkDidsRequest, 8}; 9 10pub async fn get_backlink_dids( 11 client: &Client, 12 host: &str, 13 subject: &str, 14 source: &str, 15 limit: Option<i64>, 16 cursor: Option<&str>, 17) -> anyhow::Result<GetBacklinkDidsOutput<'static>> { 18 let url = format!( 19 "{}{}", 20 host.trim_end_matches('/'), 21 GetBacklinkDidsRequest::PATH, 22 ); 23 24 let mut query: Vec<(&str, String)> = Vec::with_capacity(4); 25 query.push(("subject", subject.to_string())); 26 query.push(("source", source.to_string())); 27 if let Some(limit) = limit { 28 query.push(("limit", limit.to_string())); 29 } 30 if let Some(cursor) = cursor { 31 query.push(("cursor", cursor.to_string())); 32 } 33 34 let resp = client 35 .get(&url) 36 .header(reqwest::header::CONTENT_TYPE, "application/json") 37 .header(reqwest::header::ACCEPT, "application/json") 38 .query(&query) 39 .send() 40 .await 41 .context("constellation getBacklinkDids request")?; 42 43 let status = resp.status(); 44 let bytes = resp 45 .bytes() 46 .await 47 .context("constellation getBacklinkDids read")?; 48 49 if !status.is_success() { 50 anyhow::bail!( 51 "constellation getBacklinkDids: status={} body={}", 52 status, 53 String::from_utf8_lossy(&bytes) 54 ); 55 } 56 57 let parsed: GetBacklinkDidsOutput<'_> = 58 serde_json::from_slice(&bytes).context("constellation getBacklinkDids parse")?; 59 60 Ok(parsed.into_static()) 61}