···
use anyhow::{Context, Result};
3
-
use reqwest::{Client as HttpClient, header::{HeaderMap, HeaderValue, AUTHORIZATION}};
4
+
header::{HeaderMap, HeaderValue, AUTHORIZATION},
5
+
Client as HttpClient,
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(),
71
-
let response = self.http_client
.header("Content-Type", "application/json")
···
pub async fn publish_blip(&self, content: &str) -> Result<String> {
96
-
let session = self.session.as_ref()
.context("Not authenticated. Please run 'thought login' first.")?;
105
+
let timestamp = Utc::now().to_rfc3339().replace("+00:00", "Z");
let record = BlipRecord {
record_type: "stream.thought.blip".to_string(),
content: content.to_string(),
102
-
created_at: Utc::now().to_rfc3339().replace("+00:00", "Z"),
110
+
created_at: timestamp.clone(),
let request = CreateRecordRequest {
repo: session.did.clone(),
collection: "stream.thought.blip".to_string(),
108
-
record: serde_json::to_value(&record)
109
-
.context("Failed to serialize blip record")?,
116
+
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")?,
122
-
HeaderValue::from_static("application/json"),
127
+
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
125
-
let response = self.http_client
129
+
let response = self
···
.context("Failed to parse create record response")?;
144
-
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())