aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api_controller.rb14
-rw-r--r--app/models/info_request.rb6
-rw-r--r--app/models/public_body.rb4
-rw-r--r--app/models/user.rb3
-rw-r--r--app/views/api/new_requests.atom.builder21
5 files changed, 38 insertions, 10 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 524aa44b7..b34386377 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -155,6 +155,20 @@ class ApiController < ApplicationController
head :no_content
end
+ def body_new_requests
+ 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
+ if feed_type == "atom"
+ render :template => "api/new_requests.atom"
+ elsif feed_type == "json"
+ render :json => @requests
+ else
+ raise ActiveRecord::RecordNotFound.new("Unrecognised feed type: " + feed_type)
+ end
+ end
+
protected
def check_api_key
raise "Missing required parameter 'k'" if params[:k].nil?
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index d09acbcf6..a41d6d2db 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -1,11 +1,10 @@
# == Schema Information
-# Schema version: 114
#
# Table name: info_requests
#
# id :integer not null, primary key
# title :text not null
-# user_id :integer not null
+# user_id :integer
# public_body_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
@@ -17,10 +16,11 @@
# allow_new_responses_from :string(255) default("anybody"), not null
# handle_rejected_responses :string(255) default("bounce"), not null
# idhash :string(255) not null
+# external_user_name :string(255)
+# external_url :string(255)
# attention_requested :boolean default(FALSE)
#
-
require 'digest/sha1'
class InfoRequest < ActiveRecord::Base
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index bc8f084bb..9efeadf55 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -1,5 +1,4 @@
# == Schema Information
-# Schema version: 114
#
# Table name: public_bodies
#
@@ -19,7 +18,6 @@
# publication_scheme :text default(""), not null
# api_key :string(255) not null
#
-
# models/public_body.rb:
# A public body, from which information can be requested.
#
@@ -583,5 +581,3 @@ class PublicBody < ActiveRecord::Base
end
end
-
-
diff --git a/app/models/user.rb b/app/models/user.rb
index a21676f68..657ea2a4a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,5 +1,4 @@
# == Schema Information
-# Schema version: 114
#
# Table name: users
#
@@ -21,9 +20,7 @@
# email_bounce_message :text default(""), not null
# no_limit :boolean default(FALSE), not null
# receive_email_alerts :boolean default(TRUE), not null
-# user_similarity_id :integer
#
-
# models/user.rb:
# Model of people who use the site to file requests, make comments etc.
#
diff --git a/app/views/api/new_requests.atom.builder b/app/views/api/new_requests.atom.builder
new file mode 100644
index 000000000..38d33bce3
--- /dev/null
+++ b/app/views/api/new_requests.atom.builder
@@ -0,0 +1,21 @@
+atom_feed do |feed|
+ feed.title("New requests made to #{@public_body.name}")
+ feed.updated(@requests.first.updated_at)
+
+ for request in @requests
+ feed.entry(request) do |entry|
+ entry.updated(request.updated_at)
+ entry.published(request.created_at)
+ entry.title(request.title)
+ entry.content(content, :type => 'html')
+ entry.author do |author|
+ author.name(request.user_name)
+ if !request.user.nil?
+ author.uri(main_url(user_url(request.user)))
+ end
+ author.email(request.incoming_email)
+ end
+ end
+ end
+end
+