Sha256: 1c963bd83888c877f4a6c332e9e079ecdf6ae95c4b65049527072b039565b580

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, json: 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.4 lib/slack_webhook_logger/request_io.rb