play.boilerplate.api.server.dsl.Compat.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of play-boilerplate-api-server-play26_2.11 Show documentation
Show all versions of play-boilerplate-api-server-play26_2.11 Show documentation
play-boilerplate-api-server-play26
The newest version!
package play.boilerplate.api.server.dsl
import play.api.http.Writeable
import play.api.mvc.AnyContent
object Compat extends AbstractCompat {
implicit class AnyContentOps(val body: AnyContent) extends AnyVal {
def dataPart(key: String): Option[String] = {
body.asMultipartFormData.flatMap(_.dataParts.get(key)).flatMap(_.headOption)
}
def file(key: String): Option[java.io.File] = {
body.asMultipartFormData.flatMap(_.file(key)).map(_.ref.path.toFile)
}
def formValue(key: String): Option[String] = {
body.asFormUrlEncoded.flatMap(_.get(key)).flatMap(_.headOption)
}
}
implicit def contentOps[C](implicit wr: Writeable[C]): PrintableContent[C] =
PrintableContent(content => wr.transform(content).utf8String)
}