Sha256: 89ad139baff6f838ed919c26f4826c292acedf054283aa83e90ef166b23038ab

Contents?: true

Size: 894 Bytes

Versions: 6

Compression:

Stored size: 894 Bytes

Contents

module SpiffyStoresApp
  class WebhooksController < ActionController::Base
    include SpiffyStoresApp::WebhookVerification

    class SpiffyStoresApp::MissingWebhookJobError < StandardError; end

    def receive
      params.permit!
      job_args = {shop_domain: shop_domain, webhook: webhook_params.to_h}
      webhook_job_klass.perform_later(job_args)
      head :no_content
    end

    private

    def webhook_params
      params.except(:controller, :action, :type)
    end

    def webhook_job_klass
      webhook_job_klass_name.safe_constantize or raise SpiffyStoresApp::MissingWebhookJobError
    end

    def webhook_job_klass_name(type = webhook_type)
      [webhook_namespace, "#{type}_job"].compact.join('/').classify
    end

    def webhook_type
      params[:type]
    end

    def webhook_namespace
      SpiffyStoresApp.configuration.webhook_jobs_namespace
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spiffy_stores_app-8.2.11 app/controllers/spiffy_stores_app/webhooks_controller.rb
spiffy_stores_app-8.2.10 app/controllers/spiffy_stores_app/webhooks_controller.rb
spiffy_stores_app-8.2.9 app/controllers/spiffy_stores_app/webhooks_controller.rb
spiffy_stores_app-8.2.8 app/controllers/spiffy_stores_app/webhooks_controller.rb
spiffy_stores_app-8.2.7 app/controllers/spiffy_stores_app/webhooks_controller.rb
spiffy_stores_app-8.2.6 app/controllers/spiffy_stores_app/webhooks_controller.rb