class NotificationHub::Channels::Webhook::Httparty
Public Class Methods
new(configuration)
click to toggle source
Calls superclass method
NotificationHub::Channels::Webhook::Base::new
# File lib/notification_hub/channels/webhook/httparty.rb, line 9 def initialize(configuration) super end
send_message(event_code, data, options)
click to toggle source
# File lib/notification_hub/channels/webhook/httparty.rb, line 14 def send_message(event_code, data, options) event = event_code.split(".") begin json_string = ActionController::Base.new. render_to_string("#{gateway_options[:template_path]}/#{event[0]}/#{event[1]}", locals: data) json_object = JSON.parse(json_string) json_object[:event] = event_code json_object[:timestamp] = Time.zone.now response = HTTParty.post(options[:webhook_url], { :body => json_object.to_json, :headers => { 'Content-Type' => 'application/json' }, :timeout => gateway_options[:timeout_time] }) raise "Webhook::Httparty Error: #{response.body}" if response.code != 200 rescue => exception raise "Webhook::Httparty Error Error: #{exception.message}" end end