class Vultr::Collection

Attributes

data[R]
next_cursor[R]
prev_cursor[R]
total[R]

Public Class Methods

from_response(response, key:, type:) click to toggle source
# File lib/vultr/collection.rb, line 5
def self.from_response(response, key:, type:)
  body = response.body
  new(
    data: body[key].map { |attrs| type.new(attrs) },
    total: body.dig("meta", "total"),
    next_cursor: body.dig("meta", "links", "next"),
    prev_cursor: body.dig("meta", "links", "prev")
  )
end
new(data:, total:, next_cursor:, prev_cursor:) click to toggle source
# File lib/vultr/collection.rb, line 15
def initialize(data:, total:, next_cursor:, prev_cursor:)
  @data = data
  @total = total
  @next_cursor = next_cursor.empty? ? nil : next_cursor
  @prev_cursor = prev_cursor.empty? ? nil : prev_cursor
end