class AxTrack::Collection

Attributes

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

Public Class Methods

from_response(json_response, key:, type: ) click to toggle source

key is the subset of the json_response for which to create an array type is the class Type to wrap the results from key

# File lib/ax_track/collection.rb, line 7
def self.from_response(json_response, key:, type: )
  body = json_response.body
  new(data: body[key].map { |attrs| type.new(attrs ) },
      total: body.dig('count'),
      next_cursor: body.dig('next'),
      prev_cursor: body.dig('previous'))
end
new(data:, total:, next_cursor:, prev_cursor:) click to toggle source
# File lib/ax_track/collection.rb, line 15
def initialize(data:, total:, next_cursor:, prev_cursor:)
  @data = data
  @total = total
  @next_cursor = next_cursor.nil? || next_cursor.empty? ? nil : next_cursor
  @prev_cursor = prev_cursor.nil? || prev_cursor.empty? ? nil : prev_cursor
end