-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Switch PDS API endpoint dynamically (#88)
* Add SessionStore trait, which AtpAgent uses * Restructure agent inner wrappers * Move agent::tests * Implement Store::update_endpoint * Update docs
- Loading branch information
Showing
6 changed files
with
475 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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(()) | ||
} | ||
``` |
Oops, something went wrong.