Class: Fediverse::Collection

Inherits:
Array
  • Object
show all
Defined in:
lib/fediverse/collection.rb

Constant Summary collapse

PUBLIC =
'https://www.w3.org/ns/activitystreams#Public'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/fediverse/collection.rb', line 5

def id
  @id
end

#total_itemsObject (readonly)

Returns the value of attribute total_items.



5
6
7
# File 'lib/fediverse/collection.rb', line 5

def total_items
  @total_items
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/fediverse/collection.rb', line 5

def type
  @type
end

Class Method Details

.fetch(url) ⇒ Object



7
8
9
# File 'lib/fediverse/collection.rb', line 7

def self.fetch(url)
  new.fetch(url)
end

Instance Method Details

#fetch(url) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fediverse/collection.rb', line 11

def fetch(url)
  json = Fediverse::Request.dereference(url)
  @total_items = json['totalItems']
  @id = json['id']
  @type = json['type']
  raise Errors::NotACollection unless %w[OrderedCollection Collection].include?(@type)

  next_url = json['first']
  while next_url
    page = Fediverse::Request.dereference(next_url)
    concat(page['orderedItems'] || page['items'])
    next_url = page['next']
  end
  self
end