class Honeybadger::Util::HTTP

Constants

ERRORS
HEADERS

Attributes

config[R]

Public Class Methods

new(config) click to toggle source
# File lib/honeybadger/util/http.rb, line 36
def initialize(config)
  @config = config
end

Public Instance Methods

get(endpoint) click to toggle source
# File lib/honeybadger/util/http.rb, line 40
def get(endpoint)
  response = http_connection.get(endpoint)
  debug { sprintf("http method=GET path=%s code=%d", endpoint.dump, response.code) }
  response
end
post(endpoint, payload, headers = nil) click to toggle source
# File lib/honeybadger/util/http.rb, line 46
def post(endpoint, payload, headers = nil)
  response = http_connection.post(endpoint, compress(payload.to_json), http_headers(headers))
  debug { sprintf("http method=POST path=%s code=%d", endpoint.dump, response.code) }
  response
end

Private Instance Methods

compress(string, level = Zlib::DEFAULT_COMPRESSION) click to toggle source
# File lib/honeybadger/util/http.rb, line 87
def compress(string, level = Zlib::DEFAULT_COMPRESSION)
  Zlib::Deflate.deflate(string, level)
end
http_connection() click to toggle source
# File lib/honeybadger/util/http.rb, line 56
def http_connection
  setup_http_connection
end
http_headers(headers = nil) click to toggle source
# File lib/honeybadger/util/http.rb, line 60
def http_headers(headers = nil)
  {}.tap do |hash|
    hash.merge!(HEADERS)
    hash.merge!({'X-API-Key' => config[:api_key].to_s})
    hash.merge!(headers) if headers
  end
end
setup_http_connection() click to toggle source
# File lib/honeybadger/util/http.rb, line 68
def setup_http_connection
  http_class = Net::HTTP::Proxy(config[:'connection.proxy_host'], config[:'connection.proxy_port'], config[:'connection.proxy_user'], config[:'connection.proxy_pass'])
  http = http_class.new(config[:'connection.host'], config.connection_port)

  http.read_timeout = config[:'connection.http_read_timeout']
  http.open_timeout = config[:'connection.http_open_timeout']

  if config[:'connection.secure']
    http.use_ssl = true

    http.ca_file = config.ca_bundle_path
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  else
    http.use_ssl = false
  end

  http
end