class FreeAgent::Collection

Attributes

data[R]
total[R]

Public Class Methods

from_response(response, type:, key: nil) click to toggle source
# File lib/free_agent/collection.rb, line 5
def self.from_response(response, type:, key: nil)
  body = response.body

  if key.is_a?(String)
    data = body[key].map { |attrs| type.new(attrs) }
  else
    data = body.map { |attrs| type.new(attrs) }
  end

  total = response.headers["X-total-count"]

  new(
    data: data,
    total: total
  )
end
new(data:, total:) click to toggle source
# File lib/free_agent/collection.rb, line 22
def initialize(data:, total:)
  @data = data
  @total = total
end