module Jamf::JPAPIResource
@see_also Jamf::OAPIObject
Constants
- API_SOURCE
which API do APIObjects come from? The classic equivalent is in
Jamf::APIObject
- NEW_CALLERS
These methods are allowed to call .new
- RSRC_PREVIEW_VERSION
The resource version for previewing new features
Attributes
cnx[R]
@return [Jamf::Connection] the API connection thru which we deal with
this resource.
get_path[R]
@return [String] The path for fetching this thing from the JPAPI
this gets set in the constructor in the CollectionResource or SingletonResource mixins
update_path[R]
@return [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.
Public Class Methods
included(includer)
click to toggle source
when this module is included, also extend our Class Methods
# File lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb 34 def self.included(includer) 35 # TODO: only allow being directly mixed in to CollectionResource and 36 # SingletonResource modules. 37 Jamf.load_msg "--> #{includer} is including Jamf::JPAPIResource" 38 includer.extend(ClassMethods) 39 end
new(**data)
click to toggle source
constructor
Calls superclass method
# File lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb 109 def initialize(**data) 110 @cnx = data.delete :cnx 111 super(**data) 112 end
Public Instance Methods
pretty_print_instance_variables()
click to toggle source
Remove large cached items from the instance_variables used to create pretty-print (pp) output.
@return [Array] the desired instance_variables
Calls superclass method
# File lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb 123 def pretty_print_instance_variables 124 vars = super.sort 125 vars.delete :@cnx 126 vars 127 end
save()
click to toggle source
TODO: error handling
# File lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb 130 def save 131 raise Jamf::UnsupportedError, "#{self.class} objects cannot be changed" unless self.class.mutable? 132 133 if exist? 134 return unless unsaved_changes? 135 136 update_in_jamf 137 else 138 create_in_jamf 139 end 140 141 clear_unsaved_changes 142 143 @id || :saved 144 end
Private Instance Methods
update_in_jamf()
click to toggle source
# File lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb 151 def update_in_jamf 152 if defined? self.class::PUT_OBJECT 153 put_object = self.class::PUT_OBJECT.new(to_jamf) 154 cnx.jp_put(update_path, put_object.to_jamf) 155 156 elsif defined? self.class::PATCH_OBJECT 157 patch_object = self.class::PATCH_OBJECT.new(to_jamf) 158 cnx.jp_patch(update_path, patch_object.to_jamf) 159 160 else 161 raise Jamf::MissingDataError, "Class #{self.class} has not defined a PUT_OBJECT or PATCH_OBJECT" 162 end 163 end