Class: ATProto::Repo

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
RequestUtils
Defined in:
lib/at_protocol/repo.rb,
lib/at_protocol/collection.rb

Overview

typed: true

Defined Under Namespace

Classes: Collection

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequestUtils

at_uri, #create_session_uri, #default_authenticated_headers, #default_headers, #delete_record_uri, #delete_session_uri, #get_paginated_data, #get_post_thread_uri, #get_session_uri, #mute_actor_uri, #query_obj_to_query_params, #refresh_session_uri, #refresh_token_headers, #resolve_handle, #upload_blob_uri

Constructor Details

#initialize(username, pds = "https://bsky.social", open: true, authenticate: nil) ⇒ Repo

Returns a new instance of Repo.

Parameters:

  • username (String)

    The username or DID (Decentralized Identifier) to use.

  • pds (String) (defaults to: "https://bsky.social")

    The URL of the personal data server (default: “bsky.social”).

  • open (Boolean) (defaults to: true)

    Whether to open the repository or not (default: true).

  • authenticate (NilClass, Object) (defaults to: nil)

    Additional authentication data (default: nil).



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/at_protocol/repo.rb', line 14

def initialize(username, pds = "https://bsky.social", open: true, authenticate: nil)
  @pds = T.let pds, String
  @xrpc = T.let(XRPC::Client.new(pds), XRPC::Client)
  if username.start_with?("did:")
    @did = T.let(username, String)
  else
    @did = T.let(resolve_handle(username, pds), String)
  end
  @record_list = []
  if open == true
    open!
  end
end

Instance Attribute Details

#didObject (readonly)

Returns the value of attribute did.



66
67
68
# File 'lib/at_protocol/repo.rb', line 66

def did
  @did
end

#pdsObject (readonly)

Returns the value of attribute pds.



66
67
68
# File 'lib/at_protocol/repo.rb', line 66

def pds
  @pds
end

#record_listObject (readonly)

Returns the value of attribute record_list.



66
67
68
# File 'lib/at_protocol/repo.rb', line 66

def record_list
  @record_list
end

#xrpcObject (readonly)

Returns the value of attribute xrpc.



66
67
68
# File 'lib/at_protocol/repo.rb', line 66

def xrpc
  @xrpc
end

Instance Method Details

#[](collection) ⇒ Object



58
59
60
# File 'lib/at_protocol/repo.rb', line 58

def [](collection)
  Collection.new(repo: self, collection: collection)
end

#describe_repoObject



46
47
48
# File 'lib/at_protocol/repo.rb', line 46

def describe_repo
  @xrpc.get.com_atproto_repo_describeRepo(repo: @did)
end

#did_documentObject



52
53
54
# File 'lib/at_protocol/repo.rb', line 52

def did_document
  describe_repo()["didDoc"]
end

#inspectObject



62
63
64
# File 'lib/at_protocol/repo.rb', line 62

def inspect
  "Repo(#{@did})"
end

#open!Object



28
29
30
# File 'lib/at_protocol/repo.rb', line 28

def open!
  @collections = describe_repo["collections"]
end

#to_sObject



40
41
42
# File 'lib/at_protocol/repo.rb', line 40

def to_s
  @did
end

#to_uriObject



34
35
36
# File 'lib/at_protocol/repo.rb', line 34

def to_uri
  "at://#{@did}/"
end