Class: Riddl::Utils::Notifications::Producer::UpdateSubscription

Inherits:
Implementation
  • Object
show all
Defined in:
lib/ruby/riddl/utils/notifications_producer.rb

Overview

}}}

Instance Method Summary collapse

Methods inherited from Implementation

#headers, #initialize, #status

Constructor Details

This class inherits a constructor from Riddl::Implementation

Instance Method Details

#responseObject

{{{



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/ruby/riddl/utils/notifications_producer.rb', line 270

def response
  backend = @a[0]
  handler = @a[1]
  key     = @r.last

  url  = @p[0].name == 'url' ? @p.shift.value : nil

  # TODO check if message is valid (with producer secret)
  unless backend.subscriptions[key]
    @status = 404
    return # subscription not found
  end

  topics = []
  backend.subscriptions[key].modify do |doc|
    if url.nil?
      doc.find('/n:subscription/@url').delete_all!
    else
      doc.root.attributes['url'] = url
    end
    doc.root.children.delete_all!
    while @p.length > 1
      topic = @p.shift.value
      base = @p.shift
      type = base.name
      items = base.value.split(',')
      t = if topics.include?(topic)
        doc.find("/n:subscription/n:topic[@id='#{topic}']").first
      else
        topics << topic
        doc.root.add('topic', :id => topic)
      end
      items.each do |i|
        t.add(type[0..-2], i)
      end
    end
  end

  handler.key(key).topics(topics).update unless handler.nil?
  nil
end