Class: BlueskyAccount

Inherits:
Object
  • Object
show all
Defined in:
app/bluesky_account.rb

Instance Method Summary collapse

Constructor Details

#initializeBlueskyAccount

Returns a new instance of BlueskyAccount.



5
6
7
# File 'app/bluesky_account.rb', line 5

def initialize
  @sky = BlueskyClient.new
end

Instance Method Details

#delete_record_at(uri) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'app/bluesky_account.rb', line 43

def delete_record_at(uri)
  repo, collection, rkey = uri.split('/')[2..4]

  begin
    @sky.post_request('com.atproto.repo.deleteRecord', { repo: repo, collection: collection, rkey: rkey })
  rescue JSON::ParserError
    # todo
  end
end

#didObject



9
10
11
# File 'app/bluesky_account.rb', line 9

def did
  @sky.user.did
end

#fetch_likesObject



29
30
31
32
33
34
35
36
37
# File 'app/bluesky_account.rb', line 29

def fetch_likes
  json = @sky.get_request('com.atproto.repo.listRecords', {
    repo: @sky.user.did,
    collection: 'app.bsky.feed.like',
    limit: 100
  })

  json['records']
end

#fetch_record(repo, collection, rkey) ⇒ Object



39
40
41
# File 'app/bluesky_account.rb', line 39

def fetch_record(repo, collection, rkey)
  @sky.get_request('com.atproto.repo.getRecord', { repo: repo, collection: collection, rkey: rkey })
end

#login_with_password(handle, password) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/bluesky_account.rb', line 13

def (handle, password)
  did = DID.resolve_handle(handle)
  if did.nil?
    puts "Error: couldn't resolve handle #{handle.inspect}"
    exit 1
  end

  pds = did.get_document.pds_endpoint.gsub('https://', '')

  @sky.host = pds
  @sky.user.id = handle
  @sky.user.pass = password

  @sky.
end