Class: Chook::Event
- Inherits:
-
Object
- Object
- Chook::Event
- Defined in:
- lib/chook/event.rb
Overview
This is the MetaClass for all Event objects, both handled and test. It holds constants, methods, and attributes that are common to all events in Chook.
An ‘event’ within Chook is the ruby-abstraction of a JSON payload as sent by a JSS Webhook representing an event that takes place in the JSS.
All events contain a #subject attribute, which represent the thing upon which the event acted, e.g. a computer, mobile divice, or the JSS itself. The #subject attribute contains an object which is a subclass of Chook::Subject, q.v.
Direct Known Subclasses
Constant Summary collapse
- EVENTS =
A mapping of the Event Names (as they are known to the JSS) to the the matching Subject class names
The event names from the JSS are in the JSON hash as the value of JSON_hash[:webhookEvent] and they are also the names of the matching event classes within the HandledEvent module and the TestEvent module.
E.g. the HandledEvents class that handles the ‘ComputerPolicyFinished’ event is Chook::HandledEvent::ComputerPolicyFinished
and
the TestEvents that simulates ‘ComputerPolicyFinished’ is Chook::TestEvents::ComputerPolicyFinished
And, those classes take the matching ‘Computer’ subject, either Chook::HandledSubjects::Computer or Chook::TestSubjects::Computer
{ 'ComputerAdded' => Chook::Subject::COMPUTER, 'ComputerCheckIn' => Chook::Subject::COMPUTER, 'ComputerInventoryCompleted' => Chook::Subject::COMPUTER, 'ComputerPolicyFinished' => Chook::Subject::COMPUTER, 'ComputerPushCapabilityChanged' => Chook::Subject::COMPUTER, 'JSSShutdown' => Chook::Subject::JAMF_SOFTWARE_SERVER, 'JSSStartup' => Chook::Subject::JAMF_SOFTWARE_SERVER, 'MobileDeviceCheckIn' => Chook::Subject::MOBILE_DEVICE, 'MobileDeviceCommandCompleted' => Chook::Subject::MOBILE_DEVICE, 'MobileDeviceEnrolled' => Chook::Subject::MOBILE_DEVICE, 'MobileDevicePushSent' => Chook::Subject::MOBILE_DEVICE, 'MobileDeviceUnEnrolled' => Chook::Subject::MOBILE_DEVICE, 'PatchSoftwareTitleUpdated' => Chook::Subject::PATCH_SW_UPDATE, 'PushSent' => Chook::Subject::PUSH, 'RestAPIOperation' => Chook::Subject::REST_API_OPERATION, 'SCEPChallenge' => Chook::Subject::SCEP_CHALLENGE, 'SmartGroupComputerMembershipChange' => Chook::Subject::SMART_GROUP, 'SmartGroupMobileDeviceMembershipChange' => Chook::Subject::SMART_GROUP }.freeze
- EVENT_NAME_CONST =
Event subclasses will have an EVENT_NAME constant, which contains the name of the event, one of the keys from the Event::EVENTS Hash.
'EVENT_NAME'.freeze
- SUBJECT_CLASS_CONST =
Event subclasses will have a SUBJECT_CLASS constant, which contains the class of the subject of the event, based on one of the values from the Event::EVENTS Hash.
'SUBJECT_CLASS'.freeze
Instance Attribute Summary collapse
-
#parsed_json ⇒ Hash?
readonly
If this event object was initialized with a JSON blob as from the JSS, the Hash parsed from it will be stored here.
-
#raw_json ⇒ String?
readonly
If this event object was initialized with a JSON blob as from the JSS, it will be stored here.
-
#subject ⇒ Object
readonly
The subject of this event - i.e.
-
#webhook_id ⇒ Integer
readonly
The webhook id in the JSS that caused this event.
-
#webhook_name ⇒ String
readonly
The webhook name in the JSS that caused this event.
Instance Method Summary collapse
-
#initialize(**args) ⇒ Event
constructor
Args are a hash (or group of named params) with these possible keys: raw_json: [String] A raw JSON blob for a full event as sent by the JSS If this is present, all other keys are ignored and the instance is built with this data.
Constructor Details
#initialize(**args) ⇒ Event
Args are a hash (or group of named params) with these possible keys:
raw_json: [String] A raw JSON blob for a full event as sent by the JSS
If this is present, all other keys are ignored and the instance is
built with this data.
parsed_json: [Hash] A pre-parsed JSON blob for a full event.
If this is present, all other keys are ignored and the instance is
built with this data (however raw_json wins if both are provided)
webhook_event: [String] The name of the event, one of the keys of EVENTS
webhook_id: [Integer] The id of the webhook defined in the JSS
webhook_name: [String] The name of the webhook defined in the JSS
The remaning keys are the attributes of the Subject subclass for this event. Any not provided will be nil.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/chook/event.rb', line 130 def initialize(**args) if args[:raw_json] @raw_json = args[:raw_json] @parsed_json = JSON.parse @raw_json, symbolize_names: true elsif args[:parsed_json] @parsed_json = args[:parsed_json] end if @parsed_json @webhook_name = @parsed_json[:webhook][:name] @webhook_id = @parsed_json[:webhook][:id] subject_data = @parsed_json[:event] else @webhook_name = args.delete :webhook_name @webhook_id = args.delete :webhook_id subject_data = args end @subject = self.class::SUBJECT_CLASS.new subject_data end |
Instance Attribute Details
#parsed_json ⇒ Hash? (readonly)
Returns If this event object was initialized with a JSON blob as from the JSS, the Hash parsed from it will be stored here.
114 115 116 |
# File 'lib/chook/event.rb', line 114 def parsed_json @parsed_json end |
#raw_json ⇒ String? (readonly)
Returns If this event object was initialized with a JSON blob as from the JSS, it will be stored here.
110 111 112 |
# File 'lib/chook/event.rb', line 110 def raw_json @raw_json end |
#subject ⇒ Object (readonly)
Returns The subject of this event - i.e. the thing it acted upon. An instance of a class from either the Chook::HandledSubjects module or the Chook::TestSubjects module.
106 107 108 |
# File 'lib/chook/event.rb', line 106 def subject @subject end |
#webhook_id ⇒ Integer (readonly)
Returns The webhook id in the JSS that caused this event.
98 99 100 |
# File 'lib/chook/event.rb', line 98 def webhook_id @webhook_id end |
#webhook_name ⇒ String (readonly)
Returns The webhook name in the JSS that caused this event.
101 102 103 |
# File 'lib/chook/event.rb', line 101 def webhook_name @webhook_name end |