in src/main/scala/com/gu/fastly/Lambda.scala [213:243]
def sendFastlyPurgeRequest(
contentId: String,
purgeType: PurgeType,
serviceId: String,
surrogateKey: String,
fastlyApiKey: String,
contentType: Option[ContentType] = None
): Boolean = {
val url = s"https://api.fastly.com/service/$serviceId/purge/$surrogateKey"
val requestBuilder = new Request.Builder()
.url(url)
.header("Fastly-Key", fastlyApiKey)
.post(EmptyJsonBody)
val request = (purgeType match {
case Soft => requestBuilder.header("Fastly-Soft-Purge", "1")
case _ => requestBuilder
}).build()
val response = httpClient.newCall(request).execute()
println(
s"Sent $purgeType purge request for content with ID [$contentId], service with ID [$serviceId] and surrogate key [$surrogateKey]. Response from Fastly API: [${response.code}] [${response.body.string}]"
)
val purged = response.code == 200
sendPurgeCountMetric(contentType)
purged
}