def parseNotification()

in anghammarad/src/main/scala/com/gu/anghammarad/serialization/Serialization.scala [42:55]


  def parseNotification(snsEvent: SNSEvent): Try[Notification] = {
    val maybeSns = snsEvent.getRecords.asScala.toList match {
      case singleRecord :: Nil => Success(singleRecord.getSNS)
      case _ => Fail(s"Found multiple SNSRecords")
    }

    for {
      sns <- maybeSns
      subject = sns.getSubject
      message = sns.getMessage
      jsonMsg <- parse(message).toTry
      notification <- generateNotification(subject, jsonMsg)
    } yield notification
  }