Sha256: 6feb87da1e28230c732c679d238846868e36dfaf7985fbd2bbb9ea81be136a80

Contents?: true

Size: 944 Bytes

Versions: 6

Compression:

Stored size: 944 Bytes

Contents

# frozen_string_literal: true

require "httparty"
require_relative "errors"

module Flipper
  module Notifications
    module Webhooks
      class Webhook

        include HTTParty

        default_timeout 5 # seconds
        raise_on 400..599

        def initialize(url:)
          @url = url
        end

        attr_reader :url

        def notify(**_kwargs)
          raise "Implement #notify in your subclass"
        end

        def serialized_attributes
          { url: url }
        end

        def ==(other)
          other.is_a?(self.class) && url == other.url
        end

        private

        def webhook_api_errors(&block)
          block.call
        rescue HTTParty::ResponseError => e
          error = e.response.code.to_i < 500 ? ClientError : ServerError
          raise error, e.response
        rescue Errno::ECONNRESET, Timeout::Error => e
          raise NetworkError, e
        end

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
flipper-notifications-0.1.6 lib/flipper/notifications/webhooks/webhook.rb
flipper-notifications-0.1.5 lib/flipper/notifications/webhooks/webhook.rb
flipper-notifications-0.1.4 lib/flipper/notifications/webhooks/webhook.rb
flipper-notifications-0.1.3 lib/flipper/notifications/webhooks/webhook.rb
flipper-notifications-0.1.2 lib/flipper/notifications/webhooks/webhook.rb
flipper-notifications-0.1.1 lib/flipper/notifications/webhooks/webhook.rb