lib/jss/api_object/management_history.rb in ruby-jss-1.2.0 vs lib/jss/api_object/management_history.rb in ruby-jss-1.2.2

- old
+ new

@@ -291,10 +291,31 @@ def completed_mdm_commands(ident, api: JSS.api) mdm_command_history(ident, :completed, api: api) end # completed_mdm_commands alias completed_commands completed_mdm_commands + # The time of the most recently completed MDM command. + # + # For Mobile Devices, this seems to be the best indicator of the real + # last-contact time, since the last_inventory_update is changed when + # changes are made via the API. + # + # @param ident [Type] The identifier for the object - id, name, sn, udid, etc. + # + # @param api [JSS::APIConnection] The API connection to use for the query + # defaults to the currently active connection + # + # @return [Time, nil] An array of completed MDMCommands + # + def last_mdm_contact(ident, api: JSS.api) + cmds = completed_mdm_commands(ident, api: api) + return nil if cmds.empty? + + JSS.epoch_to_time cmds.map{|cmd| cmd.completed_epoch }.max + end + + # The history of pending mdm commands for a target # # @param ident [Type] The identifier for the object - id, name, sn, udid, etc. # # @param api [JSS::APIConnection] The API connection to use for the query @@ -693,9 +714,17 @@ # def completed_mdm_commands self.class.completed_mdm_commands(@id, api: @api) end # completed_mdm_commands alias completed_commands completed_mdm_commands + + # The time of the last completed mdm command for this object + # + # @see the matching method in {JSS::ManagementHistory::ClassMethods} + # + def last_mdm_contact + self.class.last_mdm_contact(@id, api: @api) + end # completed_mdm_commands # The pending_mdm_commands for this object # # @see the matching method in {JSS::ManagementHistory::ClassMethods} #