Class: Undantag::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/undantag/notifier.rb

Constant Summary collapse

URL =
"https://undantag.herokuapp.com/exception"

Class Method Summary collapse

Class Method Details

.notify(env, exception, request) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/undantag/notifier.rb', line 7

def self.notify env, exception, request
  config_vars = Undantag::Configuration.to_hash
  unless config_vars[:api_key]
    raise Undantag::ConfigurationError::NoApiKey
  end
  post_params = config_vars.merge(env: PP.pp(env, ""),
                                  request: PP.pp(request, ""),
                                  backtrace: exception.backtrace.join("\n"),
                                  exception: PP.pp(exception, ''))

  uri = URI(Notifier::URL)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request = Net::HTTP::Post.new(uri.request_uri)
  request.set_form_data(post_params)

  response = http.request(request)
  case response.code
  when "401"
    raise Undantag::NotAuthorized
  end
end