guardian/content-api-scala-client — pull request #59 by adamnfish (2014-11-28 16:11:37+00:00)
Title: Separates queries from their execution

This allows users of the library to create CAPI queries without having access to a configured API client - it breaks the dependency between configuration, models and the execution of queries.

For example, someone building their own client library (for another team here, say) that needs to make CAPI calls as part of its working, we can now build instances of ItemQuery and and return them to the application for alteration (e.g. adding application-specific parameters) before executing the query. This was previously not possible because the ItemQuery type was accessable only from within a configured CAPI client. Beyond not being able to create instances of queries, this means it wasn't even possible to specify a function that uses those types e.g. `addAppParams(query: ItemQuery): ItemQuery`.

We move the query types out into the models package and remove their dependency on configuration properties like the api-key. In their place, we provide implicit conversions to restore this behaviour for existing clients along with providing new methods to execute these queries directly.

For existing clients using the `GuardianContentClient` class, compatibility is maintained by importing `.Results._`. For those using the trait they would import `Results._`. This backwards compatibility includes the `response` method as well as other helpers like `asResponse` and the `as` methods.

@mchv has mentioned IRL that backwards compatibility may not be a priority for the team. If this is the case, these implicits can be removed in favour of directly executing the query from the new execute methods. I submit this PR with them because that represents that fundamental interface to the client at the moment and I'd like to prove that this doesn't undermine that.

Let's chat.

p.s. git has made a an outrageous mess of this diff for `GuardianContentClient.scala`. It's much simpler than it looks:

* remove the models
* replace them with the Results object
* add `url` method so we can still test the API key gets added