guardian/open-platform-content-api-scala-client — pull request #20 by bmjames (2013-08-12 16:05:45+00:00)
Title: Convenient methods for custom parameters

Currently, it is difficult to add parameters to a query in a programmatic way.

The API of the client is designed to be used by calling methods named after known parameters, e.g.

val query = Api.search.q("sausages")

However, if I have a map of parameters (e.g. from user input), I have to do something hacky:

val params = Map("q" -> "sausages")
val query = ???

This patch adds methods for adding completely custom parameters to a query, e.g.

val query = Api.search.stringParam("q", "sausages")

This makes it less painful to programmatically add parameters:

val query = params.foldLeft(Api.search) {
case (query, (key, value)) => query.stringParam(key, value)
}

This could also be useful for using new parameters that are supported by the API, without waiting for a new release of the client.