Module: Jamf::ChangeLog::ClassMethods

Defined in:
lib/jamf/api/jamf_pro/mixins/change_log.rb

Overview

Class Methods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(extender) ⇒ Object



102
103
104
# File 'lib/jamf/api/jamf_pro/mixins/change_log.rb', line 102

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

Instance Method Details

#add_change_log_note(note, id: nil, cnx: Jamf.cnx) ⇒ Jamf::ChangeLogEntry

Add an entry with a note to this object’s change log.

If the change history has been cached already, the cache is flushed after adding the note.

Parameters:

  • note (String)

    The note to add. It cannot be empty.

Returns:



115
116
117
118
119
120
121
122
123
# File 'lib/jamf/api/jamf_pro/mixins/change_log.rb', line 115

def add_change_log_note(note, id: nil, cnx: Jamf.cnx)
  note_to_send = POST_NOTE_OBJECT.new note: Jamf::Validate.non_empty_string(note)

  result = cnx.jp_post history_path(id), note_to_send.to_jamf

  # flush the cached data, forces reload when next accessed, to get new note
  @cached_change_log = nil
  HISTORY_ENTRY_OBJECT.new result
end

#change_log(id: nil, sort: nil, filter: nil, cnx: Jamf.cnx) ⇒ Array<Jamf::ChangeLogEntry>

The entire change and note history for this resource

Parameters:

  • id (String, Integer) (defaults to: nil)

    For Collection Items that have a change log This is the id of the item. Omit this param for singletons, or collections which have a single change log.

  • sort (String, Array<String>) (defaults to: nil)

    Server-side sorting criteria in the format: property:direction, where direction is ‘asc’ or ‘desc’. Multiple properties are supported, either as separate strings in an Array, or a single string, comma separated.

  • filter (String) (defaults to: nil)

    An RSQL filter string. Not all change_log resources currently support filters, and if they don’t, this will be ignored.

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

    The API connection to use, default: Jamf.cnx. If this is an instance of a Collection Resource, this is always the connection from which it was fetched.

Returns:



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/jamf/api/jamf_pro/mixins/change_log.rb', line 145

def change_log(id: nil, sort: nil, filter: nil, cnx: Jamf.cnx)
  sort &&= Jamf::Sortable.parse_url_sort_param(sort)
  filter &&= Jamf::Filterable.parse_url_filter_param(filter)

  Jamf::Pager.all_pages(
    list_path: history_path(id),
    sort: sort,
    filter: filter,
    instantiate: Jamf::ChangeLogEntry,
    cnx: cnx
  )
end

#change_log_pager(page_size: Jamf::Pager::DEFAULT_PAGE_SIZE, id: nil, sort: nil, filter: nil, cnx: Jamf.cnx) ⇒ Jamf::Pager

Return a Jamf::Pager object for retrieving all change log entries in smaller groups.

For most parameters, see .change_log

Parameters:

  • page_size (Integer) (defaults to: Jamf::Pager::DEFAULT_PAGE_SIZE)

    The pager object returns results in groups of this many entries. Minimum is 1, maximum is 2000, default is 100 Note: the final page of data may contain fewer items than the page_size

Returns:

  • (Jamf::Pager)

    An object from which you can retrieve sequential or arbitrary pages from the collection.



170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/jamf/api/jamf_pro/mixins/change_log.rb', line 170

def change_log_pager(page_size: Jamf::Pager::DEFAULT_PAGE_SIZE, id: nil, sort: nil, filter: nil, cnx: Jamf.cnx)
  sort &&= Jamf::Sortable.parse_url_sort_param(sort)
  filter &&= Jamf::Filterable.parse_url_filter_param(filter)

  Jamf::Pager.new(
    page_size: page_size,
    list_path: history_path(id),
    sort: sort,
    filter: filter,
    instantiate: Jamf::ChangeLogEntry,
    cnx: cnx
  )
end

#change_log_size(id: nil, cnx: Jamf.cnx) ⇒ Integer

how many change log entries are there? needed when using paged #change_log calls

Parameters:

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

    The API connection to use, default: Jamf.cnx This is ignored for instances of Collection Resources, which always use the same connection from which they were fetched.

Returns:

  • (Integer)

    How many changelog entries exist?



193
194
195
196
197
# File 'lib/jamf/api/jamf_pro/mixins/change_log.rb', line 193

def change_log_size(id: nil, cnx: Jamf.cnx)
  search_path = "#{history_path(id)}?page=0&page-size=1"
  search_result = SEARCH_RESULTS_OBJECT.new cnx.jp_get(search_path)
  search_result.totalCount
end

#history_path(id = nil) ⇒ String

Returns The path to get or post change logs for this object.

Returns:

  • (String)

    The path to get or post change logs for this object



201
202
203
204
205
206
207
# File 'lib/jamf/api/jamf_pro/mixins/change_log.rb', line 201

def history_path(id = nil)
  if id
    "#{get_path}/#{id}/#{DFT_HISTORY_PATH}"
  else
    "#{get_path}/#{DFT_HISTORY_PATH}"
  end
end