bsky_sdk/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![doc = include_str!("../README.md")]
3pub mod agent;
4pub mod error;
5pub mod moderation;
6pub mod preference;
7pub mod record;
8#[cfg_attr(docsrs, doc(cfg(feature = "rich-text")))]
9#[cfg(feature = "rich-text")]
10pub mod rich_text;
11
12pub use agent::BskyAgent;
13pub use atrium_api as api;
14pub use error::{Error, Result};
15
16#[cfg(test)]
17mod tests {
18    use atrium_api::xrpc::http::{Request, Response};
19    use atrium_api::xrpc::types::Header;
20    use atrium_api::xrpc::{HttpClient, XrpcClient};
21
22    pub const FAKE_CID: &str = "bafyreiclp443lavogvhj3d2ob2cxbfuscni2k5jk7bebjzg7khl3esabwq";
23
24    pub struct MockClient;
25
26    impl HttpClient for MockClient {
27        async fn send_http(
28            &self,
29            request: Request<Vec<u8>>,
30        ) -> core::result::Result<
31            Response<Vec<u8>>,
32            Box<dyn std::error::Error + Send + Sync + 'static>,
33        > {
34            if let Some(handle) = request.uri().query().and_then(|s| s.strip_prefix("handle=")) {
35                Ok(Response::builder()
36                    .status(200)
37                    .header(Header::ContentType, "application/json")
38                    .body(format!(r#"{{"did": "did:fake:{}"}}"#, handle).as_bytes().to_vec())?)
39            } else {
40                Ok(Response::builder().status(500).body(Vec::new())?)
41            }
42        }
43    }
44
45    impl XrpcClient for MockClient {
46        fn base_uri(&self) -> String {
47            String::new()
48        }
49    }
50}