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 fetch_likes
30 json = @sky.get_request('com.atproto.repo.listRecords', {
31 repo: @sky.user.did,
32 collection: 'app.bsky.feed.like',
33 limit: 100
34 })
35
36 json['records']
37 end
38
39 def fetch_record(repo, collection, rkey)
40 @sky.get_request('com.atproto.repo.getRecord', { repo: repo, collection: collection, rkey: rkey })
41 end
42
43 def delete_record_at(uri)
44 repo, collection, rkey = uri.split('/')[2..4]
45
46 begin
47 @sky.post_request('com.atproto.repo.deleteRecord', { repo: repo, collection: collection, rkey: rkey })
48 rescue JSON::ParserError
49 # todo
50 end
51 end
52end