diff --git a/bsky-sdk/src/agent.rs b/bsky-sdk/src/agent.rs index e7030ddd..5e9c6ddf 100644 --- a/bsky-sdk/src/agent.rs +++ b/bsky-sdk/src/agent.rs @@ -2,14 +2,14 @@ mod builder; pub mod config; -pub use self::builder::BskyAgentBuilder; +pub use self::builder::BskyAtpAgentBuilder; use self::config::Config; use crate::error::Result; use crate::moderation::util::interpret_label_value_definitions; use crate::moderation::{ModerationPrefsLabeler, Moderator}; use crate::preference::{FeedViewPreferenceData, Preferences, ThreadViewPreferenceData}; -use atrium_api::agent::store::MemorySessionStore; -use atrium_api::agent::{store::SessionStore, AtpAgent}; +use atrium_api::agent::atp_agent::store::MemorySessionStore; +use atrium_api::agent::atp_agent::{store::AtpSessionStore, AtpAgent}; use atrium_api::app::bsky::actor::defs::PreferencesItem; use atrium_api::types::{Object, Union}; use atrium_api::xrpc::XrpcClient; @@ -21,8 +21,8 @@ use std::sync::Arc; /// A Bluesky agent. /// -/// This agent is a wrapper around the [`AtpAgent`] that provides additional functionality for working with Bluesky. -/// For creating an instance of this agent, use the [`BskyAgentBuilder`]. +/// This agent is a wrapper around the [`Agent`](atrium_api::agent::Agent) that provides additional functionality for working with Bluesky. +/// For creating an instance of this agent, use the [`BskyAtpAgentBuilder`]. /// /// # Example /// @@ -40,7 +40,7 @@ use std::sync::Arc; pub struct BskyAgent where T: XrpcClient + Send + Sync, - S: SessionStore + Send + Sync, + S: AtpSessionStore + Send + Sync, { inner: Arc>, } @@ -49,7 +49,7 @@ where pub struct BskyAgent where T: XrpcClient + Send + Sync, - S: SessionStore + Send + Sync, + S: AtpSessionStore + Send + Sync, { inner: Arc>, } @@ -57,16 +57,16 @@ where #[cfg_attr(docsrs, doc(cfg(feature = "default-client")))] #[cfg(feature = "default-client")] impl BskyAgent { - /// Create a new [`BskyAgentBuilder`] with the default client and session store. - pub fn builder() -> BskyAgentBuilder { - BskyAgentBuilder::default() + /// Create a new [`BskyAtpAgentBuilder`] with the default client and session store. + pub fn builder() -> BskyAtpAgentBuilder { + BskyAtpAgentBuilder::default() } } impl BskyAgent where T: XrpcClient + Send + Sync, - S: SessionStore + Send + Sync, + S: AtpSessionStore + Send + Sync, { /// Get the agent's current state as a [`Config`]. pub async fn to_config(&self) -> Config { @@ -248,7 +248,7 @@ where impl Deref for BskyAgent where T: XrpcClient + Send + Sync, - S: SessionStore + Send + Sync, + S: AtpSessionStore + Send + Sync, { type Target = AtpAgent; @@ -260,16 +260,16 @@ where #[cfg(test)] mod tests { use super::*; - use atrium_api::agent::Session; + use atrium_api::agent::atp_agent::AtpSession; #[derive(Clone)] struct NoopStore; - impl SessionStore for NoopStore { - async fn get_session(&self) -> Option { + impl AtpSessionStore for NoopStore { + async fn get_session(&self) -> Option { unimplemented!() } - async fn set_session(&self, _: Session) { + async fn set_session(&self, _: AtpSession) { unimplemented!() } async fn clear_session(&self) { diff --git a/bsky-sdk/src/agent/builder.rs b/bsky-sdk/src/agent/builder.rs index 9e333181..3a870434 100644 --- a/bsky-sdk/src/agent/builder.rs +++ b/bsky-sdk/src/agent/builder.rs @@ -1,25 +1,27 @@ use super::config::Config; use super::BskyAgent; use crate::error::Result; -use atrium_api::agent::store::MemorySessionStore; -use atrium_api::agent::{store::SessionStore, AtpAgent}; +use atrium_api::agent::atp_agent::{ + store::{AtpSessionStore, MemorySessionStore}, + AtpAgent, +}; use atrium_api::xrpc::XrpcClient; #[cfg(feature = "default-client")] use atrium_xrpc_client::reqwest::ReqwestClient; use std::sync::Arc; -/// A builder for creating a [`BskyAgent`]. -pub struct BskyAgentBuilder +/// A builder for creating a [`BskyAtpAgent`]. +pub struct BskyAtpAgentBuilder where T: XrpcClient + Send + Sync, - S: SessionStore + Send + Sync, + S: AtpSessionStore + Send + Sync, { config: Config, store: S, client: T, } -impl BskyAgentBuilder +impl BskyAtpAgentBuilder where T: XrpcClient + Send + Sync, { @@ -29,10 +31,10 @@ where } } -impl BskyAgentBuilder +impl BskyAtpAgentBuilder where T: XrpcClient + Send + Sync, - S: SessionStore + Send + Sync, + S: AtpSessionStore + Send + Sync, { /// Set the configuration for the agent. pub fn config(mut self, config: Config) -> Self { @@ -42,20 +44,20 @@ where /// Set the session store for the agent. /// /// Returns a new builder with the session store set. - pub fn store(self, store: S0) -> BskyAgentBuilder + pub fn store(self, store: S0) -> BskyAtpAgentBuilder where - S0: SessionStore + Send + Sync, + S0: AtpSessionStore + Send + Sync, { - BskyAgentBuilder { config: self.config, store, client: self.client } + BskyAtpAgentBuilder { config: self.config, store, client: self.client } } /// Set the XRPC client for the agent. /// /// Returns a new builder with the XRPC client set. - pub fn client(self, client: T0) -> BskyAgentBuilder + pub fn client(self, client: T0) -> BskyAtpAgentBuilder where T0: XrpcClient + Send + Sync, { - BskyAgentBuilder { config: self.config, store: self.store, client } + BskyAtpAgentBuilder { config: self.config, store: self.store, client } } pub async fn build(self) -> Result> { let agent = AtpAgent::new(self.client, self.store); @@ -91,7 +93,7 @@ where #[cfg_attr(docsrs, doc(cfg(feature = "default-client")))] #[cfg(feature = "default-client")] -impl Default for BskyAgentBuilder { +impl Default for BskyAtpAgentBuilder { /// Create a new builder with the default client and session store. /// /// Default client is [`ReqwestClient`] and default session store is [`MemorySessionStore`]. @@ -103,10 +105,10 @@ impl Default for BskyAgentBuilder { #[cfg(test)] mod tests { use super::*; - use atrium_api::agent::Session; + use atrium_api::agent::atp_agent::AtpSession; use atrium_api::com::atproto::server::create_session::OutputData; - fn session() -> Session { + fn session() -> AtpSession { OutputData { access_jwt: String::new(), active: None, @@ -124,11 +126,11 @@ mod tests { struct MockSessionStore; - impl SessionStore for MockSessionStore { - async fn get_session(&self) -> Option { + impl AtpSessionStore for MockSessionStore { + async fn get_session(&self) -> Option { Some(session()) } - async fn set_session(&self, _: Session) {} + async fn set_session(&self, _: AtpSession) {} async fn clear_session(&self) {} } @@ -137,13 +139,13 @@ mod tests { async fn default() -> Result<()> { // default build { - let agent = BskyAgentBuilder::default().build().await?; + let agent = BskyAtpAgentBuilder::default().build().await?; assert_eq!(agent.get_endpoint().await, "https://bsky.social"); assert_eq!(agent.get_session().await, None); } // with store { - let agent = BskyAgentBuilder::default().store(MockSessionStore).build().await?; + let agent = BskyAtpAgentBuilder::default().store(MockSessionStore).build().await?; assert_eq!(agent.get_endpoint().await, "https://bsky.social"); assert_eq!( agent.get_session().await.map(|session| session.data.handle), @@ -152,7 +154,7 @@ mod tests { } // with config { - let agent = BskyAgentBuilder::default() + let agent = BskyAtpAgentBuilder::default() .config(Config { endpoint: "https://example.com".to_string(), ..Default::default() @@ -172,12 +174,13 @@ mod tests { // default build { - let agent = BskyAgentBuilder::new(MockClient).build().await?; + let agent = BskyAtpAgentBuilder::new(MockClient).build().await?; assert_eq!(agent.get_endpoint().await, "https://bsky.social"); } // with store { - let agent = BskyAgentBuilder::new(MockClient).store(MockSessionStore).build().await?; + let agent = + BskyAtpAgentBuilder::new(MockClient).store(MockSessionStore).build().await?; assert_eq!(agent.get_endpoint().await, "https://bsky.social"); assert_eq!( agent.get_session().await.map(|session| session.data.handle), @@ -186,7 +189,7 @@ mod tests { } // with config { - let agent = BskyAgentBuilder::new(MockClient) + let agent = BskyAtpAgentBuilder::new(MockClient) .config(Config { endpoint: "https://example.com".to_string(), ..Default::default() diff --git a/bsky-sdk/src/agent/config.rs b/bsky-sdk/src/agent/config.rs index a804e729..51f5951f 100644 --- a/bsky-sdk/src/agent/config.rs +++ b/bsky-sdk/src/agent/config.rs @@ -1,12 +1,11 @@ //! Configuration for the [`BskyAgent`](super::BskyAgent). mod file; -use std::future::Future; - +pub use self::file::FileStore; use crate::error::{Error, Result}; -use atrium_api::agent::Session; -pub use file::FileStore; +use atrium_api::agent::atp_agent::AtpSession; use serde::{Deserialize, Serialize}; +use std::future::Future; /// Configuration data struct for the [`BskyAgent`](super::BskyAgent). #[derive(Debug, Clone, Serialize, Deserialize)] @@ -14,7 +13,7 @@ pub struct Config { /// The base URL for the XRPC endpoint. pub endpoint: String, /// The session data. - pub session: Option, + pub session: Option, /// The labelers header values. pub labelers_header: Option>, /// The proxy header for service proxying. diff --git a/bsky-sdk/src/record.rs b/bsky-sdk/src/record.rs index 1a3cac92..3d5788a3 100644 --- a/bsky-sdk/src/record.rs +++ b/bsky-sdk/src/record.rs @@ -5,7 +5,7 @@ use std::future::Future; use crate::error::{Error, Result}; use crate::BskyAgent; -use atrium_api::agent::store::SessionStore; +use atrium_api::agent::atp_agent::store::AtpSessionStore; use atrium_api::com::atproto::repo::{ create_record, delete_record, get_record, list_records, put_record, }; @@ -16,7 +16,7 @@ use atrium_api::xrpc::XrpcClient; pub trait Record where T: XrpcClient + Send + Sync, - S: SessionStore + Send + Sync, + S: AtpSessionStore + Send + Sync, { fn list( agent: &BskyAgent, @@ -45,7 +45,7 @@ macro_rules! record_impl { impl Record for $record where T: XrpcClient + Send + Sync, - S: SessionStore + Send + Sync, + S: AtpSessionStore + Send + Sync, { async fn list( agent: &BskyAgent, @@ -162,7 +162,7 @@ macro_rules! record_impl { impl Record for $record_data where T: XrpcClient + Send + Sync, - S: SessionStore + Send + Sync, + S: AtpSessionStore + Send + Sync, { async fn list( agent: &BskyAgent, @@ -273,9 +273,9 @@ record_impl!( #[cfg(test)] mod tests { use super::*; - use crate::agent::BskyAgentBuilder; + use crate::agent::BskyAtpAgentBuilder; use crate::tests::FAKE_CID; - use atrium_api::agent::Session; + use atrium_api::agent::atp_agent::AtpSession; use atrium_api::com::atproto::server::create_session::OutputData; use atrium_api::types::string::Datetime; use atrium_api::xrpc::http::{Request, Response}; @@ -321,8 +321,8 @@ mod tests { struct MockSessionStore; - impl SessionStore for MockSessionStore { - async fn get_session(&self) -> Option { + impl AtpSessionStore for MockSessionStore { + async fn get_session(&self) -> Option { Some( OutputData { access_jwt: String::from("access"), @@ -339,13 +339,13 @@ mod tests { .into(), ) } - async fn set_session(&self, _: Session) {} + async fn set_session(&self, _: AtpSession) {} async fn clear_session(&self) {} } #[tokio::test] async fn actor_profile() -> Result<()> { - let agent = BskyAgentBuilder::new(MockClient).store(MockSessionStore).build().await?; + let agent = BskyAtpAgentBuilder::new(MockClient).store(MockSessionStore).build().await?; // create let output = atrium_api::app::bsky::actor::profile::RecordData { avatar: None, @@ -377,7 +377,7 @@ mod tests { #[tokio::test] async fn feed_post() -> Result<()> { - let agent = BskyAgentBuilder::new(MockClient).store(MockSessionStore).build().await?; + let agent = BskyAtpAgentBuilder::new(MockClient).store(MockSessionStore).build().await?; // create let output = atrium_api::app::bsky::feed::post::RecordData { created_at: Datetime::now(), @@ -409,7 +409,7 @@ mod tests { #[tokio::test] async fn graph_follow() -> Result<()> { - let agent = BskyAgentBuilder::new(MockClient).store(MockSessionStore).build().await?; + let agent = BskyAtpAgentBuilder::new(MockClient).store(MockSessionStore).build().await?; // create let output = atrium_api::app::bsky::graph::follow::RecordData { created_at: Datetime::now(), diff --git a/bsky-sdk/src/record/agent.rs b/bsky-sdk/src/record/agent.rs index 30a2f626..23e7ec04 100644 --- a/bsky-sdk/src/record/agent.rs +++ b/bsky-sdk/src/record/agent.rs @@ -1,7 +1,7 @@ use super::Record; use crate::error::{Error, Result}; use crate::BskyAgent; -use atrium_api::agent::store::SessionStore; +use atrium_api::agent::atp_agent::store::AtpSessionStore; use atrium_api::com::atproto::repo::{create_record, delete_record}; use atrium_api::record::KnownRecord; use atrium_api::types::string::RecordKey; @@ -10,7 +10,7 @@ use atrium_api::xrpc::XrpcClient; impl BskyAgent where T: XrpcClient + Send + Sync, - S: SessionStore + Send + Sync, + S: AtpSessionStore + Send + Sync, { /// Create a record with various types of data. /// For example, the Record families defined in [`KnownRecord`](atrium_api::record::KnownRecord) are supported. diff --git a/bsky-sdk/src/rich_text.rs b/bsky-sdk/src/rich_text.rs index f1783722..6bf6bd9e 100644 --- a/bsky-sdk/src/rich_text.rs +++ b/bsky-sdk/src/rich_text.rs @@ -2,7 +2,7 @@ mod detection; use crate::agent::config::Config; -use crate::agent::BskyAgentBuilder; +use crate::agent::BskyAtpAgentBuilder; use crate::error::Result; use atrium_api::app::bsky::richtext::facet::{ ByteSliceData, Link, MainFeaturesItem, Mention, MentionData, Tag, @@ -204,7 +204,7 @@ impl RichText { } /// Detect facets in the text and set them. pub async fn detect_facets(&mut self, client: impl XrpcClient + Send + Sync) -> Result<()> { - let agent = BskyAgentBuilder::new(client) + let agent = BskyAtpAgentBuilder::new(client) .config(Config { endpoint: PUBLIC_API_ENDPOINT.into(), ..Default::default() }) .build() .await?;