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

'v1'.freeze
RSRC_PATH =
'inventory-preload'.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: :integer,
    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 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

Returns:



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

#assetTagString

Returns:



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

#barCode1String

Returns:



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

#barCode2String

Returns:



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

#buildingString

Returns:



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

#departmentString

Returns:



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

#deviceTypeString

Returns:



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

#emailAddressString

Returns:



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

#extensionAttributesJamf::InventoryPreloadExtensionAttribute



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

#fullNameString

Returns:



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

#idInteger (readonly)

Returns:

  • (Integer)


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

#leaseExpirationString

Returns:



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

#lifeExpectancyString

Returns:



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

#phoneNumberString

Returns:



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

#poDateString

Returns:



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

#poNumberString

Returns:



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

#positionString

Returns:



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

#purchasePriceString

Returns:



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

#purchasingAccountString

Returns:



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

#purchasingContactString

Returns:



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

#roomString

Returns:



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

#serialNumberString

Returns:



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

#usernameString

Returns:



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

#warrantyExpirationString

Returns:



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

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, it is recached after adding the note.

Parameters:

  • note (String)

    The note to add. It cannot be empty.

.change_log(refresh = false, cnx: Jamf.cnx) ⇒ Array<Jamf::ChangeHistoryEntry> Originally defined in module ChangeLog

The change and note history for this resource.

The history is cached internally and only re-fetched when a truthy parameter is given.

Parameters:

  • refresh (Boolean) (defaults to: false)

    re-fetch and re-cache the history

Returns:

  • (Array<Jamf::ChangeHistoryEntry>)

    The change and note history for this resource

Instance Method Details

#clearObject

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



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 262

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.



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

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

#remove_ext_attr(ea_name) ⇒ Object

remove an EA value



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

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)

Parameters:



243
244
245
246
# File 'lib/jamf/api/resources/collection_resources/inventory_preload_record.rb', line 243

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