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



46
47
48
49
50
51
52
53
54
55
# File 'lib/at_protocol/collection.rb', line 46

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

#each(&block) ⇒ Object



57
58
59
# File 'lib/at_protocol/collection.rb', line 57

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

#list(limit = 10) ⇒ Object



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

def list(limit = 10)
  self.repo.xrpc
    .get.com_atproto_repo_listRecords(
      repo: self.repo.did,
      collection: self.collection,
      limit: limit,
    )["records"]
    .map { |record|
    ATProto::Record.from_hash(record)
  }
end

#list_allObject



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

def list_all()
  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 }, cursor: nil) do |record|
    ATProto::Record.from_hash(record)
  end)
end

#to_sObject



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

def to_s
  @collection
end

#to_uriObject



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

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