Class: NotificationServices::WebhookService

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

Constant Summary collapse

Label =
"webhook"
Fields =
[
  [:api_token, {
    :placeholder => 'URL to receive a POST request when an error occurs',
    :label => 'URL'
  }]
]

Instance Method Summary collapse

Instance Method Details

#check_paramsObject


10
11
12
13
14
# File 'app/models/notification_services/webhook_service.rb', line 10

def check_params
  if Fields.detect {|f| self[f[0]].blank? }
    errors.add :base, 'You must specify the URL'
  end
end

#create_notification(problem) ⇒ Object


20
21
22
# File 'app/models/notification_services/webhook_service.rb', line 20

def create_notification(problem)
  HTTParty.post(api_token, :body => message_for_webhook(problem))
end

#message_for_webhook(problem) ⇒ Object


16
17
18
# File 'app/models/notification_services/webhook_service.rb', line 16

def message_for_webhook(problem)
  {:problem => {:url => problem_url(problem)}.merge(problem.as_json).to_json}
end