def generateNotification()

in anghammarad/src/main/scala/com/gu/anghammarad/serialization/Serialization.scala [57:72]


  def generateNotification(subject: String, content: Json): Try[Notification] = {
    val hCursor = content.hcursor
    val parsingResult = for {
      sourceSystem <- hCursor.downField("sender").as[String]
      rawTargets <- hCursor.downField("target").as[Json]
      rawChannel <- hCursor.downField("channel").as[String]
      rawActions <- hCursor.downField("actions").as[List[Json]]
      message <- hCursor.downField("message").as[String]
      threadKey <- hCursor.downField("threadKey").as[Option[String]]
      channel <- parseRequestedChannel(rawChannel).toEither
      targets <- parseAllTargets(rawTargets).toEither
      actions <- rawActions.traverseT(parseAction).toEither
    } yield Notification(subject, message, actions, targets, channel, sourceSystem, threadKey)

    parsingResult.toTry
  }