Class: Envato::Collection

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, items:, total:) ⇒ Collection

Returns a new instance of Collection.



19
20
21
22
23
# File 'lib/envato/collection.rb', line 19

def initialize(data:, items:, total:)
  @data   = data
  @items  = items
  @total  = total
end

Instance Attribute Details

#dataObject (readonly)

TODO: links: { next_page_url, prev_page_url, first_page_url, last_page_url } TODO: total_hits: TODO: took:



8
9
10
# File 'lib/envato/collection.rb', line 8

def data
  @data
end

#itemsObject (readonly)

TODO: links: { next_page_url, prev_page_url, first_page_url, last_page_url } TODO: total_hits: TODO: took:



8
9
10
# File 'lib/envato/collection.rb', line 8

def items
  @items
end

#totalObject (readonly)

TODO: links: { next_page_url, prev_page_url, first_page_url, last_page_url } TODO: total_hits: TODO: took:



8
9
10
# File 'lib/envato/collection.rb', line 8

def total
  @total
end

Class Method Details

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



10
11
12
13
14
15
16
17
# File 'lib/envato/collection.rb', line 10

def self.from_response(response, key:, type:)
  body = response.body
  new(
    data: body[key].map {|attrs| type.new(attrs) },
    items: body["items"],
    total: body["total"]
  )
end