Skip to content

Commit

Permalink
feat: Switch PDS API endpoint dynamically (#88)
Browse files Browse the repository at this point in the history
* Add SessionStore trait, which AtpAgent uses

* Restructure agent inner wrappers

* Move agent::tests

* Implement Store::update_endpoint

* Update docs
  • Loading branch information
sugyan authored Nov 23, 2023
1 parent 3a32abc commit d5aa306
Show file tree
Hide file tree
Showing 6 changed files with 475 additions and 228 deletions.
2 changes: 1 addition & 1 deletion atrium-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ agent = ["tokio/sync"]
atrium-xrpc-client = "0.2.0"
futures = "0.3.28"
serde_json = "1.0.107"
tokio = { version = "1.33.0", features = ["test-util", "macros"] }
tokio = { version = "1.33.0", features = ["macros", "rt-multi-thread"] }

[package.metadata.docs.rs]
all-features = true
Expand Down
31 changes: 30 additions & 1 deletion atrium-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use atrium_api::client::AtpServiceClient;
use atrium_api::com::atproto::server::create_session::Input;
use atrium_xrpc_client::reqwest::ReqwestClient;
#[tokio::main(flavor = "current_thread")]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AtpServiceClient::new(ReqwestClient::new("https://bsky.social"));
let result = client
Expand All @@ -34,3 +34,32 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
```

### `AtpAgent`

While `AtpServiceClient` can be used for simple XRPC calls, it is better to use `AtpAgent`, which has practical features such as session management.

```rust,no_run
use atrium_api::agent::{store::MemorySessionStore, AtpAgent};
use atrium_xrpc_client::reqwest::ReqwestClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let agent = AtpAgent::new(
ReqwestClient::new("https://bsky.social"),
MemorySessionStore::default(),
);
agent.login("[email protected]", "hunter2").await?;
let result = agent
.api
.app
.bsky
.actor
.get_profile(atrium_api::app::bsky::actor::get_profile::Parameters {
actor: "bsky.app".into(),
})
.await?;
println!("{:?}", result);
Ok(())
}
```
Loading

0 comments on commit d5aa306

Please sign in to comment.