Module: Jamf::Pageable

Included in:
CollectionResource
Defined in:
lib/jamf/api/mixins/pageable.rb

Overview

methods for dealing with paged collection GET requests

Constant Summary collapse

DFT_PAGE_SIZE =

# When This is included def self.included(klass)

puts "Pageable was included by #{klass}"

end

# When this is exdended def self.extended(klass)

puts "Pageable was extended by #{klass}"

end

100
MIN_PAGE_SIZE =
1
MAX_PAGE_SIZE =
2000
PAGE_SIZE_RANGE =
(MIN_PAGE_SIZE..MAX_PAGE_SIZE).freeze

Instance Method Summary collapse

Instance Method Details

#collection_count(rsrc, cnx: Jamf.cnx) ⇒ Integer

Returns How many items exist in this collection?.

Parameters:

  • rsrc (String)

    The collection resource GET endpoint

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    The API connection to use

Returns:

  • (Integer)

    How many items exist in this collection?



55
56
57
58
59
# File 'lib/jamf/api/mixins/pageable.rb', line 55

def collection_count(rsrc, cnx: Jamf.cnx)
  # this should only be true for instances of CollectionResources
  cnx = @cnx if @cnx
  cnx.get("#{rsrc}?page=0&page-size=1")[:totalCount]
end

#fetch_collection_page(rsrc, page, page_size, sort, filter, cnx: Jamf.cnx) ⇒ Array<Object>

Get a specific page of a paged collection request, possibly sorted & filtered.

Parameters:

  • rsrc (String)

    The collection resource GET endpoint

  • page (Integer)

    which page to get

  • page_size (Integer)

    how many items per page

  • sort (String, Array<String>)

    server-side sorting parameters

  • filter (String)

    RSQL String limiting the result set

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    The API connection to use

Returns:

  • (Array<Object>)

    The parsed JSON for the requested page



78
79
80
81
82
83
84
# File 'lib/jamf/api/mixins/pageable.rb', line 78

def fetch_collection_page(rsrc, page, page_size, sort, filter, cnx: Jamf.cnx)
  page_size ||= DFT_PAGE_SIZE
  validate_page_params page_size, page
  raw = cnx.get "#{rsrc}?page=#{page}&page-size=#{page_size}#{sort}#{filter}"

  raw[:results]
end