Class: CPEE::Notifications::Subscription

Inherits:
Riddl::Implementation
  • Object
show all
Defined in:
lib/cpee/implementation_notifications.rb

Overview

}}}

Instance Method Summary collapse

Instance Method Details

#responseObject

{{{



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cpee/implementation_notifications.rb', line 72

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('handler',key,'url'))
      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