Sha256: e9e43fbc190a23a9ce1dfc5059a49230f04b02d9d3d75f240ed081f7cdc25b26

Contents?: true

Size: 879 Bytes

Versions: 8

Compression:

Stored size: 879 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| SlackWebhookLogger::Formatter.fetch_text(hash).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

8 entries across 8 versions & 1 rubygems

Version Path
slack_webhook_logger-0.7.0 lib/slack_webhook_logger/request_io.rb
slack_webhook_logger-0.6.5 lib/slack_webhook_logger/request_io.rb
slack_webhook_logger-0.6.4 lib/slack_webhook_logger/request_io.rb
slack_webhook_logger-0.6.3 lib/slack_webhook_logger/request_io.rb
slack_webhook_logger-0.6.2 lib/slack_webhook_logger/request_io.rb
slack_webhook_logger-0.6.1 lib/slack_webhook_logger/request_io.rb
slack_webhook_logger-0.6.0 lib/slack_webhook_logger/request_io.rb
slack_webhook_logger-0.5.5 lib/slack_webhook_logger/request_io.rb