class Jamf::WebHook
A webhook as defined in JamfPro.
Constants
- CONTENT_TYPES
the content types available for webhooks, internally we use Symbols, but the API wants the proper MIME strings
- EVENTS
The available webhook events.
- OBJECT_HISTORY_OBJECT_TYPE
the object type for this object in the object history table. See {APIObject#add_object_history_entry}
- RSRC_BASE
The base for REST resources of this class
- RSRC_LIST_KEY
the hash key used for the JSON list output of all objects in the
JSS
- RSRC_OBJECT_KEY
The hash key used for the JSON object output. It’s also used in various error messages
Attributes
@return [Symbols] the content_type
, one of the keys of CONTENT_TYPES
@return [Boolean] is this webhook enabled?
@return [Boolean] is this webhook enabled?
@return [String] the event name to which this webhook responds
@return [String] the URL accessed by this webhook
Public Class Methods
See Jamf::APIObject#initialize
Jamf::APIObject::new
# File lib/jamf/api/classic/api_objects/web_hook.rb 110 def initialize(**args) 111 super 112 113 # now we have pkg_data with something in it, so fill out the instance vars 114 @enabled = @init_data[:enabled] 115 @url = @init_data[:url] 116 @content_type = CONTENT_TYPES.invert[@init_data[:content_type]] 117 @event = @init_data[:event] 118 119 # defaults 120 @content_type ||= :json 121 @enabled = false if @enabled.nil? 122 end
Public Instance Methods
Set the content_type
sent to the url Must be one of the keys of CONTENT_TYPES
, i.e. :xml or :json
@param new_val The new content_type
@return [void]
# File lib/jamf/api/classic/api_objects/web_hook.rb 167 def content_type=(new_val) 168 return nil if new_val == @content_type 169 raise Jamf::InvalidDataError, "content_type must be one of :#{CONTENT_TYPES.keys.join ', :'}" unless \ 170 CONTENT_TYPES.keys.include? new_val 171 @content_type = new_val 172 @need_to_update = true 173 end
Disable this webhook, saving the new state immediately
@return [void]
# File lib/jamf/api/classic/api_objects/web_hook.rb 206 def disable 207 raise Jamf::NoSuchItemError, 'Save the webhook before disabling it' unless @in_jss 208 self.enabled = false 209 save 210 end
Enable this webhook, saving the new state immediately
@return [void]
# File lib/jamf/api/classic/api_objects/web_hook.rb 196 def enable 197 raise Jamf::NoSuchItemError, 'Save the webhook before enabling it' unless @in_jss 198 self.enabled = true 199 save 200 end
Set the enabled state of this webhook
@param new_val the new state
@return [void]
# File lib/jamf/api/classic/api_objects/web_hook.rb 136 def enabled=(new_val) 137 return nil if new_val == @enabled 138 new_val = false if new_val.to_s.empty? 139 raise Jamf::InvalidDataError, "enabled must be boolean 'true' or 'false'" unless \ 140 Jamf::TRUE_FALSE.include? new_val 141 @enabled = new_val 142 @need_to_update = true 143 end
Set the event handled by this webhook Must be a member of the EVENTS
Array
@param new_val The event name
@return [void]
# File lib/jamf/api/classic/api_objects/web_hook.rb 182 def event=(new_val) 183 return nil if new_val == @event 184 raise Jamf::InvalidDataError, 'Unknown webhook event' unless EVENTS.include? new_val 185 @event = new_val 186 @need_to_update = true 187 end
Set the URL accessed by this webhook
@param new_val The new URL
@return [void]
# File lib/jamf/api/classic/api_objects/web_hook.rb 151 def url=(new_val) 152 return nil if new_val == @url 153 # handy - from http://stackoverflow.com/questions/1805761/check-if-url-is-valid-ruby#1805788 154 url_ok = new_val =~ /\A#{URI.regexp(%w(http https))}\z/ 155 raise Jamf::InvalidDataError, 'New value is not a valid http(s) url' unless url_ok && url_ok.zero? 156 @url = new_val 157 @need_to_update = true 158 end
Private Instance Methods
Return the REST XML for this webhook, with the current values, for saving or updating
# File lib/jamf/api/classic/api_objects/web_hook.rb 225 def rest_xml 226 validate_before_save 227 doc = REXML::Document.new Jamf::Connection::XML_HEADER 228 webhook = doc.add_element 'webhook' 229 webhook.add_element('name').text = @name 230 webhook.add_element('enabled').text = @enabled 231 webhook.add_element('url').text = @url 232 webhook.add_element('content_type').text = CONTENT_TYPES[@content_type] 233 webhook.add_element('event').text = @event 234 doc.to_s 235 end
# File lib/jamf/api/classic/api_objects/web_hook.rb 237 def validate_before_save 238 raise 'url must be a valid http(s) URL String' unless @url.is_a? String 239 raise 'event must be a valid event name from Jamf::WebHook::EVENTS' unless EVENTS.include? @event 240 end