def put_bucket_notification(bucket_name, notification)
builder = Nokogiri::XML::Builder.new do
NotificationConfiguration do
notification.fetch('Topics', []).each do |topic|
TopicConfiguration do
Id topic['Id']
Topic topic['Topic']
Event topic['Event']
end
end
notification.fetch('Queues', []).each do |queue|
QueueConfiguration do
Id queue['Id']
Queue queue['Queue']
Event queue['Event']
end
end
notification.fetch('CloudFunctions', []).each do |func|
CloudFunctionConfiguration do
Id func['Id']
CloudFunction func['CloudFunction']
InvocationRole func['InvocationRole']
Event func['Event']
end
end
end
end
body = builder.to_xml
body.gsub!(/<([^<>]+)\/>/, '<\1></\1>')
request({
:body => body,
:expects => 200,
:headers => {'Content-MD5' => Base64.encode64(OpenSSL::Digest::MD5.digest(body)).chomp!,
'Content-Type' => 'application/xml'},
:bucket_name => bucket_name,
:method => 'PUT',
:query => {'notification' => nil}
})
end