Sha256: c736f13c3508863630a652f2a12f365e47a4f5de796fcdd02c2f2488cdec40bb

Contents?: true

Size: 1.32 KB

Versions: 9

Compression:

Stored size: 1.32 KB

Contents

require 'net/http'
require 'json'
require 'zlib'
require 'openssl'

require 'honeybadger/backend/base'
require 'honeybadger/util/http'

module Honeybadger
  module Backend
    class Server < Base
      ENDPOINTS = {
        notices: '/v1/notices'.freeze,
        deploys: '/v1/deploys'.freeze
      }.freeze

      HTTP_ERRORS = Util::HTTP::ERRORS

      def initialize(config)
        @http = Util::HTTP.new(config)
        super
      end

      # Internal: Post payload to endpoint for feature.
      #
      # feature - The feature which is being notified.
      # payload - The payload to send, responding to `#to_json`.
      #
      # Returns Response.
      def notify(feature, payload)
        ENDPOINTS[feature] or raise(BackendError, "Unknown feature: #{feature}")
        Response.new(@http.post(ENDPOINTS[feature], payload, payload_headers(payload)))
      rescue *HTTP_ERRORS => e
        Response.new(:error, nil, "HTTP Error: #{e.class}")
      end

      private

      # Internal: Construct headers for supported payloads.
      #
      # payload - The payload object.
      #
      # Returns Hash headers if supported, otherwise nil.
      def payload_headers(payload)
        if payload.respond_to?(:api_key) && payload.api_key
          {
            'X-API-Key' => payload.api_key
          }
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
honeybadger-3.2.0.beta1 lib/honeybadger/backend/server.rb
honeybadger-3.1.2 lib/honeybadger/backend/server.rb
honeybadger-3.1.1 lib/honeybadger/backend/server.rb
honeybadger-3.1.0 lib/honeybadger/backend/server.rb
honeybadger-3.0.2 lib/honeybadger/backend/server.rb
honeybadger-3.0.1 lib/honeybadger/backend/server.rb
honeybadger-3.0.0 lib/honeybadger/backend/server.rb
honeybadger-3.0.0.beta6 lib/honeybadger/backend/server.rb
honeybadger-3.0.0.beta5 lib/honeybadger/backend/server.rb