Class: Tempest::AvatarStore::DefaultProfileClient

Inherits:
Object
  • Object
show all
Defined in:
lib/tempest/avatar_store.rb

Overview

Standalone profile client used by Tempest::CLI.

AvatarStore resolves DIDs on a background thread, so the client it uses must be thread-safe. We deliberately do NOT use Tempest::XRPCClient here, because the underlying Tempest::HTTP layer is built on Async::HTTP::Internet whose Fibers cannot be resumed from a thread other than the one that created them — calling it from our worker yields ‘FiberError: fiber called across threads`.

app.bsky.actor.getProfile is served unauthenticated by public.api.bsky.app, so we don’t need a session here.

Constant Summary collapse

HOST =
"https://public.api.bsky.app".freeze

Instance Method Summary collapse

Instance Method Details

#get(nsid, query: nil) ⇒ Object

Raises:



39
40
41
42
43
44
45
46
47
# File 'lib/tempest/avatar_store.rb', line 39

def get(nsid, query: nil)
  uri = URI("#{HOST}/xrpc/#{nsid}")
  uri.query = URI.encode_www_form(query) if query && !query.empty?
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
    http.get(uri.request_uri, "Accept" => "application/json")
  end
  raise Tempest::APIError.new(res.code.to_i, { "error" => res.message }) unless res.is_a?(Net::HTTPSuccess)
  JSON.parse(res.body)
end