Sha256: dda3c479dbb3e915dd65585bf41cbe5567ba49dcae598472bac9484cd0842f6b

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

module WebhookSystem

  # This is the model holding on to all webhook responses
  class EventLog < ActiveRecord::Base
    self.table_name = 'webhook_event_logs'

    belongs_to :subscription, class_name: 'WebhookSystem::Subscription'

    validates :event_id, presence: true
    validates :subscription_id, presence: true
    validates :event_name, presence: true
    validates :status, presence: true

    serialize :request, JSON
    serialize :response, JSON

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

      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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webhook_system-1.0.1 lib/webhook_system/event_log.rb
webhook_system-1.0.0 lib/webhook_system/event_log.rb