Module: Jamf::CollectionResource Abstract

Includes:
JPAPIResource
Included in:
APIClient, APIRole, ComputerPrestage, DeviceEnrollment, InventoryPreloadRecord, JBuilding, JPackage, ManagedSoftwareUpdates::Plan, MobileDevicePrestage
Defined in:
lib/jamf/api/jamf_pro/mixins/collection_resource.rb

Overview

This module is abstract.

A Collection Resource in Jamf Pro

See Resource for general info about API resources.

Collection resources have more than one resource within them, and those can (usually) be created and deleted as well as fetched and updated. The entire collection (or a part of it) can also be retrieved as an Array. When the whole collection is retrieved, the result may be cached for future use.

# Subclassing

## Creatability, & Deletability

Sometimes the API doesn’t support creation of new members of the collection. If that’s the case, just extend the subclass with Jamf::Uncreatable and the ‘.create’ class method will raise an error.

Similarly for deletion of members: if the API doesn’t have a way to delete them, extend the subclass with Jamf::Undeletable

See also Jamf::JSONObject, which talks about extending subclasses with Jamf::Immutable

## Bulk Deletion

Some collection resources have a resource for bulk deletion, passing in a JSON array of ids to delete.

If so, just define a BULK_DELETE_RSRC, and the .delete class method will use it, rather than making multiple calls to delete individual items. See Jamf::Category::BULK_DELETE_RSRC for an example

Defined Under Namespace

Modules: ClassMethods

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)

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



659
660
661
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 659

def delete_path
  @delete_path
end

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

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



654
655
656
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 654

def post_path
  @post_path
end

#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

.included(includer) ⇒ Object

when this module is included, also extend our Class Methods



50
51
52
53
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 50

def self.included(includer)
  Jamf.load_msg "--> #{includer} is including Jamf::CollectionResource"
  includer.extend(ClassMethods)
end

Instance Method Details

#deleteObject



677
678
679
680
681
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 677

def delete
  raise Jamf::UnsupportedError, "Deleting #{self} objects is not currently supported" unless self.class.deletable?

  @cnx.jp_delete delete_path
end

#exist?Boolean

Returns:

  • (Boolean)


672
673
674
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 672

def exist?
  !@id.nil?
end

#initialize(**data) ⇒ Object

Constructor



663
664
665
666
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 663

def initialize(**data)
  super
  set_api_paths
end

#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

#saveObject Originally defined in module JPAPIResource

TODO: error handling

#to_sString

A meaningful string representation of this object

Returns:



687
688
689
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 687

def to_s
  "#{self.class}@#{cnx.host}, id: #{@id}"
end