2 unstable releases

0.2.0 Aug 30, 2023
0.1.1 Aug 30, 2023
0.1.0 Aug 30, 2023

#3 in #bsky

BSD-3-Clause

14KB
167 lines

[!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.

Dependencies

~4–15MB
~222K SLoC