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

Returns:



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

#assetTagString

Returns:



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

#barCode1String

Returns:



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

#barCode2String

Returns:



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

#buildingString

Returns:



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

#departmentString

Returns:



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

#deviceTypeString

Returns:



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

#emailAddressString

Returns:



# 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

Returns:



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

#idInteger (readonly)

Returns:

  • (Integer)


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

#leaseExpirationString

Returns:



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

#lifeExpectancyString

Returns:



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

#phoneNumberString

Returns:



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

#poDateString

Returns:



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

#poNumberString

Returns:



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

#positionString

Returns:



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

#purchasePriceString

Returns:



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

#purchasingAccountString

Returns:



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

#purchasingContactString

Returns:



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

#roomString

Returns:



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

#serialNumberString

Returns:



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

#usernameString

Returns:



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

#vendorString

Returns:



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

#warrantyExpirationString

Returns:



# 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.

Parameters:

  • note (String)

    The note to add. It cannot be empty.

.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.

Parameters:

  • sort (String, Array<String>) (defaults to: nil)

    Server-side sorting criteria in the format: property:direction, where direction is ‘asc’ or ‘desc’. Multiple properties are supported, either as separate strings in an Array, or a single string, comma separated.

  • filter (String) (defaults to: nil)

    An RSQL filter string. Not all change_log resources currently support filters, and if they don’t, this will be ignored.

  • paged (Boolean) (defaults to: nil)

    Defaults to false. Returns only the first page of ‘page_size` log entries. Use #next_page_of_change_log to retrieve each

  • page_size (Integer) (defaults to: nil)

    How many log entries are returned per page? Minimum is 1, maximum is 2000, default is 100. Ignored unless paged: is truthy. Note: the final page may contain fewer entries than the page_size

  • refresh (Boolean) (defaults to: false)

    re-fetch and re-cache the full list of all entries. Ignored if paged:, page_size:, sort:, or filter: are used.

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    The API connection to use, default: Jamf.cnx. If this is an instance of a Collection Resource, this is always the connection from which it was fetched.

Returns:

.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

Parameters:

  • cnx (Jamf::Connection) (defaults to: Jamf.cnx)

    The API connection to use, default: Jamf.cnx This is ignored for instances of Collection Resources, which always use the same connection from which they were fetched.

Returns:

  • (Integer)

    How many changelog entries exist?

.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.

Returns:

  • (Array<Jamf::ChangeHistoryEntry>)

    The next page of the change and note history for this resource

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)

Parameters:



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