summaryrefslogtreecommitdiff
path: root/app/models/hooks/web_hook_log.rb
blob: 2d9f7594e8c5cdcc8b494ef3f58d5058e020dc0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

class WebHookLog < ActiveRecord::Base
  belongs_to :web_hook

  serialize :request_headers, Hash # rubocop:disable Cop/ActiveRecordSerialize
  serialize :request_data, Hash # rubocop:disable Cop/ActiveRecordSerialize
  serialize :response_headers, Hash # rubocop:disable Cop/ActiveRecordSerialize

  validates :web_hook, presence: true

  def self.recent
    where('created_at >= ?', 2.days.ago.beginning_of_day)
      .order(created_at: :desc)
  end

  def success?
    response_status =~ /^2/
  end
end