Toot toooooooot (Bluesky-Mastodon cross-poster)
1require 'didkit' 2require_relative 'bluesky_client' 3 4class BlueskyAccount 5 def initialize 6 @sky = BlueskyClient.new 7 end 8 9 def did 10 @sky.user.did 11 end 12 13 def login_with_password(handle, password) 14 did = DID.resolve_handle(handle) 15 if did.nil? 16 puts "Error: couldn't resolve handle #{handle.inspect}" 17 exit 1 18 end 19 20 pds = did.get_document.pds_endpoint.gsub('https://', '') 21 22 @sky.host = pds 23 @sky.user.id = handle 24 @sky.user.pass = password 25 26 @sky.log_in 27 end 28 29 def log_in 30 @sky.log_in 31 end 32 33 def fetch_likes 34 json = @sky.get_request('com.atproto.repo.listRecords', { 35 repo: @sky.user.did, 36 collection: 'app.bsky.feed.like', 37 limit: 100 38 }) 39 40 json['records'] 41 end 42 43 def fetch_record(repo, collection, rkey) 44 @sky.get_request('com.atproto.repo.getRecord', { repo: repo, collection: collection, rkey: rkey }) 45 end 46 47 def fetch_blob(cid) 48 @sky.get_request('com.atproto.sync.getBlob', { did: @sky.user.did, cid: cid }) 49 end 50 51 def delete_record_at(uri) 52 repo, collection, rkey = uri.split('/')[2..4] 53 @sky.post_request('com.atproto.repo.deleteRecord', { repo: repo, collection: collection, rkey: rkey }) 54 end 55end