Class: Jamf::InventoryPreloadRecord

Inherits:
CollectionResource show all
Extended by:
ChangeLog
Defined in:
lib/jamf/api/resources/collection_resources/inventory_preload_record.rb

Overview

An Inventory Preload record for a Computer or Mobile Device in Jamf.

Since the JPAPI offers access to these records via JSON as well as CSV uploads, we are implementing JSON access, to stay in line with the rest of how ruby-jss works, and keep things simple.

If you want to use a CSV as your data source, you should use a ruby CSV library, such as the one built in to ruby, and loop thru your CSV records, creating or fetching instances of this class as needed, manipulating them, and saving them.

Constant Summary collapse

RSRC_VERSION =

Constants

'v2'.freeze
RSRC_PATH =
'inventory-preload/records'.freeze
CHANGE_LOG_RSRC =
"#{RSRC_VERSION}/inventory-preload/history".freeze
DEVICE_TYPE_COMPUTER =
'Computer'.freeze
DEVICE_TYPE_MOBILE_DEV =
'Mobile Device'.freeze
DEVICE_TYPE_UNKNOWN =
'Unknown'.freeze
DEVICE_TYPES =
[
  DEVICE_TYPE_COMPUTER,
  DEVICE_TYPE_MOBILE_DEV,
  DEVICE_TYPE_UNKNOWN
].freeze
UNCLEARABLE_ATTRS =

The 'clear' instance method won't change these attrs

%i[id serialNumber deviceType].freeze
OBJECT_MODEL =

Object Model / Attributes See APIObject class documentation for details of how the OBJECT_MODEL hash works.

{

  # @!attribute [r] id
  #   @return [Integer]
  id: {
    class: :j_id,
    identifier: :primary,
    readonly: true
  },

  # @!attribute serialNumber
  #   @return [String]
  serialNumber: {
    class: :string,
    identifier: true,
    validator: :non_empty_string,
    required: true
  },

  # @!attribute deviceType
  #   @return [String]
  deviceType: {
    class: :string,
    enum: Jamf::InventoryPreloadRecord::DEVICE_TYPES,
    required: true
  },

  # @!attribute username
  #   @return [String]
  username: {
    class: :string
  },

  # @!attribute fullName
  #   @return [String]
  fullName: {
    class: :string
  },

  # @!attribute emailAddress
  #   @return [String]
  emailAddress: {
    class: :string
  },

  # @!attribute phoneNumber
  #   @return [String]
  phoneNumber: {
    class: :string
  },

  # @!attribute position
  #   @return [String]
  position: {
    class: :string
  },

  # @!attribute department
  #   @return [String]
  department: {
    class: :string
  },

  # @!attribute building
  #   @return [String]
  building: {
    class: :string
  },

  # @!attribute room
  #   @return [String]
  room: {
    class: :string
  },

  # @!attribute poNumber
  #   @return [String]
  poNumber: {
    class: :string
  },

  # @!attribute poDate
  #   @return [String]
  poDate: {
    class: :string
  },

  # @!attribute warrantyExpiration
  #   @return [String]
  warrantyExpiration: {
    class: :string
  },

  # @!attribute appleCareId
  #   @return [String]
  appleCareId: {
    class: :string
  },

  # @!attribute lifeExpectancy
  #   @return [String]
  lifeExpectancy: {
    class: :string
  },

  # @!attribute purchasePrice
  #   @return [String]
  purchasePrice: {
    class: :string
  },

  # @!attribute purchasingContact
  #   @return [String]
  purchasingContact: {
    class: :string
  },

  # @!attribute purchasingAccount
  #   @return [String]
  purchasingAccount: {
    class: :string
  },

  # @!attribute leaseExpiration
  #   @return [String]
  leaseExpiration: {
    class: :string
  },

  # @!attribute barCode1
  #   @return [String]
  barCode1: {
    class: :string
  },

  # @!attribute barCode2
  #   @return [String]
  barCode2: {
    class: :string
  },

  # @!attribute assetTag
  #   @return [String]
  assetTag: {
    class: :string
  },

  # @!attribute vendor
  #   @return [String]
  vendor: {
    class: :string
  },

  # @!attribute extensionAttributes
  #   @return [Jamf::InventoryPreloadExtensionAttribute]
  extensionAttributes: {
    class: Jamf::InventoryPreloadExtensionAttribute,
    multi: true,
    aliases: %i[eas]
  }

}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Jamf::JSONObject

Instance Attribute Details

#appleCareIdString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 170

#assetTagString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 218

#barCode1String



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 206

#barCode2String



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 212

#buildingString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 140

#departmentString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 134

#deviceTypeString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 96

#emailAddressString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 116

#extensionAttributesJamf::InventoryPreloadExtensionAttribute



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 230

#fullNameString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 110

#idInteger (readonly)



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 79

#leaseExpirationString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 200

#lifeExpectancyString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 176

#phoneNumberString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 122

#poDateString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 158

#poNumberString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 152

#positionString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 128

#purchasePriceString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 182

#purchasingAccountString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 194

#purchasingContactString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 188

#roomString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 146

#serialNumberString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 87

#usernameString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 104

#vendorString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 224

#warrantyExpirationString



# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 164

Class Method Details

.add_change_log_note(note, cnx: Jamf.cnx) ⇒ void Originally defined in module ChangeLog

This method returns an undefined value.

Add a note to this resource's change log.

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

.change_log(sort: nil, filter: nil, paged: nil, page_size: nil, refresh: false, cnx: Jamf.cnx) ⇒ Array<Jamf::ChangeLogEntry> Originally defined in module ChangeLog

The change and note history for this resource. This is a collection of objects as a sub-resource of some primary resource. As such, retriving the change log returns an array of objects, and can be paged, sorted and filtered.

This method is very similar to CollectionResource.all, see the docs for that method for more details

successive page.

.change_log_count(cnx: Jamf.cnx) ⇒ Integer Originally defined in module ChangeLog

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

.next_page_of_change_logArray<Jamf::ChangeHistoryEntry> Originally defined in module ChangeLog

Fetch the next page of a paged #change_log request Returns an empty array if there's been no paged request or if the last one has no more pages.

Instance Method Details

#clearObject

clear all values for this record except id, serialNumber, and deviceType



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 270

def clear
  OBJECT_MODEL.keys.each do |attr|
    next if UNCLEARABLE_ATTRS.include? attr

    if attr == :extensionAttributes
      extensionAttributes = []
      next
    end

    # skip nils
    curr_val = send attr
    next unless curr_val

    send "#{attr}=", nil
  end
end

#ext_attrsObject

a Hash of ea name => ea_value for all eas currently set.



263
264
265
266
267
# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 263

def ext_attrs
  eas = {}
  extensionAttributes.each { |ea| eas[ea.name] = ea.value }
  eas
end

#remove_ext_attr(ea_name) ⇒ Object

remove an EA value



257
258
259
260
# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 257

def remove_ext_attr(ea_name)
  idx = extensionAttributes.index { |ea| ea.name == ea_name }
  extensionAttributes_delete_at idx if idx
end

#set_ext_attr(ea_name, new_val) ⇒ void

This method returns an undefined value.

TODO: validation for ea's existance and value data type, once EAs are implemented in JPAPI (see inventory_preload_extension_attribute.rb)



251
252
253
254
# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 251

def set_ext_attr(ea_name, new_val)
  remove_ext_attr(ea_name)
  extensionAttributes_append Jamf::InventoryPreloadExtensionAttribute.new(name: ea_name, value: new_val)
end