Class: NotFoundNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo_developer/app/services/not_found_notifier.rb

Class Method Summary collapse

Class Method Details

.crawler?(user_agent) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/nexmo_developer/app/services/not_found_notifier.rb', line 23

def self.crawler?(user_agent)
  Woothee.parse(user_agent)[:category] == :crawler
end

.ignored_format?(format) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/nexmo_developer/app/services/not_found_notifier.rb', line 17

def self.ignored_format?(format)
  return false unless format

  IGNORED_FORMATS.include? format.downcase
end

.notification_name(exception) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/nexmo_developer/app/services/not_found_notifier.rb', line 27

def self.notification_name(exception)
  if exception.instance_of? Nexmo::Markdown::DocFinder::MissingDoc
    'Missing Document'
  else
    '404 - Not Found'
  end
end

.notify(request, exception) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/nexmo_developer/app/services/not_found_notifier.rb', line 4

def self.notify(request, exception)
  return if ignored_format?(request.params['format'])
  return if crawler?(request.user_agent)

  Bugsnag.notify(notification_name(exception)) do |notification|
    notification.add_tab(:request, {
      params: request.params,
      path: request.path,
      base_url: request.base_url,
    })
  end
end