aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/api_controller.rb
diff options
context:
space:
mode:
authorRobin Houston <robin.houston@gmail.com>2012-07-04 13:45:29 +0100
committerRobin Houston <robin.houston@gmail.com>2012-07-04 13:45:29 +0100
commitd5a43f1aa76c1e0086f08bec9c575d2a41ae9a9b (patch)
tree9c8a851c0f6e26b40be181f705bae582df20c90b /app/controllers/api_controller.rb
parent886a8baef232cce37c829137a8b6a625d16b0504 (diff)
Atom feed of request events
We need not only new requests, but new outgoing correspondence of any sort. The idea is that this feed will contain any event that would have triggered an email to be sent to the public body, so can be used as an alternative, equivalent way to stay up-to-date with happenings on WDTK (or the Alaveteli installation of choice).
Diffstat (limited to 'app/controllers/api_controller.rb')
-rw-r--r--app/controllers/api_controller.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index a8c9b5fef..3001ca3cb 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -155,17 +155,27 @@ class ApiController < ApplicationController
head :no_content
end
- def body_new_requests
+ def body_request_events
feed_type = params[:feed_type]
raise PermissionDenied.new("#{@public_body.id} != #{params[:id]}") if @public_body.id != params[:id].to_i
- @requests = @public_body.info_requests
+ @events = InfoRequestEvent.find_by_sql([
+ %(select info_request_events.*
+ from info_requests
+ join info_request_events on info_requests.id = info_request_events.info_request_id
+ where info_requests.public_body_id = ?
+ and info_request_events.event_type in (
+ 'sent', 'followup_sent', 'resent', 'followup_resent'
+ )
+ order by info_request_events.created_at desc
+ ), @public_body.id
+ ])
if feed_type == "atom"
- render :template => "api/new_requests.atom", :layout => false
+ render :template => "api/request_events.atom", :layout => false
elsif feed_type == "json"
- render :json => @requests
+ render :json => @events
else
- raise ActiveRecord::RecordNotFound.new("Unrecognised feed type: " + feed_type)
+ raise ActiveRecord::RecordNotFound.new("Unrecognised feed type: #{feed_type}")
end
end