Sha256: df741f6e1c9bf36cf73cdf435508f7489a8d7af775a97d587cd71bbee3bc43e5
Contents?: true
Size: 1.9 KB
Versions: 4
Compression:
Stored size: 1.9 KB
Contents
# frozen_string_literal: true module Emailbutler class WebhooksController < Emailbutler::ApplicationController skip_before_action :verify_authenticity_token before_action :validate_provider, only: %i[create] def create Emailbutler::Container.resolve(:webhooks_receiver).call( mapper: receiver_mapper, payload: mapper_params.to_h ) head :ok end private def validate_provider head :ok if Emailbutler.configuration.providers.exclude?(params[:provider]) end def receiver_mapper case params[:provider] when 'sendgrid' then Emailbutler::Container.resolve(:sendgrid_mapper) when 'smtp2go' then Emailbutler::Container.resolve(:smtp2go_mapper) when 'resend' then Emailbutler::Container.resolve(:resend_mapper) when 'mailjet' then Emailbutler::Container.resolve(:mailjet_mapper) when 'mailtrap' then Emailbutler::Container.resolve(:mailtrap_mapper) when 'mandrill' then Emailbutler::Container.resolve(:mandrill_mapper) end end def mapper_params case params[:provider] when 'sendgrid' then sendgrid_params when 'smtp2go' then smtp2go_params when 'resend' then resend_params when 'mailjet' then mailjet_params when 'mailtrap' then mailtrap_params when 'mandrill' then mandrill_params end end def sendgrid_params params.permit('_json' => %w[smtp-id event timestamp sg_message_id]) end def smtp2go_params params.permit('event', 'sendtime', 'message-id') end def resend_params params.permit('type', 'created_at', 'data' => %w[email_id]) end def mailjet_params params.permit('event', 'time', 'Message_GUID') end def mailtrap_params params.permit('events' => %w[event timestamp message_id]) end def mandrill_params params.permit('mandrill_events' => %w[event ts _id]) end end end
Version data entries
4 entries across 4 versions & 1 rubygems