in eventbrite-consents/src/main/scala/com/gu/identity/eventbriteconsents/clients/EventbriteClient.scala [14:41]
def findConsents(credentials: EventbriteCredentials, lastRun: Instant, continuationToken: String = ""): EventbriteResponse = {
val formattedLastRun = DateTimeFormatter
.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
.withZone(ZoneId.of("UTC"))
.format(lastRun)
val response = Http(s"https://www.eventbriteapi.com/v3/organizations/${credentials.organisationId}/attendees/")
.headers(
"Authorization" -> s"Bearer ${credentials.token}",
"Accept" -> "application/json"
)
.params(
"status" -> "attending",
"changed_since" -> formattedLastRun,
"continuation" -> continuationToken
)
.timeout(2000, 10000)
.asString
if (response.code == 200) {
parse(response.body).flatMap(_.as[EventbriteResponse]) match {
case Right(response) => response
case Left(error) => throw new RuntimeException(s"unable to deserialise ${response.body}", error)
}
} else {
throw new RuntimeException(s"unexpected response from eventbrite ${response.code} ${response.body}")
}
}