Class: ContentfulRails::WebhooksController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/contentful_rails/webhooks_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

this is where we receive a webhook, via a POST



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/contentful_rails/webhooks_controller.rb', line 10

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 ok
  render nothing: true
end

#debugObject



29
30
31
# File 'app/controllers/contentful_rails/webhooks_controller.rb', line 29

def debug
  render text: "Debug method works ok"
end