Class: NotificationServices::HipchatService

Inherits:
NotificationService
  • Object
show all
Defined in:
app/models/notification_services/hipchat_service.rb

Constant Summary collapse

Label =
'hipchat'
Mandatory_fields =
[:service, :api_token, :room_id]
API_versions =
['v1', 'v2']

Instance Method Summary collapse

Instance Method Details

#check_paramsObject


25
26
27
28
29
30
31
32
33
34
# File 'app/models/notification_services/hipchat_service.rb', line 25

def check_params
  Fields.each do |field, hash|
    if Mandatory_fields.include?(field) && self[field].blank?
      errors.add field, "You must specify #{hash[:label]}"
    end
  end
  unless API_versions.include?(self[:service])
    errors.add :service, "API version must be #{API_versions.join(' or ')}"
  end
end

#create_notification(problem) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/notification_services/hipchat_service.rb', line 40

def create_notification(problem)
  url = app_problem_url problem.app, problem
  message = <<-MSG.strip_heredoc
    <strong>#{ERB::Util.html_escape problem.app.name}</strong> error in <strong>#{ERB::Util.html_escape problem.environment}</strong> at <strong>#{ERB::Util.html_escape problem.where}</strong> (<a href="#{url}">details</a>)<br>
    &nbsp;&nbsp;#{ERB::Util.html_escape problem.message.to_s.truncate(100)}<br>
    &nbsp;&nbsp;Times occurred: #{problem.notices_count}
  MSG

  options = { :api_version => self[:service] }
  options[:server_url] = self[:service_url] if service_url.present?

  client = HipChat::Client.new(api_token, options)
  client[room_id].send('Errbit', message, :color => 'red', :notify => true)
end

#urlObject


36
37
38
# File 'app/models/notification_services/hipchat_service.rb', line 36

def url
  "https://www.hipchat.com/sign_in"
end