| Crates.io | atproto_api |
| lib.rs | atproto_api |
| version | 0.2.0 |
| created_at | 2023-08-30 00:31:51.186548+00 |
| updated_at | 2023-08-30 18:36:50.8555+00 |
| description | A simple ATProto implementation in Rust |
| homepage | https://atproto.com |
| repository | https://git.sr.ht/~jordanreger/atproto_api |
| max_upload_size | |
| id | 958542 |
| size | 48,108 |
[!NOTE] This code is mostly useable. A few things are missing, like
.post()and some other minor methods, but the majority is complete.
A simple ATProto implementation in Rust
AtpAgentAtpAgent is meant for general AT Protocol operations.
It can be initialized like this:
#[macro_use]
extern crate dotenv_codegen;
use serde_json::json
use atproto_api::{Agent, AtpAgent};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let agent = AtpAgent::new("https://fjall.net".to_string());
println!("{:?}", agent);
Ok(())
}
// AtpAgent { service: "https://fjall.net/", session: None }
You can perform a get request by doing the following:
// macros
use dotenv_codegen::dotenv;
use serde_json::json;
use atproto_api::{Agent, AtpAgent};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let agent = AtpAgent::new("https://bsky.social".to_string());
let agent = agent
.login(
dotenv!("BLUESKY_IDENTIFIER").to_string(),
dotenv!("BLUESKY_PASSWORD").to_string(),
)
.await?;
let record = json!({
"repo": "fjall.net",
"collection": "app.bsky.feed.post",
"rkey": "3k653jvvxlw2v"
});
let res = agent
.get("com.atproto.repo.getRecord".to_string(), record)
.await?;
println!("{:?}", res);
Ok(())
}
The first parameter is a lexicon, the specific ones you can view by scrolling down to the bottom of the page and looking through the "Lexicons" section. The second parameter is a record, which is a JSON object that contains the other important information (in the case of com.atproto.repo.getRecord, that's repo, collection, and rkey).
BskyAgent[!NOTE]
BskyAgentis currently on the backburner, as it's a superset ofAtpAgent. If for some reason you're using this library now, please useAtpAgentinstead ofBskyAgentfor the time being.
This code is licensed under the BSD 3-Clause license. You can view the license here.