announcing good-first-issue tags added on @tangled.sh (not affiliated with tangled!)

extract link posting to a helper

+42 -35
+42 -35
src/main.rs
··· 9 9 server::create_session::CreateSession, 10 10 repo::create_record::CreateRecord, 11 11 }, 12 - client::{AuthenticatedClient, Session, XrpcClient}, 12 + client::{HttpClient, AuthenticatedClient, Session, XrpcClient}, 13 13 types::{ 14 14 datetime::Datetime, 15 15 ident::AtIdentifier, ··· 36 36 app_password: String, 37 37 } 38 38 39 - #[tokio::main] 40 - async fn main() -> Result<()> { 41 - env_logger::init(); 42 - let args = Args::parse(); 43 - 44 - 45 - // Create HTTP client 46 - let pds_uri = args.pds.as_str().trim_end_matches('/').to_string().into(); 47 - let mut client = AuthenticatedClient::new(reqwest::Client::new(), pds_uri); 48 - 49 - // Create session 50 - let session = Session::from( 51 - client 52 - .send( 53 - CreateSession::new() 54 - .identifier(&args.identifier) 55 - .password(args.app_password) 56 - .build(), 57 - ) 58 - .await? 59 - .into_output()?, 60 - ); 61 - 62 - println!("logged in as {} ({})", session.handle, session.did); 63 - client.set_session(session); 64 - 65 - let text = "hello from tangled.org/@bad-example.com/hacktober-bot/"; 39 + async fn post_link<C: HttpClient>(client: &AuthenticatedClient<C>, identifier: &AtIdentifier<'_>, pre_text: &str, link: Url) -> Result<()> { 40 + let link_text = link.to_string(); 41 + let text = format!("{pre_text} {link_text}"); 66 42 let link_feature = serde_json::json!({ 67 43 "$type": "app.bsky.richtext.facet#link", 68 - "uri": "https://tangled.org/@bad-example.com/hacktober-bot/", 44 + "uri": link_text, 69 45 }); 70 46 let link_facet = Facet { 71 47 features: vec![Data::from_json(&link_feature)?], 72 48 index: ByteSlice { 73 - byte_start: 11, 74 - byte_end: 54, 49 + byte_start: (pre_text.len() + 1) as i64, 50 + byte_end: text.len() as i64, 75 51 extra_data: Default::default(), 76 52 }, 77 53 extra_data: Default::default(), ··· 93 69 94 70 let json = serde_json::to_value(post)?; 95 71 let data = Data::from_json(&json)?; 96 - let identifier = AtIdentifier::new(&args.identifier)?; 97 72 98 73 println!("\nposting..."); 99 - let wat = client 74 + client 100 75 .send(CreateRecord::new() 101 - .repo(identifier) 76 + .repo(identifier.clone()) 102 77 .collection(Post::nsid()) 103 78 .record(data) 104 79 .build()) 105 80 .await? 106 81 .into_output()?; 107 82 108 - println!("\ngot: {wat:?}"); 83 + Ok(()) 84 + } 85 + 86 + #[tokio::main] 87 + async fn main() -> Result<()> { 88 + env_logger::init(); 89 + let args = Args::parse(); 90 + 91 + 92 + // Create HTTP client 93 + let pds_uri = args.pds.as_str().trim_end_matches('/').to_string().into(); 94 + let mut client = AuthenticatedClient::new(reqwest::Client::new(), pds_uri); 95 + 96 + // Create session 97 + let session = Session::from( 98 + client 99 + .send( 100 + CreateSession::new() 101 + .identifier(&args.identifier) 102 + .password(args.app_password) 103 + .build(), 104 + ) 105 + .await? 106 + .into_output()?, 107 + ); 108 + 109 + println!("logged in as {} ({})", session.handle, session.did); 110 + client.set_session(session); 111 + 112 + let identifier = AtIdentifier::new(&args.identifier)?; 113 + 114 + let u2: Url = "https://bad-example.com".parse()?; 115 + post_link(&client, &identifier, "link test 2: ", u2).await?; 109 116 110 117 Ok(()) 111 118 }