Class: Jamf::InventoryPreloadRecord

Inherits:
OAPISchemas::InventoryPreloadRecordV2 show all
Extended by:
Filterable
Includes:
ChangeLog, CollectionResource
Defined in:
lib/jamf/api/jamf_pro/api_objects/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

SEARCH_RESULT_OBJECT =

The OAPI object class we get back from a ‘list’ query to get the whole collection, or a subset of it. It contains a :results key which is an array of data for objects of the parent class.

Jamf::OAPISchemas::InventoryPreloadRecordSearchResultsV2
POST_OBJECT =

The OAPI object class we send with a POST request to make a new member of the collection in Jamf. This is usually the same as the parent class.

Jamf::OAPISchemas::InventoryPreloadRecordV2
PUT_OBJECT =

The OAPI object class we send with a PUT request to change an object in Jamf by specifying all its values. Most updates happen this way, and this is usually the same as the parent class

Jamf::OAPISchemas::InventoryPreloadRecordV2
LIST_PATH =

The path for GETting the list of all objects in the collection, possibly filtered, sorted, and/or paged REQUIRED for all collection resources

GET_PATH, POST_PATH, PUT_PATH, PATCH_PATH, and DELETE_PATH are automatically assumed from the LIST_PATH if they follow the standards:

  • GET_PATH = “#LIST_PATH/id”

    • fetch an object from the collection

  • POST_PATH = LIST_PATH

    • create a new object in the collection

  • PUT_PATH = “#LIST_PATH/id”

    • update an object passing all its values back. Most objects use this or PATCH but not both

  • PATCH_PATH = “#LIST_PATH/id”

    • update an object passing some of its values back Most objects use this or PUT but not both

  • DELETE_PATH = “#LIST_PATH/id”

    • delete an object from the collection

If those paths differ from the standards, the constants must be defined here

'v2/inventory-preload/records'.freeze
ALT_IDENTIFIERS =

Identifiers not marked in the superclass’s OAPI_PROPERTIES constant which usually only identifies ‘:id’

%i[serialNumber].freeze
FILTER_KEYS =

Must define this when extending Filterable

OAPI_PROPERTIES.keys - [:extensionAttributes]
DEVICE_TYPE_COMPUTER =
'Computer'.freeze
DEVICE_TYPE_MOBILE_DEV =
'Mobile Device'.freeze
DEVICE_TYPE_UNKNOWN =
'Unknown'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cnxJamf::Connection (readonly) Originally defined in module JPAPIResource

Returns the API connection thru which we deal with this resource.

Returns:

  • (Jamf::Connection)

    the API connection thru which we deal with this resource.

#delete_pathString (readonly) Originally defined in module CollectionResource

Returns The path for deleting a this item from the collection in the JPAPI.

Returns:

  • (String)

    The path for deleting a this item from the collection in the JPAPI

#get_pathString (readonly) Originally defined in module JPAPIResource

Returns The path for fetching this thing from the JPAPI

this gets set in the constructor in the CollectionResource or SingletonResource mixins.

Returns:

  • (String)

    The path for fetching this thing from the JPAPI

    this gets set in the constructor in the CollectionResource or SingletonResource mixins

#post_pathString (readonly) Originally defined in module CollectionResource

Returns The path for creating a new item in the collection in the JPAPI.

Returns:

  • (String)

    The path for creating a new item in the collection in the JPAPI

#update_pathString (readonly) Originally defined in module JPAPIResource

Returns The path for updating this thing from the JPAPI

this gets set in the constructor in the CollectionResource or SingletonResource mixins

We use ‘update_path’ because some items are updated via a PUT_PATH and others via a PATCH_PATH. When this gets set, it will contain the appropriate one.

Returns:

  • (String)

    The path for updating this thing from the JPAPI

    this gets set in the constructor in the CollectionResource or SingletonResource mixins

    We use ‘update_path’ because some items are updated via a PUT_PATH and others via a PATCH_PATH. When this gets set, it will contain the appropriate one.

Class Method Details

.filter_keysObject Originally defined in module Filterable

.history_path(_id) ⇒ Object

InvPreload Recs have a non-standard /history path



120
121
122
# File 'lib/jamf/api/jamf_pro/api_objects/inventory_preload_record.rb', line 120

def self.history_path(_id)
  'v2/inventory-preload/history'
end

Instance Method Details

#add_change_log_note(note) ⇒ Object Originally defined in module ChangeLog

Instance Methods

wrappers for the class methods, which pass the id and cnx should work on Singleton Resources since @id will be nil but @cnx will be set.

#change_log(sort: nil, filter: nil) ⇒ Object Originally defined in module ChangeLog

#change_log_countObject Originally defined in module ChangeLog

#change_log_pager(page_size: Jamf::Pager::DEFAULT_PAGE_SIZE, sort: nil, filter: nil) ⇒ Object Originally defined in module ChangeLog

#clearObject

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



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/jamf/api/jamf_pro/api_objects/inventory_preload_record.rb', line 152

def clear
  OAPI_PROPERTIES.each do |attr_name, attr_def|
    next unless attr_def[:nil_ok]

    if attr_name == :extensionAttributes
      self.extensionAttributes = []
      next
    end
    send "#{attr}=", nil
  end
end

#deleteObject Originally defined in module CollectionResource

#exist?Boolean Originally defined in module CollectionResource

Returns:

  • (Boolean)

#ext_attrsObject

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



145
146
147
148
149
# File 'lib/jamf/api/jamf_pro/api_objects/inventory_preload_record.rb', line 145

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

#history_path(_id) ⇒ Object

InvPreload Recs have a non-standard /history path



165
166
167
# File 'lib/jamf/api/jamf_pro/api_objects/inventory_preload_record.rb', line 165

def history_path(_id)
  raise Jamf::UnsupportedError, 'InventoryPreloadRecords do not have individual change logs. Use Jamf::InventoryPreloadRecord.change_log'
end

#initialize(**data) ⇒ Object Originally defined in module CollectionResource

Constructor

#pretty_print_instance_variablesArray Originally defined in module JPAPIResource

Remove large cached items from the instance_variables used to create pretty-print (pp) output.

Returns:

  • (Array)

    the desired instance_variables

#remove_ext_attr(ea_name) ⇒ Object

remove an EA totally (vs setting its value to nil)



139
140
141
142
# File 'lib/jamf/api/jamf_pro/api_objects/inventory_preload_record.rb', line 139

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

#saveObject Originally defined in module JPAPIResource

TODO: error handling

#set_ext_attr(ea_name, new_val) ⇒ void

This method returns an undefined value.

Parameters:



130
131
132
133
134
135
136
# File 'lib/jamf/api/jamf_pro/api_objects/inventory_preload_record.rb', line 130

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

#to_sString Originally defined in module CollectionResource

A meaningful string representation of this object

Returns: