Module: CustosNotifier
- Defined in:
- lib/custos_notifier.rb,
lib/custos_notifier/rack.rb,
lib/custos_notifier/railtie.rb,
lib/custos_notifier/configuration.rb,
lib/custos_notifier/rails/action_controller_catcher.rb
Defined Under Namespace
Modules: Rails Classes: Configuration, Notice, Rack, Railtie
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
-
.configure {|configuration| ... } ⇒ Object
Configure Custos notifier.
-
.custom_notify(message, parameters = {}) ⇒ Object
Send custom notification to Custos service.
-
.notify(exception, options = {}) ⇒ Object
Notify Custos service about raised exceptions.
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
15 16 17 |
# File 'lib/custos_notifier.rb', line 15 def configuration @configuration end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
Configure Custos notifier. Sets configuration options based on passed block. Example:
CustosNotifier.configure do |config|
config.url = "blah.foo.bar'
config.project = 'awsome'
config.stage = 'production'
config.api_key = 'secret'
end
- returns
-
Configuration
51 52 53 54 55 56 |
# File 'lib/custos_notifier.rb', line 51 def configure self.configuration ||= Configuration.new yield(configuration) self.configuration.stage ||= detect_stage configuration end |
.custom_notify(message, parameters = {}) ⇒ Object
Send custom notification to Custos service. Any messages can be sent to service in message
param. Second parameter is optional and could be anything you want.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/custos_notifier.rb', line 61 def custom_notify(, parameters = {}) return if ["test"].include? configuration.stage.downcase url = "#{ configuration.url }/notifications" notify_params = { :project => CustosNotifier.configuration.project, :api_key => CustosNotifier.configuration.api_key } notify_params["notification"] = {"title" => , "customs" => parameters.inspect, "stage" => CustosNotifier.configuration.stage } RestClient.post(url, notify_params) end |
.notify(exception, options = {}) ⇒ Object
Notify Custos service about raised exceptions. Exception will be ignored if notifier is configured with “development” stage. Raised exception is passed to this method, additional request attributes can be passed. Very simple example you can find in CustosNotifier::Rack
middleware. Example:
begin
raise "My example exception"
rescue => ex
CustosNotifier.notify ex, :rack_env => env
end
- exception
-
Exception ancestors
- options
-
Hash, default empty hash.
30 31 32 33 34 35 36 37 38 |
# File 'lib/custos_notifier.rb', line 30 def notify(exception, = {}) return if ["development", "test"].include? configuration.stage.downcase [:exception] = exception notice = Notice.new() url = URI.parse("#{ configuration.url }/errors") RestClient.post(url.to_s, notice.to_param) end |