Class: ContentfulRails::WebhooksController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- ContentfulRails::WebhooksController
- Defined in:
- app/controllers/contentful_rails/webhooks_controller.rb
Overview
Controller for debugging and receiving Contentful Webhooks Webhooks are forwarded via the ActiveSupport::Notification system
Instance Method Summary collapse
-
#create ⇒ Object
this is where we receive a webhook, via a POST.
-
#debug ⇒ Object
Debug route.
Instance Method Details
#create ⇒ Object
this is where we receive a webhook, via a POST
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/contentful_rails/webhooks_controller.rb', line 20 def create # The only things we need to handle in here (for now at least) are entries. # If there's been an update or a deletion, we just remove the cached timestamp. # The updated_at method which is included in ContentfulModel::Base in this gem # will check the cache first before making the call to the API. # We can then just use normal Rails russian doll caching without expensive API calls. request.format = :json update_type = request.headers['HTTP_X_CONTENTFUL_TOPIC'] # All we do here is publish an ActiveSupport::Notification, which is subscribed to # elsewhere. In this gem are subscription options for timestamp or object caching, # implement your own and subscribe in an initializer. ActiveSupport::Notifications.instrument("Contentful.#{update_type}", params) # must return an empty response render body: nil end |
#debug ⇒ Object
Debug route
40 41 42 |
# File 'app/controllers/contentful_rails/webhooks_controller.rb', line 40 def debug render plain: 'Debug method works ok' end |