This repository has been archived by the owner on Feb 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from kailuowang/master
getting ready for release.
- Loading branch information
Showing
17 changed files
with
236 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
play-dsl-akka/src/main/scala/com/iheart/play/dsl/akka/Syntax.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
play-dsl-core/src/main/scala/com/iheart/play/dsl/CatsInstances.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.iheart.play.dsl | ||
|
||
import cats.Monad | ||
import cats.functor.Contravariant | ||
|
||
import scala.concurrent.Future | ||
|
||
object CatsInstances { | ||
|
||
implicit val futureMonad: Monad[Future] = new Monad[Future] { | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
def pure[A](x: A): Future[A] = Future.successful(x) | ||
|
||
def flatMap[A, B](fa: Future[A])(f: (A) ⇒ Future[B]): Future[B] = fa flatMap f | ||
} | ||
|
||
implicit def partialFunctionContravariant[R]: Contravariant[PartialFunction[?, R]] = | ||
new Contravariant[PartialFunction[?, R]] { | ||
def contramap[T1, T0](pa: PartialFunction[T1, R])(f: T0 ⇒ T1) = new PartialFunction[T0, R] { | ||
def isDefinedAt(x: T0): Boolean = pa.isDefinedAt(f(x)) | ||
def apply(x: T0): R = pa(f(x)) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
play-dsl-core/src/main/scala/com/iheart/play/dsl/ScalaCatsInstances.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
play-dsl-core/src/main/scala/com/iheart/play/dsl/extractors/AuthInfoExtractorBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.iheart.play.dsl.extractors | ||
|
||
import cats.data.Xor | ||
import com.iheart.play.dsl.Extractor | ||
import play.api.mvc.RequestHeader | ||
import play.api.mvc.Results._ | ||
import shapeless.HList | ||
|
||
import scala.concurrent.Future | ||
|
||
class AuthInfoExtractorBuilder[AuthInfoT](buildAuthInfo: RequestHeader ⇒ Future[Either[String, AuthInfoT]]) { | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
def apply[Repr <: HList](toRecord: AuthInfoT ⇒ Repr): Extractor[Repr] = { req ⇒ | ||
buildAuthInfo(req).map { | ||
case Left(msg) ⇒ Xor.Left(Unauthorized(msg)) | ||
case Right(authInfo) ⇒ Xor.Right(toRecord(authInfo)) | ||
} | ||
} | ||
} |
21 changes: 14 additions & 7 deletions
21
play-dsl-core/src/main/scala/com/iheart/play/dsl/filters/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
package com.iheart.play.dsl | ||
|
||
import org.joda.time.DateTime | ||
import play.api.mvc.Results._ | ||
import play.api.cache.CacheApi | ||
|
||
import scala.concurrent.Future | ||
import scala.concurrent.duration.Duration | ||
|
||
package object filters { | ||
|
||
def notFoundIfEmpty[RMT, OT]( | ||
fieldExtractor: RMT ⇒ Option[OT], | ||
notFoundMessage: Option[String] = None | ||
): Filter[RMT] = (req, result) ⇒ { | ||
def caching[RMT](duration: Duration)(implicit cache: CacheApi): Filter[RMT] = | ||
(req, result) ⇒ cache.getOrElse(req.body.toString)(result) | ||
|
||
val notFoundResult = Future.successful(NotFound(notFoundMessage.getOrElse(""))) | ||
fieldExtractor(req.body).fold(notFoundResult)(_ ⇒ result) | ||
def eTag[T](getETag: T ⇒ DateTime): Filter[T] = { (req, result) ⇒ | ||
import play.api.libs.concurrent.Execution.Implicits._ | ||
import play.api.http.HeaderNames.ETAG | ||
val eTAGInRequest = req.headers.get(ETAG) | ||
val rse = getETag(req.body) | ||
eTAGInRequest match { | ||
case Some(e) if e.toLong == rse.getMillis ⇒ Future.successful(NotModified) | ||
case _ ⇒ result.map(_.withHeaders(ETAG → rse.getMillis.toString)) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.