Class: ATProto::Repo::Collection

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

Instance Method Summary collapse

Methods included from ATProto::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

Instance Method Details

#[](rkey) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/at_protocol/collection.rb', line 34

def [](rkey)
  ATProto::Record.from_uri(
    T.must(
      at_uri(
        "at://#{self.repo.did}/#{@collection}/#{rkey}"
      )
    ),
    self.repo.pds
  )
end

#each(&block) ⇒ Object



45
46
47
# File 'lib/at_protocol/collection.rb', line 45

def each(&block)
  list_all.each(&block)
end

#list(count = nil) ⇒ Object



14
15
16
17
18
# File 'lib/at_protocol/collection.rb', line 14

def list(count = nil)
  T.must(get_paginated_data(self.repo, :com_atproto_repo_listRecords.to_s, key: "records", params: { repo: self.repo.to_s, collection: self.to_s }, count: count, cursor: nil) do |record|
    ATProto::Record.from_hash(record)
  end)
end

#to_sObject



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

def to_s
  @collection
end

#to_uriObject



22
23
24
# File 'lib/at_protocol/collection.rb', line 22

def to_uri
  "at://#{self.repo.did}/#{self.collection}/"
end