···
use anyhow::{Context, Result};
-
use reqwest::{Client as HttpClient, header::{HeaderMap, HeaderValue, AUTHORIZATION}};
use serde::{Deserialize, Serialize};
···
pub async fn login(&mut self, credentials: &Credentials) -> Result<()> {
let login_url = format!("{}/xrpc/com.atproto.server.createSession", self.base_url);
let request = LoginRequest {
identifier: credentials.username.clone(),
password: credentials.password.clone(),
-
let response = self.http_client
.header("Content-Type", "application/json")
···
pub async fn publish_blip(&self, content: &str) -> Result<String> {
-
let session = self.session.as_ref()
.context("Not authenticated. Please run 'thought login' first.")?;
let record = BlipRecord {
record_type: "stream.thought.blip".to_string(),
content: content.to_string(),
-
created_at: Utc::now().to_rfc3339().replace("+00:00", "Z"),
let request = CreateRecordRequest {
repo: session.did.clone(),
collection: "stream.thought.blip".to_string(),
-
record: serde_json::to_value(&record)
-
.context("Failed to serialize blip record")?,
let create_url = format!("{}/xrpc/com.atproto.repo.createRecord", self.base_url);
let mut headers = HeaderMap::new();
HeaderValue::from_str(&format!("Bearer {}", session.access_jwt))
.context("Invalid authorization header")?,
-
HeaderValue::from_static("application/json"),
-
let response = self.http_client
···
.context("Failed to parse create record response")?;
-
Ok(create_response.uri)
pub fn is_authenticated(&self) -> bool {
···
pub fn get_user_did(&self) -> Option<String> {
self.session.as_ref().map(|s| s.did.clone())
···
use anyhow::{Context, Result};
+
header::{HeaderMap, HeaderValue, AUTHORIZATION},
use serde::{Deserialize, Serialize};
···
pub async fn login(&mut self, credentials: &Credentials) -> Result<()> {
let login_url = format!("{}/xrpc/com.atproto.server.createSession", self.base_url);
let request = LoginRequest {
identifier: credentials.username.clone(),
password: credentials.password.clone(),
.header("Content-Type", "application/json")
···
pub async fn publish_blip(&self, content: &str) -> Result<String> {
.context("Not authenticated. Please run 'thought login' first.")?;
+
let timestamp = Utc::now().to_rfc3339().replace("+00:00", "Z");
let record = BlipRecord {
record_type: "stream.thought.blip".to_string(),
content: content.to_string(),
+
created_at: timestamp.clone(),
let request = CreateRecordRequest {
repo: session.did.clone(),
collection: "stream.thought.blip".to_string(),
+
record: serde_json::to_value(&record).context("Failed to serialize blip record")?,
let create_url = format!("{}/xrpc/com.atproto.repo.createRecord", self.base_url);
let mut headers = HeaderMap::new();
HeaderValue::from_str(&format!("Bearer {}", session.access_jwt))
.context("Invalid authorization header")?,
+
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
···
.context("Failed to parse create record response")?;
pub fn is_authenticated(&self) -> bool {
···
pub fn get_user_did(&self) -> Option<String> {
self.session.as_ref().map(|s| s.did.clone())