Sha256: d17cd4b61b8a73cf460cf067b0d520a883f991000214b57c55f7b78c79237725

Contents?: true

Size: 967 Bytes

Versions: 1

Compression:

Stored size: 967 Bytes

Contents

module Urkel
  class Connection
    API_ENDPOINT="/api/v1/failures"

    def initialize(configuration)
      @configuration = configuration
    end

    def publish(error)
      response = @configuration.request(request_for(error))
      response.is_a?(Net::HTTPOK)
    end

    def publish!(error)
      response = @configuration.request(request_for(error))
      if response.is_a? Net::HTTPOK
        true
      elsif response.is_a? Net::HTTPUnauthorized
        raise InvalidAPITokenError.new
      else
        false
      end
    end

    private

    def request_for(error)
      Net::HTTP::Post.new(API_ENDPOINT).tap do |request|
        request.set_form_data(form_payload_for(error))
      end
    end

    def form_payload_for(error)
      {
        "error[message]" => error.message,
        "error[hostname]" => Socket.gethostname,
        "error[error_type]" => error.class.name,
        "error[backtrace][]" => error.backtrace,
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
urkel-0.0.2 lib/urkel/connection.rb