Class: MistApi::WebhooksHandler

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeWebhooksHandler

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.

Parameters:

  • request (Rack::Request)

    The incoming HTTP request containing the event payload.



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.message])
  end
end