tangled
alpha
login
or
join now
alephcubed.com
/
jacquard
forked from
nonbinary.computer/jacquard
0
fork
atom
A better Rust ATProto crate
0
fork
atom
overview
issues
pulls
pipelines
readme for main crate
Orual
5 months ago
4e3ee1ee
df48cd53
+89
-1
1 changed file
expand all
collapse all
unified
split
crates
jacquard
src
lib.rs
+89
-1
crates/jacquard/src/lib.rs
···
1
1
-
#![doc = include_str!("../../../README.md")]
1
1
+
//! # Jacquard
2
2
+
//!
3
3
+
//! A suite of Rust crates for the AT Protocol.
4
4
+
//!
5
5
+
//!
6
6
+
//! ## Goals
7
7
+
//!
8
8
+
//! - Validated, spec-compliant, easy to work with, and performant baseline types (including typed at:// uris)
9
9
+
//! - Batteries-included, but easily replaceable batteries.
10
10
+
//! - Easy to extend with custom lexicons
11
11
+
//! - lexicon Value type for working with unknown atproto data (dag-cbor or json)
12
12
+
//! - order of magnitude less boilerplate than some existing crates
13
13
+
//! - either the codegen produces code that's easy to work with, or there are good handwritten wrappers
14
14
+
//! - didDoc type with helper methods for getting handles, multikey, and PDS endpoint
15
15
+
//! - use as much or as little from the crates as you need
16
16
+
//!
17
17
+
//!
18
18
+
//! ## Example
19
19
+
//!
20
20
+
//! Dead simple api client. Logs in, prints the latest 5 posts from your timeline.
21
21
+
//!
22
22
+
//! ```rust
23
23
+
//! # use clap::Parser;
24
24
+
//! # use jacquard::CowStr;
25
25
+
//! use jacquard::api::app_bsky::feed::get_timeline::GetTimeline;
26
26
+
//! use jacquard::api::com_atproto::server::create_session::CreateSession;
27
27
+
//! use jacquard::client::{AuthenticatedClient, Session, XrpcClient};
28
28
+
//! # use miette::IntoDiagnostic;
29
29
+
//!
30
30
+
//! # #[derive(Parser, Debug)]
31
31
+
//! # #[command(author, version, about = "Jacquard - AT Protocol client demo")]
32
32
+
//! # struct Args {
33
33
+
//! # /// Username/handle (e.g., alice.mosphere.at)
34
34
+
//! # #[arg(short, long)]
35
35
+
//! # username: CowStr<'static>,
36
36
+
//! #
37
37
+
//! # /// PDS URL (e.g., https://bsky.social)
38
38
+
//! # #[arg(long, default_value = "https://bsky.social")]
39
39
+
//! # pds: CowStr<'static>,
40
40
+
//! #
41
41
+
//! # /// App password
42
42
+
//! # #[arg(short, long)]
43
43
+
//! # password: CowStr<'static>,
44
44
+
//! # }
45
45
+
//!
46
46
+
//! #[tokio::main]
47
47
+
//! async fn main() -> miette::Result<()> {
48
48
+
//! let args = Args::parse();
49
49
+
//!
50
50
+
//! // Create HTTP client
51
51
+
//! let mut client = AuthenticatedClient::new(reqwest::Client::new(), args.pds);
52
52
+
//!
53
53
+
//! // Create session
54
54
+
//! let session = Session::from(
55
55
+
//! client
56
56
+
//! .send(
57
57
+
//! CreateSession::new()
58
58
+
//! .identifier(args.username)
59
59
+
//! .password(args.password)
60
60
+
//! .build(),
61
61
+
//! )
62
62
+
//! .await?
63
63
+
//! .into_output()?,
64
64
+
//! );
65
65
+
//!
66
66
+
//! println!("logged in as {} ({})", session.handle, session.did);
67
67
+
//! client.set_session(session);
68
68
+
//!
69
69
+
//! // Fetch timeline
70
70
+
//! println!("\nfetching timeline...");
71
71
+
//! let timeline = client
72
72
+
//! .send(GetTimeline::new().limit(5).build())
73
73
+
//! .await?
74
74
+
//! .into_output()?;
75
75
+
//!
76
76
+
//! println!("\ntimeline ({} posts):", timeline.feed.len());
77
77
+
//! for (i, post) in timeline.feed.iter().enumerate() {
78
78
+
//! println!("\n{}. by {}", i + 1, post.post.author.handle);
79
79
+
//! println!(
80
80
+
//! " {}",
81
81
+
//! serde_json::to_string_pretty(&post.post.record).into_diagnostic()?
82
82
+
//! );
83
83
+
//! }
84
84
+
//!
85
85
+
//! Ok(())
86
86
+
//! }
87
87
+
//! ```
88
88
+
//!
89
89
+
2
90
#![warn(missing_docs)]
3
91
4
92
/// XRPC client traits and basic implementation