Module: DiscoApp::Concerns::WebhooksController
- Extended by:
- ActiveSupport::Concern
- Included in:
- WebhooksController
- Defined in:
- app/controllers/disco_app/concerns/webhooks_controller.rb
Instance Method Summary collapse
Instance Method Details
#process_webhook ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/disco_app/concerns/webhooks_controller.rb', line 10 def process_webhook # Get the topic and domain for this webhook. topic = request.headers['HTTP_X_SHOPIFY_TOPIC'] shopify_domain = request.headers['HTTP_X_SHOPIFY_SHOP_DOMAIN'] # Ensure a domain was provided in the headers. return head :bad_request unless shopify_domain # Try to find a matching background job task for the given topic using class name. job_class = DiscoApp::WebhookService.find_job_class(topic) # Return bad request if we couldn't match a job class. return head :bad_request if job_class.blank? # Decode the body data and enqueue the appropriate job. data = JSON.parse(request.body.read).with_indifferent_access job_class.perform_later(shopify_domain, data) render body: nil end |