Method: Jamf::PatchTitle.fetch

Defined in:
lib/jamf/api/classic/api_objects/patch_title.rb

.fetch(identifier = nil, **params) ⇒ Object

Patch titles only have an id-based GET resource in the API. so all other lookup values have to be converted to ID before the call to super

NOTE: The only truely unique identifiers are id and source_name_id



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/jamf/api/classic/api_objects/patch_title.rb', line 317

def self.fetch(identifier = nil, **params)
  # default connection if unspecified
  cnx = params.delete :cnx
  cnx ||= params.delete :api # backward compatibility, deprecated
  cnx ||= Jamf.cnx

  # source: and source_id: are considered the same, source_id: wins
  params[:source_id] ||= params[:source]

  # if given a source name in params[:source_id] this converts it to an id
  if params[:source_id]
    params[:source_id] = Jamf::PatchInternalSource.valid_id(params[:source_id], cnx: cnx)
    params[:source_id] ||= Jamf::PatchExternalSource.valid_id(params[:source_id], cnx: cnx)
  end

  id =
    if identifier
      valid_id identifier, cnx: cnx

    elsif params[:id]
      all_ids(cnx: cnx).include?(params[:id]) ? params[:id] : nil

    elsif params[:source_name_id]
      # TODO: make 'map_all' work with :source_name_id
      # map_all(:source_name_id, to: :id, cnx: cnx)[params[:source_name_id]]
      map_all(:id, to: :source_name_id, cnx: cnx).invert[params[:source_name_id]]

      # WARNING: name_id may not be unique
    elsif params[:name_id]
      # TODO: make 'map_all' work with :source_name_id
      # map_all(:source_name_id, to: :id, cnx: cnx)[params[:source_name_id]]
      map_all(:id, to: :name_id, cnx: cnx).invert[params[:name_id]]

    # WARNING: name_id may not be unique
    elsif params[:name]
      # map_all_ids_to(:name, cnx: cnx).invert[params[:name]]
      map_all(:name, to: :id, cnx: cnx)[params[:name]]
    end

  raise Jamf::NoSuchItemError, "No matching #{name} found" unless id

  super id: id, cnx: cnx
end