class Honeybadger::Backend::Server

Constants

CHECK_IN_ENDPOINT
ENDPOINTS
HTTP_ERRORS

Public Class Methods

new(config) click to toggle source
Calls superclass method Honeybadger::Backend::Base::new
# File lib/honeybadger/backend/server.rb, line 22
def initialize(config)
  @http = Util::HTTP.new(config)
  super
end

Public Instance Methods

check_in(id) click to toggle source

Does a check in using the input id.

@param [String] id The unique check_in id.

@return [Response]

# File lib/honeybadger/backend/server.rb, line 45
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
notify(feature, payload) click to toggle source

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]

# File lib/honeybadger/backend/server.rb, line 33
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 Instance Methods

payload_headers(payload) click to toggle source
# File lib/honeybadger/backend/server.rb, line 53
def payload_headers(payload)
  if payload.respond_to?(:api_key) && payload.api_key
    {
      'X-API-Key' => payload.api_key
    }
  end
end