Module: Jamf::CollectionResource Abstract
- Includes:
- JPAPIResource
- Included in:
- ComputerPrestage, DeviceEnrollment, InventoryPreloadRecord, JpBuilding, MobileDevicePrestage
- Defined in:
- lib/jamf/api/jamf_pro/mixins/collection_resource.rb
Overview
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
-
#cnx ⇒ Jamf::Connection
included
from JPAPIResource
readonly
The API connection thru which we deal with this resource.
-
#delete_path ⇒ String
readonly
The path for deleting a this item from the collection in the JPAPI.
-
#get_path ⇒ String
included
from JPAPIResource
readonly
The path for fetching this thing from the JPAPI.
-
#post_path ⇒ String
readonly
The path for creating a new item in the collection in the JPAPI.
-
#update_path ⇒ String
included
from JPAPIResource
readonly
The path for updating this thing from the JPAPI.
Class Method Summary collapse
-
.included(includer) ⇒ Object
when this module is included, also extend our Class Methods.
Instance Method Summary collapse
- #delete ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(**data) ⇒ Object
Constructor.
-
#pretty_print_instance_variables ⇒ Array
included
from JPAPIResource
Remove large cached items from the instance_variables used to create pretty-print (pp) output.
-
#save ⇒ Object
included
from JPAPIResource
TODO: error handling.
-
#to_s ⇒ String
A meaningful string representation of this object.
Instance Attribute Details
#cnx ⇒ Jamf::Connection (readonly) Originally defined in module JPAPIResource
Returns the API connection thru which we deal with this resource.
#delete_path ⇒ String (readonly)
Returns The path for deleting a this item from the collection in the JPAPI.
670 671 672 |
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 670 def delete_path @delete_path end |
#get_path ⇒ String (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.
#post_path ⇒ String (readonly)
Returns The path for creating a new item in the collection in the JPAPI.
665 666 667 |
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 665 def post_path @post_path end |
#update_path ⇒ String (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.
Class Method Details
.included(includer) ⇒ Object
when this module is included, also extend our Class Methods
66 67 68 69 |
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 66 def self.included(includer) Jamf.load_msg "--> #{includer} is including Jamf::CollectionResource" includer.extend(ClassMethods) end |
Instance Method Details
#delete ⇒ Object
688 689 690 691 692 |
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 688 def delete raise Jamf::UnsupportedError, "Deleting #{self} objects is not currently supported" unless self.class.deletable? @cnx.jp_delete delete_path end |
#exist? ⇒ Boolean
683 684 685 |
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 683 def exist? !@id.nil? end |
#initialize(**data) ⇒ Object
Constructor
674 675 676 677 |
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 674 def initialize(**data) super set_api_paths end |
#pretty_print_instance_variables ⇒ Array Originally defined in module JPAPIResource
Remove large cached items from the instance_variables used to create pretty-print (pp) output.
#save ⇒ Object Originally defined in module JPAPIResource
TODO: error handling
#to_s ⇒ String
A meaningful string representation of this object
698 699 700 |
# File 'lib/jamf/api/jamf_pro/mixins/collection_resource.rb', line 698 def to_s "#{self.class}@#{cnx.host}, id: #{@id}" end |