Method: Jamf::Computer.application_usage

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

.application_usage(ident, start_date, end_date = nil, api: nil, cnx: Jamf.cnx) ⇒ Hash{Date=>Array<Hash>}

Retrieve Application Usage data for a computer by id, without instantiation.



429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/jamf/api/classic/api_objects/computer.rb', line 429

def self.application_usage(ident, start_date, end_date = nil, api: nil, cnx: Jamf.cnx)
  cnx = api if api

  id = valid_id ident, cnx: cnx
  raise Jamf::NoSuchItemError, "No computer matches identifier: #{ident}" unless id

  end_date ||= start_date
  start_date = Jamf.parse_time start_date
  end_date = Jamf.parse_time end_date

  start_date = start_date.strftime APPLICATION_USAGE_DATE_FMT
  end_date = end_date.strftime APPLICATION_USAGE_DATE_FMT

  data = cnx.c_get(APPLICATION_USAGE_RSRC + "/id/#{id}/#{start_date}_#{end_date}")

  parsed_data = {}

  data[APPLICATION_USAGE_KEY].each do |day_hash|
    date = Date.parse day_hash[:date]
    parsed_data[date] = day_hash[:apps]
  end

  parsed_data
end