class CPEE::Notifications::Subscription

Public Instance Methods

response() click to toggle source
# File lib/cpee/implementation_notifications.rb, line 91
      def response
        id = @a[0]
        opts = @a[1]
        key = @r[-1]
        if CPEE::Persistence::exists_handler?(id,opts,key)
          Riddl::Parameter::Complex.new("subscriptions","text/xml") do
            ret = XML::Smart::string <<-END
              <subscription xmlns='http://riddl.org/ns/common-patterns/notifications-producer/2.0'/>
            END
            url = CPEE::Persistence::extract_item(id,opts,File.join('handlers',key,'url'))
            ret.root.attributes['id'] = key
            ret.root.attributes['url'] = url if url && !url.empty?
            items = {}
            CPEE::Persistence::extract_handler(id,opts,key).each do |h|
              t, i, v = h.split('/')
              items[t] ||= []
              items[t] << [i,v]
            end
            items.each do |k,v|
              ret.root.add('topic').tap do |n|
                n.attributes['id'] = k
                v.each do |e|
                  n.add *e
                end
              end
            end
            ret.to_s
          end
        else
          @status = 404
       end
      end