def parseMediaAtom()

in common/src/main/scala/com/gu/media/util/ThriftUtil.scala [67:99]


  def parseMediaAtom(params: Map[String, Seq[String]]): ThriftResult[MediaAtom] = {
    val version = params.get("version").map(_.head.toLong).getOrElse(1L)
    val title = params.get("title").map(_.head) getOrElse "unknown"
    val category = params.get("category").map(_.head) match {
      case Some("documentary") => Category.Documentary
      case Some("explainer") => Category.Explainer
      case Some("feature") => Category.Feature
      case Some("hosted") => Category.Hosted
      case _ => Category.News
    }
    val description = params.get("description").map(_.head)
    val duration = params.get("duration").map(_.head.toLong)
    val source = params.get("source").map(_.head)
    val posterUrl = params.get("posterUrl").map(_.head).flatMap {
      case Url(url) => Some(url)
      case _ => None
    }
    for {
      assets <- parseAssets(params.getOrElse("uri", Nil), version).right
      metadata <- parseMetadata(params.getOrElse("metadata", Nil)).right
    } yield MediaAtom(
      assets = assets,
      activeVersion = Some(version),
      title = title,
      category = category,
      plutoProjectId = None,
      duration = duration,
      source = source,
      posterUrl = posterUrl,
      description = description,
      metadata = metadata
    )
  }