Class: WCC::Contentful::WebhookController

Inherits:
ApplicationController show all
Defined in:
app/controllers/wcc/contentful/webhook_controller.rb

Instance Method Summary collapse

Instance Method Details

#authorize_contentfulObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/wcc/contentful/webhook_controller.rb', line 13

def authorize_contentful
  config = WCC::Contentful.configuration

  if config.webhook_username.present? && config.webhook_password.present?
    unless authenticate_with_http_basic do |u, p|
             u == config.webhook_username &&
                 p == config.webhook_password
           end
      request_http_basic_authentication
      return
    end
  end

  return if request.content_type == 'application/vnd.contentful.management.v1+json'
  render json: { msg: 'This endpoint only responds to webhooks from Contentful' }, status: 406
end

#receiveObject



9
10
11
# File 'app/controllers/wcc/contentful/webhook_controller.rb', line 9

def receive
  WCC::Contentful.sync!(up_to_id: params.dig('sys', 'id'))
end