Module: Jamf::Filterable

Included in:
APIClient, APIRole, InventoryPreloadRecord, JBuilding, JPackage, ManagedSoftwareUpdates::Plan
Defined in:
lib/jamf/api/jamf_pro/mixins/filterable.rb

Overview

process filter strings for resources with filter request parameters

This should be extended into CollectionResources whose LIST_PATH is filterable

Classes doing so must define the FILTER_KEYS constant, an Array of Symbols of keys from OAPI_PROPERTIES which can be used in filters.

TODO: Actually implement this module in CollectionResources?

Constant Summary collapse

FILTER_PARAM_PREFIX =
'&filter='.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(extender) ⇒ Object



38
39
40
# File 'lib/jamf/api/jamf_pro/mixins/filterable.rb', line 38

def self.extended(extender)
  Jamf.load_msg "--> #{extender} is extending Jamf::Filterable"
end

.parse_url_filter_param(filter) ⇒ String

generate the RSQL filter to put into the url This is callable from anywhere without mixing in.

Parameters:

  • filter (String, nil)

    the filter to apply, or nil. If the filter starts with FILTER_PARAM_PREFIX, it is returned as-is, assuming it is already properly escaped.

Returns:

  • (String)

    the filter to use in the URL, with FILTER_PARAM_PREFIX



52
53
54
55
56
# File 'lib/jamf/api/jamf_pro/mixins/filterable.rb', line 52

def self.parse_url_filter_param(filter)
  return filter if filter.nil? || filter.start_with?(FILTER_PARAM_PREFIX)

  "#{FILTER_PARAM_PREFIX}#{CGI.escape filter}"
end

Instance Method Details

#filter_keysObject



58
59
60
# File 'lib/jamf/api/jamf_pro/mixins/filterable.rb', line 58

def filter_keys
  defined?(self::FILTER_KEYS) ? self::FILTER_KEYS : []
end