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

{{{



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# 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