Sha256: 29ce21decc929ba42f65811c22432da59a990d8919a8fa26da1ed27c02968f79

Contents?: true

Size: 1.52 KB

Versions: 40

Compression:

Stored size: 1.52 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

      CHECK_IN_ENDPOINT = '/v1/check_in'.freeze


      HTTP_ERRORS = Util::HTTP::ERRORS

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

      # Post payload to endpoint for feature.
      #
      # @param [Symbol] feature The feature which is being notified.
      # @param [#to_json] payload The JSON payload to send.
      #
      # @return [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

      # Does a check in using the input id.
      #
      # @param [String] id The unique check_in id.
      #
      # @return [Response]
      def check_in(id)
        Response.new(@http.get("#{CHECK_IN_ENDPOINT}/#{id}"))
      rescue *HTTP_ERRORS => e
        Response.new(:error, nil, "HTTP Error: #{e.class}")
      end

      private

      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

40 entries across 40 versions & 1 rubygems

Version Path
honeybadger-5.4.1 lib/honeybadger/backend/server.rb
honeybadger-5.4.0 lib/honeybadger/backend/server.rb
honeybadger-5.3.0 lib/honeybadger/backend/server.rb
honeybadger-5.2.1 lib/honeybadger/backend/server.rb
honeybadger-5.0.2 lib/honeybadger/backend/server.rb
honeybadger-5.0.1 lib/honeybadger/backend/server.rb
honeybadger-5.0.0 lib/honeybadger/backend/server.rb
honeybadger-5.0.0.beta1 lib/honeybadger/backend/server.rb
honeybadger-4.12.2 lib/honeybadger/backend/server.rb
honeybadger-4.12.1 lib/honeybadger/backend/server.rb
honeybadger-4.12.0 lib/honeybadger/backend/server.rb
honeybadger-4.11.0 lib/honeybadger/backend/server.rb
honeybadger-4.10.0 lib/honeybadger/backend/server.rb
honeybadger-4.9.0 lib/honeybadger/backend/server.rb
honeybadger-4.8.0 lib/honeybadger/backend/server.rb
honeybadger-4.7.3 lib/honeybadger/backend/server.rb
honeybadger-4.7.2 lib/honeybadger/backend/server.rb
honeybadger-4.7.1 lib/honeybadger/backend/server.rb
honeybadger-4.7.0 lib/honeybadger/backend/server.rb
honeybadger-4.6.0 lib/honeybadger/backend/server.rb