atproto_api

Crates.ioatproto_api
lib.rsatproto_api
version0.2.0
sourcesrc
created_at2023-08-30 00:31:51.186548
updated_at2023-08-30 18:36:50.8555
descriptionA simple ATProto implementation in Rust
homepagehttps://atproto.com
repositoryhttps://git.sr.ht/~jordanreger/atproto_api
max_upload_size
id958542
size48,108
GlassKit (glasskit-owner)

documentation

README

[!NOTE] This code is mostly useable. A few things are missing, like .post() and some other minor methods, but the majority is complete.

atproto_api

Crates.io

A simple ATProto implementation in Rust

AtpAgent

AtpAgent is meant for general AT Protocol operations.

Initialization

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 }

Get request

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] BskyAgent is currently on the backburner, as it's a superset of AtpAgent. If for some reason you're using this library now, please use AtpAgent instead of BskyAgent for the time being.

License

This code is licensed under the BSD 3-Clause license. You can view the license here.

Commit count: 0

cargo fmt