Class: WebhookSystem::EventLog

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/webhook_system/event_log.rb

Overview

This is the model holding on to all webhook responses

Constant Summary collapse

MAX_JSON_ATTRIBUTE_SIZE =
40_000

Class Method Summary collapse

Class Method Details

.construct(subscription, event, request, response) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/webhook_system/event_log.rb', line 21

def self.construct(subscription, event, request, response)
  request_info = {
    'event' => event,
    'headers' => request.headers.to_hash,
    'body' => request.body.truncate(MAX_JSON_ATTRIBUTE_SIZE),
    'url' => request.path,
  }
  response_info = {
    'headers' => response.headers.to_hash,
    'body' => response.body.truncate(MAX_JSON_ATTRIBUTE_SIZE),
  }

  attributes = {
    event_name: event['event_name'],
    event_id: event['event_id'],
    status: response.status,
    request: request_info,
    response: response_info,
  }
  subscription.event_logs.build(attributes)
end