Module: HoptoadNotifier

Defined in:
lib/hoptoad_notifier.rb

Overview

Plugin for applications to automatically post errors to the Hoptoad of their choice.

Defined Under Namespace

Modules: Catcher Classes: Sender

Constant Summary collapse

IGNORE_DEFAULT =
['ActiveRecord::RecordNotFound',
'ActionController::RoutingError',
'ActionController::InvalidAuthenticityToken',
'CGI::Session::CookieStore::TamperedWithCookie']

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



19
20
21
# File 'lib/hoptoad_notifier.rb', line 19

def api_key
  @api_key
end

.backtrace_filtersObject (readonly)

Returns the value of attribute backtrace_filters.



21
22
23
# File 'lib/hoptoad_notifier.rb', line 21

def backtrace_filters
  @backtrace_filters
end

.hostObject

The host to connect to.



37
38
39
# File 'lib/hoptoad_notifier.rb', line 37

def host
  @host
end

.http_open_timeoutObject

The HTTP open timeout (defaults to 2 seconds).



42
43
44
# File 'lib/hoptoad_notifier.rb', line 42

def http_open_timeout
  @http_open_timeout
end

.http_read_timeoutObject

The HTTP read timeout (defaults to 5 seconds).



47
48
49
# File 'lib/hoptoad_notifier.rb', line 47

def http_read_timeout
  @http_read_timeout
end

.portObject

The port on which your Hoptoad server runs.



32
33
34
# File 'lib/hoptoad_notifier.rb', line 32

def port
  @port
end

.proxy_hostObject

Returns the value of attribute proxy_host.



19
20
21
# File 'lib/hoptoad_notifier.rb', line 19

def proxy_host
  @proxy_host
end

.proxy_passObject

Returns the value of attribute proxy_pass.



19
20
21
# File 'lib/hoptoad_notifier.rb', line 19

def proxy_pass
  @proxy_pass
end

.proxy_portObject

Returns the value of attribute proxy_port.



19
20
21
# File 'lib/hoptoad_notifier.rb', line 19

def proxy_port
  @proxy_port
end

.proxy_userObject

Returns the value of attribute proxy_user.



19
20
21
# File 'lib/hoptoad_notifier.rb', line 19

def proxy_user
  @proxy_user
end

.secureObject

Returns the value of attribute secure.



19
20
21
# File 'lib/hoptoad_notifier.rb', line 19

def secure
  @secure
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Call this method to modify defaults in your initializers.

HoptoadNotifier.configure do |config|

config.api_key = '1234567890abcdef'
config.secure  = false

end

NOTE: secure connections are not yet supported.

Yields:

  • (_self)

Yield Parameters:



82
83
84
# File 'lib/hoptoad_notifier.rb', line 82

def configure
  yield self
end

.default_notice_optionsObject

:nodoc:



94
95
96
97
98
99
100
101
102
103
# File 'lib/hoptoad_notifier.rb', line 94

def default_notice_options #:nodoc:
  {
    :api_key       => HoptoadNotifier.api_key,
    :error_message => 'Notification',
    :backtrace     => caller,
    :request       => {},
    :session       => {},
    :environment   => ENV.to_hash
  }
end

.environment_filtersObject



70
71
72
# File 'lib/hoptoad_notifier.rb', line 70

def environment_filters
  @environment_filters ||= %w()
end

.filter_backtrace(&block) ⇒ Object

Takes a block and adds it to the list of backtrace filters. When the filters run, the block will be handed each line of the backtrace and can modify it as necessary. For example, by default a path matching the RAILS_ROOT constant will be transformed into “[RAILS_ROOT]”



27
28
29
# File 'lib/hoptoad_notifier.rb', line 27

def filter_backtrace &block
  (@backtrace_filters ||= []) << block
end

.ignoreObject

Returns the list of errors that are being ignored. The array can be appended to.



52
53
54
55
56
# File 'lib/hoptoad_notifier.rb', line 52

def ignore
  @ignore ||= (HoptoadNotifier::IGNORE_DEFAULT.dup)
  @ignore.flatten!
  @ignore
end

.ignore_only=(names) ⇒ Object

Sets the list of ignored errors to only what is passed in here. This method can be passed a single error or a list of errors.



60
61
62
# File 'lib/hoptoad_notifier.rb', line 60

def ignore_only=(names)
  @ignore = [names].flatten
end

.notify(notice = {}) ⇒ Object

You can send an exception manually using this method, even when you are not in a controller. You can pass an exception or a hash that contains the attributes that would be sent to Hoptoad:

  • api_key: The API key for this project. The API key is a unique identifier that Hoptoad uses for identification.

  • error_message: The error returned by the exception (or the message you want to log).

  • backtrace: A backtrace, usually obtained with caller.

  • request: The controller’s request object.

  • session: The contents of the user’s session.

  • environment: ENV merged with the contents of the request’s environment.



115
116
117
# File 'lib/hoptoad_notifier.rb', line 115

def notify notice = {}
  Sender.new.notify_hoptoad( notice )
end

.params_filtersObject

Returns a list of parameters that should be filtered out of what is sent to Hoptoad. By default, all “password” attributes will have their contents replaced.



66
67
68
# File 'lib/hoptoad_notifier.rb', line 66

def params_filters
  @params_filters ||= %w(password)
end

.protocolObject

:nodoc:



86
87
88
# File 'lib/hoptoad_notifier.rb', line 86

def protocol #:nodoc:
  secure ? "https" : "http"
end

.urlObject

:nodoc:



90
91
92
# File 'lib/hoptoad_notifier.rb', line 90

def url #:nodoc:
  URI.parse("#{protocol}://#{host}:#{port}/notices/")
end