Class: Proby::Notifier

Inherits:
ProbyHttpApi show all
Defined in:
lib/proby/notifier.rb

Class Method Summary collapse

Class Method Details

.send_notification(type, proby_task_id, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/proby/notifier.rb', line 4

def self.send_notification(type, proby_task_id, options={})
  if Proby.api_key.nil?
    $stderr.puts "Proby: No notification sent because API key is not set.  Set it using Proby.api_key = 'my_api_key'"
    return nil
  end

  proby_task_id = ENV['PROBY_TASK_ID'] if blank?(proby_task_id)
  if blank?(proby_task_id)
    Proby.logger.warn "Proby: No notification sent because task ID was not specified"
    return nil
  end

  response = post("/api/v1/tasks/#{proby_task_id}/#{type}.json",
                  :body => MultiJson.encode(options),
                  :format => :json,
                  :headers => default_headers)
  response.code
rescue Exception => e
  Proby.logger.error "Proby: Proby notification failed: #{e.message}"
  Proby.logger.error e.backtrace
end