18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/wcc/contentful/webhook_enable_job.rb', line 18
def enable_webhook(client, receive_url:, webhook_username: nil, webhook_password: nil)
webhook = client.webhook_definitions.items.find { |w| w['url'] == receive_url }
logger.debug "existing webhook: #{webhook.inspect}" if webhook
return if webhook
body = {
'name' => 'WCC::Contentful webhook',
'url' => receive_url,
'topics' => [
'*.publish',
'*.unpublish'
],
'filters' => webhook_filters
}
body['httpBasicUsername'] = webhook_username if webhook_username.present?
body['httpBasicPassword'] = webhook_password if webhook_password.present?
begin
resp = client.post_webhook_definition(body)
logger.info "Created webhook: #{resp.raw.dig('sys', 'id')}"
rescue WCC::Contentful::SimpleClient::ApiError => e
logger.error "#{e.response.code}: #{e.response.raw}" if e.response
raise
end
end
|