2018-08-03 13:22:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 09:17:42 -04:00
|
|
|
class WebHookLog < ApplicationRecord
|
2019-12-17 10:08:15 -05:00
|
|
|
include SafeUrl
|
|
|
|
include Presentable
|
2020-02-03 04:08:42 -05:00
|
|
|
include DeleteWithLimit
|
|
|
|
include CreatedAtFilterable
|
2019-12-17 10:08:15 -05:00
|
|
|
|
2017-04-27 06:08:57 -04:00
|
|
|
belongs_to :web_hook
|
|
|
|
|
2017-07-03 10:01:41 -04:00
|
|
|
serialize :request_headers, Hash # rubocop:disable Cop/ActiveRecordSerialize
|
|
|
|
serialize :request_data, Hash # rubocop:disable Cop/ActiveRecordSerialize
|
|
|
|
serialize :response_headers, Hash # rubocop:disable Cop/ActiveRecordSerialize
|
2017-04-27 06:08:57 -04:00
|
|
|
|
|
|
|
validates :web_hook, presence: true
|
|
|
|
|
2019-12-17 10:08:15 -05:00
|
|
|
before_save :obfuscate_basic_auth
|
|
|
|
|
2018-06-28 09:34:31 -04:00
|
|
|
def self.recent
|
|
|
|
where('created_at >= ?', 2.days.ago.beginning_of_day)
|
|
|
|
.order(created_at: :desc)
|
|
|
|
end
|
|
|
|
|
2017-04-27 06:08:57 -04:00
|
|
|
def success?
|
|
|
|
response_status =~ /^2/
|
|
|
|
end
|
2019-12-17 10:08:15 -05:00
|
|
|
|
2020-01-27 04:08:32 -05:00
|
|
|
def internal_error?
|
|
|
|
response_status == WebHookService::InternalErrorResponse::ERROR_MESSAGE
|
|
|
|
end
|
|
|
|
|
2019-12-17 10:08:15 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def obfuscate_basic_auth
|
|
|
|
self.url = safe_url
|
|
|
|
end
|
2017-04-27 06:08:57 -04:00
|
|
|
end
|