in client/src/main/scala/com.gu.contentapi.client/ContentApiClient.scala [64:95]
def url(contentApiQuery: ContentApiQuery[_]): String =
contentApiQuery.getUrl(targetUrl, parameters)
/** Runs the query against the Content API.
*
* @tparam Q the type of a Content API query
* @param query the query
* @return a future resolving to an unmarshalled response
*/
def getResponse[R <: ThriftStruct](query: ContentApiQuery[R])(
implicit
decoder: Decoder[R],
context: ExecutionContext): Future[R] =
fetchResponse(query) map decoder.decode
/** Unfolds a query to its results, page by page
*
* @param query the initial query
* @tparam R the response type expected for this query
* @tparam E the 'element' type for the list of elements returned in the response - eg 'Tag' for 'TagsResponse'
* @tparam M a type specified by the caller to summarise the results of each response. Eg, might be `Seq[E]`
* @param f a result-processing function that converts the standard response type to the `M` type
* @return a future of a list of result-processed results (eg, if `M` = `Seq[E]`, the final result is `List[Seq[E]]`)
*/
// `R : Decoder` is a Scala 'context-bound', and means "To compile I need an implicit instance of `Decoder[R]`!"
def paginate[R <: ThriftStruct: Decoder, E, M](query: PaginatedApiQuery[R, E])(f: R => M)(
implicit
context: ExecutionContext
): Future[List[M]] =
unfoldM { r: R =>
(f(r), query.followingQueryGiven(r, Next).map(getResponse(_)))
}(getResponse(query))