in api/src/main/scala/com/gu/footballtimemachine/ApiLambda.scala [75:97]
def getPaData(request: ApiGatewayRequest): ApiGatewayResponse = {
val pathItems = request.path.drop(1).split("/")
pathItems.update(2, "apiKey")
val s3Path = pathItems.mkString("/")
println(s"accessing $s3Path")
val currentTime = computeTime
val versions = s3Client.listObjectVersions(ListObjectVersionsRequest.builder().bucket(bucket).prefix(s3Path).build()).versions().asScala.toList.sortBy(_.lastModified)
val version = versions.find(v => v.lastModified().toEpochMilli() > currentTime).getOrElse(versions.last).versionId
val gor = GetObjectRequest.builder.bucket(bucket).key(s3Path).versionId(version).build()
println(s"requesting version $version")
val s3Object = s3Client.getObject(gor)
println(s"Got version ${s3Object.response().versionId()} dated ${s3Object.response().lastModified()}")
val content = Source.fromInputStream(s3Object).mkString
ApiGatewayResponse(200, Map("Content-Type" -> "application/xml"), content)
}