Add request state updating functionality to API

WIP

Adds a new `update_state` method to the API that uses the existing API key mechanism to send a status update to a request created via an external API request. Intended usage - foi-register end-users confirming whether the information they requested has been disclosed ([the parallel work on foi-register can be found here](https://github.com/mysociety/foi-register/tree/issues/169-ask-user-to-confirm-request-state)). Status description mismatches should be handled on the foi-register side but unexpected status values are rejected with a 500 error by the API.

Adds an optional parameter to the pre-existing `add_correspondence` API method to allow it to update status (intended use - updates from a public body) if a `state` value is supplied. Again, the foi-register code is responsible for handling state description mismatches but in this case the API deals with erroneous data by ignoring that part of the request.

Apologies for having restructured `api_controller_spec` but I kept losing track of which API methods the various tests were targeting. I will be happy to change it back before finalising the Pull Request if I've caused trouble.
This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a temporary error. The following address(es) deferred:

  skenaja@gmail.com
    Domain alexskene.com has exceeded the max emails per hour (433/400 (108%)) allowed.  Message will be reattempted later

------- This is a copy of the message, including all the headers. ------
Received: from o1.sgmail.github.com ([192.254.114.176]:16589)
	by zurich.footholds.net with smtps (UNKNOWN:DHE-RSA-AES128-GCM-SHA256:128)
	(Exim 4.82)
	(envelope-from <bounces+848413-9a96-alex=alexskene.com@sgmail.github.com>)
	id 1WzpXt-0008U3-Tl
	for alex@alexskene.com; Wed, 25 Jun 2014 16:55:38 +0100
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sgmail.github.com; 
	h=from:reply-to:to:in-reply-to:references:subject:mime-version:content-type:content-transfer-encoding:list-id:list-archive:list-post:list-unsubscribe; 
	s=smtpapi; bh=ism7RCUSvSS7MAJqgz43ZuvAoIg=; b=G5qz1uH02FbHgJTiri
	Vh+79+fbc1RNYTf19EOrkSJYBm8CgIiSviC5YUNH6EEszHGOCQQB5m09FRdLrB1V
	nNnKBIxtK1jWGzaSvkoGGkOGu4MM0XvWZJ9wppjZRQgvWjVAyWKHXMiDa4LyouRq
	Kye28/nfNizxS49phjHKD0Loo=
Received: by mf163.sendgrid.net with SMTP id mf163.15442.53AAF0F01C
        Wed, 25 Jun 2014 15:55:28 +0000 (UTC)
Received: from github-smtp2b-ext-cp1-prd.iad.github.net (github-smtp2b-ext-cp1-prd.iad.github.net [192.30.253.17])
	by ismtpd-015.iad1.sendgrid.net (SG) with ESMTP id 146d3bd2c19.122d.3caf20
	for <alex@alexskene.com>; Wed, 25 Jun 2014 15:55:28 +0000 (GMT)
Date: Wed, 25 Jun 2014 08:55:28 -0700
From: Hound <notifications@github.com>
Reply-To: mysociety/alaveteli <reply@reply.github.com>
To: mysociety/alaveteli <alaveteli@noreply.github.com>
Message-ID: <mysociety/alaveteli/pull/1631/r14195060@github.com>
In-Reply-To: <mysociety/alaveteli/pull/1631@github.com>
References: <mysociety/alaveteli/pull/1631@github.com>
Subject: Re: [alaveteli] Add request state updating functionality to API
 (#1631)
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_53aaf0f058579_359f3fb9f97cb29c551ac";
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Precedence: list
X-GitHub-Recipient: skenaja
List-ID: mysociety/alaveteli <alaveteli.mysociety.github.com>
List-Archive: https://github.com/mysociety/alaveteli
List-Post: <mailto:reply@reply.github.com>
List-Unsubscribe: <mailto:unsub+p-14195060-0a3bde067e0a7d341423f61eaad645f621f53f27-510285@reply.github.com>,
 <https://github.com/notifications/unsubscribe/510285__eyJzY29wZSI6Ik5ld3NpZXM6TXV0ZSIsImV4cGlyZXMiOjE3MTkzMzA5MjgsImRhdGEiOnsiaWQiOjM1MzExOTc0fX0=--37b4288a3c8ea75b54c1d74d91251717b6ef5eff>
X-Auto-Response-Suppress: All
X-GitHub-Recipient-Address: alex@alexskene.com
X-SG-EID: hQ+xzKT9K37JzZfKEXr3QNageyq61ruQMWnl5rBwpIIXbkMyxUNYpcnLbKHxD7SBORL+g+wejF9O6e//gninZVgms1roqhCasZtkRBPAx8mTVAEw2tDqJIVqI0rx+EUkPlPTN3HycOG7gnVUCXcywDhDV//Z5kz06bMT3grk9As=

----==_mimepart_53aaf0f058579_359f3fb9f97cb29c551ac
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

>      end
>  
> -    it "should create a new request from a POST" do
> -        number_of_requests = InfoRequest.count(
> +    def _create_request
> +        post :create_request,
> +             :k => public_bodies(:geraldine_public_body).api_key,
> +             :request_json => {
> +                 "title" => "Tell me about your chickens",
> +                 "body" => "Dear Sir,\n\nI should like to know about your chickens.\n\nYours in faith,\nBob\n",
> +                  "external_url" => "http://www.example.gov.uk/foi/chickens_23",
> +                 "external_user_name" => "Bob Smith",
> +             }.to_json
> +        response.content_type.should == "application/json"
> +        return ActiveSupport::JSON.decode(response.body)["id"]

Redundant `return` detected.<br>Prefer single-quoted strings when you don't need string interpolation or special symbols.

---
Reply to this email directly or view it on GitHub:
https://github.com/mysociety/alaveteli/pull/1631/files#r14195060
----==_mimepart_53aaf0f058579_359f3fb9f97cb29c551ac
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>In spec/controllers/api_controller_spec.rb:</p>
<pre style='color:#555'>&gt;      end
&gt;  
&gt; -    it &quot;should create a new request from a POST&quot; do
&gt; -        number_of_requests = InfoRequest.count(
&gt; +    def _create_request
&gt; +        post :create_request,
&gt; +             :k =&gt; public_bodies(:geraldine_public_body).api_key,
&gt; +             :request_json =&gt; {
&gt; +                 &quot;title&quot; =&gt; &quot;Tell me about your chickens&quot;,
&gt; +                 &quot;body&quot; =&gt; &quot;Dear Sir,\n\nI should like to know about your chickens.\n\nYours in faith,\nBob\n&quot;,
&gt; +                  &quot;external_url&quot; =&gt; &quot;http://www.example.gov.uk/foi/chickens_23&quot;,
&gt; +                 &quot;external_user_name&quot; =&gt; &quot;Bob Smith&quot;,
&gt; +             }.to_json
&gt; +        response.content_type.should == &quot;application/json&quot;
&gt; +        return ActiveSupport::JSON.decode(response.body)[&quot;id&quot;]
</pre>
<p>Redundant <code>return</code> detected.<br>Prefer single-quoted strings when you don't need string interpolation or special symbols.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/mysociety/alaveteli/pull/1631/files#r14195060">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/510285__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxOTMzMDkyOCwiZGF0YSI6eyJpZCI6MzUzMTE5NzR9fQ==--d7058fe35f91687ac9e7fd2bb8a6257db449f1e6.gif" width="1" /></p>
----==_mimepart_53aaf0f058579_359f3fb9f97cb29c551ac--