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(request, exception) ⇒ Object



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

def self.notify request, exception
  config_vars = Undantag::Configuration.to_hash
  unless config_vars[:api_key]
    raise Undantag::ConfigurationError::NoApiKey
  end
  post_params = config_vars.merge(env: ENV.inspect,
                                  request: request.inspect,
                                  exception: exception.inspect)

  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