Class: Prodigi::Collection

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, has_more:, next_url:) ⇒ Collection

Returns a new instance of Collection.



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

def initialize(data:, has_more:, next_url:)
  @data = data
  @has_more = has_more
  if @has_more == true; @next_url = next_url else @next_url = nil end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/prodigi/collection.rb', line 3

def data
  @data
end

#has_moreObject (readonly)

Returns the value of attribute has_more.



3
4
5
# File 'lib/prodigi/collection.rb', line 3

def has_more
  @has_more
end

#next_urlObject (readonly)

Returns the value of attribute next_url.



3
4
5
# File 'lib/prodigi/collection.rb', line 3

def next_url
  @next_url
end

Class Method Details

.from_response(response, key:, type:) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/prodigi/collection.rb', line 5

def self.from_response(response, key:, type:)
  body = response.body
  new(
    data: body[key].map { |attrs| type.new(attrs) },
    has_more: body.dig("hasMore"),
    next_url: body.dig("nextUrl")
  )
end