Sha256: dea4e2a6ef11ab1c6e8f18db33f5b70cc4ad279b604dfc9da2c5123931b0a017

Contents?: true

Size: 844 Bytes

Versions: 1

Compression:

Stored size: 844 Bytes

Contents

# frozen_string_literal: true

require "uri"
require "json"
require "httpx"

module SlackWebhookLogger
  class RequestIO
    class << self
      def close
        true
      end

      def write(hash)
        return if hash.blank?

        return if SlackWebhookLogger.ignore_patterns.any? { |ignore_pattern| hash[:text].match(ignore_pattern) }

        response = HTTPX.with(headers: { "content-type" => "application/json" }).post(SlackWebhookLogger.webhook_uri.to_s, form: hash)

        return if (200..299).cover?(response.status)

        error_prefix = "slack_webhook_logger failed.\nRequest: #{hash}\nResponse:"
        case response
        when HTTPX::ErrorResponse
          warn("#{error_prefix} #{response}")
        else
          warn("#{error_prefix} #{response.status} #{response.body}")
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack_webhook_logger-0.5.2 lib/slack_webhook_logger/request_io.rb