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

Class Method Summary collapse

Class Attribute Details

.configurationObject

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

Yields:



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(message, 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" => message, "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, options = {})
  return if ["development", "test"].include? configuration.stage.downcase

  options[:exception] = exception
  notice = Notice.new(options)

  url = URI.parse("#{ configuration.url }/errors")
  RestClient.post(url.to_s, notice.to_param)
end