aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/public_body_controller.rb20
-rw-r--r--app/controllers/request_controller.rb40
-rw-r--r--app/views/help/api.rhtml35
-rw-r--r--app/views/layouts/default.rhtml3
-rw-r--r--app/views/request/details.rhtml3
-rw-r--r--config/routes.rb2
-rw-r--r--vendor/plugins/has_tag_string/lib/has_tag_string.rb5
7 files changed, 101 insertions, 7 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 560206900..0a2e72a5a 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -47,6 +47,26 @@ class PublicBodyController < ApplicationController
@track_thing = TrackThing.create_track_for_public_body(@public_body)
@feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss] } ]
+
+ respond_to do |format|
+ format.html { @has_json = true }
+ format.json {
+ render :json => {
+ :id => @public_body.id,
+ :url_name => @public_body.url_name,
+ :name => @public_body.name,
+ :short_name => @public_body.short_name,
+ # :request_email # we hide this behind a captcha, to stop people doing bulk requests easily
+ :created_at => @public_body.created_at,
+ :updated_at => @public_body.updated_at,
+ # :version, :last_edit_editor, :last_edit_comment # history, not done yet
+ :home_page => @public_body.calculated_home_page,
+ :notes => @public_body.notes,
+ :publication_scheme => @public_body.publication_scheme,
+ :tags => @public_body.tag_array,
+ }
+ }
+ end
end
def view_email
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 7626e5ad2..167667725 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -68,6 +68,46 @@ class RequestController < ApplicationController
# For send followup link at bottom
@last_response = @info_request.get_last_response
+
+ respond_to do |format|
+ format.html { @has_json = true }
+ format.json {
+ render :json => {
+ :id => @info_request.id,
+ :url_title => @info_request.url_title,
+ :title => @info_request.title,
+ :user => @info_request.user.url_name,
+ :public_body => @info_request.public_body.url_name,
+ :created_at => @info_request.created_at,
+ :updated_at => @info_request.updated_at,
+ :described_state => @info_request.described_state,
+ :awaiting_description => @info_request.awaiting_description ,
+ :prominence => @info_request.prominence,
+ :law_used => @info_request.law_used,
+ :tags => @info_request.tag_array,
+
+ # not sure we need to make these, mainly anti-spam, admin params public
+ # allow_new_responses_from
+ # handle_rejected_responses
+
+ :info_request_events => @info_request_events.map { |e| {
+ :id => e.id,
+ :event_type => e.event_type,
+ # params_yaml has possibly sensitive data in it, don't include it
+ :created_at => e.created_at,
+ :described_state => e.described_state,
+ :calculated_state => e.calculated_state,
+ :last_described_at => e.last_described_at,
+ :incoming_message_id => e.incoming_message_id,
+ :outgoing_message_id => e.outgoing_message_id,
+ :comment_id => e.comment_id,
+ # XXX would be nice to add links here, but alas the
+ # code to make them is in views only. See views/request/details.rhtml
+ } }
+
+ }
+ }
+ end
end
# Extra info about a request, such as event history
diff --git a/app/views/help/api.rhtml b/app/views/help/api.rhtml
index f984bed4d..6f34755b2 100644
--- a/app/views/help/api.rhtml
+++ b/app/views/help/api.rhtml
@@ -14,7 +14,9 @@ interact with WhatDoTheyKnow via an "API".
lots of things that are similar in use to an API as they are requested.
</p>
-<h2> Linking to new requests </h2>
+<hr>
+
+<h2> 1. Linking to new requests </h2>
<p>To encourage your users to make links to a particular public authority, use URLs of the form
<%= link_to new_request_to_body_url(:url_name => "liverpool_city_council") , new_request_to_body_url(:url_name => "liverpool_city_council") %>.
@@ -27,18 +29,39 @@ These are the parameters you can add to those URLs, either in the URL or from a
<li> <strong>tags</strong> - space separated list of tags, so you can find and link up any requests made later, e.g. <em>openlylocal spending_id:12345</em>. The : indicates it is a machine tag. The values of machine tags may also include colons, useful for URIs.
</ul>
-<h2> RSS (actually, Atom) feeds </h2>
+<hr>
+
+<h2> 2. RSS (actually, Atom) feeds </h2>
<p>There are Atom feeds throughout the site, which you can use to get updates
-and links in XML format.
+and links in XML format. Find the URL of the Atom feed in one of these ways:
+<ul>
+ <li>Look for the <img src="/images/feed-16.png" alt=""> RSS feed links.</li>
+ <li>Examine the <tt>&lt;link rel="alternate" type="application/atom+xml"&gt;</tt> tag in the head of the HTML. </li>
+ <li>Add <tt>/feed</tt> to the start of another URL.
+</ul>
-<p>In particular, search queries, however complicated, all have Atom feeds.
+<p>In particular, even complicated search queries have Atom feeds.
You can do all sorts of things with them, such as query by authority, by file
-type, by date range, by status. See the <a href="/search">advanced search
+type, by date range, or by status. See the <a href="/search">advanced search
tips</a> for details.
-<dl>
+<hr>
+
+<h2> 3. JSON structured data </h2>
+
+<p>Request and public authority pages have JSON feeds, which let you download
+information about objects in a structured form. Find them by:
+<ul>
+ <li>Adding <tt>.json</tt> to the end of the URL. </li>
+ <li>Look for the <tt>&lt;link rel="alternate" type="application/json"&gt;</tt> tag in the head of the HTML. </li>
+</ul>
+</p>
+
+<hr>
+<p>Please <a href="/help/contact">contact us</a> if you need an API feature that isn't there yet. It's
+very much a work in progress, and we do add things when people ask us to.</p>
<div id="hash_link_padding"></div>
diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml
index c5466964d..ca8904005 100644
--- a/app/views/layouts/default.rhtml
+++ b/app/views/layouts/default.rhtml
@@ -30,6 +30,9 @@
<link rel="alternate" type="application/atom+xml" title="<%=h feed[:title] %>" href="<%=h feed[:url]%>">
<% end %>
<% end %>
+ <% if @has_json %>
+ <link rel="alternate" type="application/json" title="JSON version" href="<%=h main_url(request.request_uri) %>.json">
+ <% end %>
<% if @no_crawl %>
<meta name="robots" content="noindex, nofollow">
diff --git a/app/views/request/details.rhtml b/app/views/request/details.rhtml
index db7e652f6..03e5148ef 100644
--- a/app/views/request/details.rhtml
+++ b/app/views/request/details.rhtml
@@ -51,4 +51,5 @@ the most recent event had its status updated to that value. <strong>calculated</
WhatDoTheyKnow for intermediate events, which weren't given an explicit
description by a user. See the <a href="/search">search tips</a> for description of the states.</p>
-
+<p>You can get this page in computer-readable format as part of the main JSON
+page for the request. See the <a href="/help/api">API documentation</a>.</p>
diff --git a/config/routes.rb b/config/routes.rb
index e4d6132a9..a54884088 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -37,6 +37,7 @@ ActionController::Routing::Routes.draw do |map|
request.new_request_to_body '/new/:url_name', :action => 'new'
request.show_request '/request/:url_title', :action => 'show'
+ request.show_request '/request/:url_title.:format', :action => 'show'
request.details_request '/details/request/:url_title', :action => 'details'
request.similar_request '/similar/request/:url_title', :action => 'similar'
@@ -81,6 +82,7 @@ ActionController::Routing::Routes.draw do |map|
body.list_public_bodies "/body/list/:tag", :action => 'list'
body.list_public_bodies_redirect "/local/:tag", :action => 'list_redirect'
body.show_public_body "/body/:url_name", :action => 'show'
+ body.show_public_body "/body/:url_name.:format", :action => 'show'
body.view_public_body_email "/body/:url_name/view_email", :action => 'view_email'
body.all_public_bodies_csv "/body/all-authorities.csv", :action => 'list_all_csv'
end
diff --git a/vendor/plugins/has_tag_string/lib/has_tag_string.rb b/vendor/plugins/has_tag_string/lib/has_tag_string.rb
index fdcc35a55..5382067fb 100644
--- a/vendor/plugins/has_tag_string/lib/has_tag_string.rb
+++ b/vendor/plugins/has_tag_string/lib/has_tag_string.rb
@@ -80,6 +80,11 @@ module HasTagString
return self.tags.map { |t| t.name_and_value }.join(' ')
end
+ # Returns the tags the model has, as an array of strings
+ def tag_array
+ return self.tags.map { |t| [t.name, t.value] }
+ end
+
# Test to see if class is tagged with the given tag
def has_tag?(tag_as_string)
for tag in self.tags