Method: JSS::Computer.application_usage
- Defined in:
- lib/jss/api_object/computer.rb
.application_usage(ident, start_date, end_date = nil, api: JSS.api) ⇒ Hash{Date=>Array<Hash>}
Retrieve Application Usage data for a computer by id, without instantiation.
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/jss/api_object/computer.rb', line 431 def self.application_usage(ident, start_date, end_date = nil, api: JSS.api) id = valid_id ident, api: api raise "No computer matches identifier: #{ident}" unless id end_date ||= start_date start_date = Time.parse start_date if start_date.is_a? String end_date = Time.parse end_date if end_date.is_a? String raise JSS::InvalidDataError, 'Invalid Start or End Date' unless ([start_date.class, end_date.class] - APPLICATION_USAGE_DATE_CLASSES).empty? start_date = start_date.strftime APPLICATION_USAGE_DATE_FMT end_date = end_date.strftime APPLICATION_USAGE_DATE_FMT data = api.get_rsrc(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 |