Class: MistApi::WebhooksHandler
- Inherits:
-
Object
- Object
- MistApi::WebhooksHandler
- Includes:
- CoreLibrary
- Defined in:
- lib/mist_api/events/webhooks/webhooks_handler.rb
Overview
WebhooksHandler is responsible for verifying request signatures and parsing incoming Webhooks events into strongly typed objects.
Instance Method Summary collapse
-
#initialize ⇒ WebhooksHandler
constructor
Creates a new instance of the WebhooksHandler.
-
#parse_event(request) ⇒ Object
Parse the event.
Constructor Details
#initialize ⇒ WebhooksHandler
Creates a new instance of the WebhooksHandler.
12 |
# File 'lib/mist_api/events/webhooks/webhooks_handler.rb', line 12 def initialize; end |
Instance Method Details
#parse_event(request) ⇒ Object
Parse the event.
@return[WebhookAlarms, nil, WebhookAssetRawRssi, WebhookAudits, WebhookClientInfo, WebhookClientJoin, WebhookClientLatency, WebhookClientSessions, WebhookDeviceEvents, WebhookDeviceUpdowns, WebhookDiscoveredRawRssi, WebhookGuestAuthorizations, WebhookLocation, WebhookLocationAsset, WebhookLocationCentrak, WebhookLocationClient, WebhookLocationSdk, WebhookLocationUnclient, WebhookMinisApplication, WebhookMinisReachability, WebhookMxedgeEvents, WebhookNacAccounting, WebhookNacEvents, WebhookOccupancyAlerts, WebhookPing, WebhookRssizone, WebhookSdkclientScanData, WebhookSiteSle, WebhookWifiConnRaw, WebhookWifiUnconnRaw, WebhookZone, UnknownEvent] WebhookAlarms, nil, WebhookAssetRawRssi, WebhookAudits, WebhookClientInfo, WebhookClientJoin, WebhookClientLatency, WebhookClientSessions, WebhookDeviceEvents, WebhookDeviceUpdowns, WebhookDiscoveredRawRssi, WebhookGuestAuthorizations, WebhookLocation, WebhookLocationAsset, WebhookLocationCentrak, WebhookLocationClient, WebhookLocationSdk, WebhookLocationUnclient, WebhookMinisApplication, WebhookMinisReachability, WebhookMxedgeEvents, WebhookNacAccounting, WebhookNacEvents, WebhookOccupancyAlerts, WebhookPing, WebhookRssizone, WebhookSdkclientScanData, WebhookSiteSle, WebhookWifiConnRaw, WebhookWifiUnconnRaw, WebhookZone for successful parsing;
UnknownEvent for unknown events.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mist_api/events/webhooks/webhooks_handler.rb', line 39 def parse_event(request) return UnknownEvent.new(['Invalid request env.']) unless request.respond_to?(:env) && request.env.is_a?(Hash) raw_body = RackRequestHelper.read_raw_body(request) return UnknownEvent.new(['Invalid request body.']) if raw_body.nil? || raw_body.empty? # Deserialize payload begin union = UnionTypeLookUp.get(:Webhooks) raw = RackRequestHelper.read_raw_body(request) APIHelper.deserialize_union_type(union, raw, false, true) rescue StandardError => e UnknownEvent.new(['Deserialization failed.', e.]) end end |