Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api for structured variants #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ import io.cardell.ff4s.flipt.model.BooleanEvaluationResponse
import io.cardell.ff4s.flipt.model.VariantEvaluationResponse
import io.cardell.ff4s.flipt.model.BatchEvaluationRequest
import io.cardell.ff4s.flipt.model.BatchEvaluationResponse
import io.circe.Decoder
import io.cardell.ff4s.flipt.model.StructuredVariantEvaluationResponse

trait FliptApi[F[_]] {
def evaluateBoolean(request: EvaluationRequest): F[BooleanEvaluationResponse]
def evaluateVariant(request: EvaluationRequest): F[VariantEvaluationResponse]
def evaluateStructuredVariant[A: Decoder](
request: EvaluationRequest
): F[StructuredVariantEvaluationResponse[A]]
def evaluateBatch(request: BatchEvaluationRequest): F[BatchEvaluationResponse]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import io.cardell.ff4s.flipt.model.BooleanEvaluationResponse
import io.cardell.ff4s.flipt.model.VariantEvaluationResponse
import io.cardell.ff4s.flipt.model.BatchEvaluationRequest
import io.cardell.ff4s.flipt.model.BatchEvaluationResponse
import io.circe.Decoder
import io.cardell.ff4s.flipt.model.StructuredVariantEvaluationResponse

protected[flipt] class FliptApiImpl[F[_]: Concurrent](
client: Client[F],
Expand Down Expand Up @@ -53,6 +55,17 @@ protected[flipt] class FliptApiImpl[F[_]: Concurrent](
client.expect[VariantEvaluationResponse](req)
}

override def evaluateStructuredVariant[A: Decoder](
request: EvaluationRequest
): F[StructuredVariantEvaluationResponse[A]] = {
val req = Request[F](
method = Method.POST,
uri = baseUri / "evaluate" / "v1" / "variant"
).withEntity(request)

client.expect[StructuredVariantEvaluationResponse[A]](req)
}

override def evaluateBatch(
request: BatchEvaluationRequest
): F[BatchEvaluationResponse] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.cardell.ff4s.flipt.model
import cats.syntax.functor._
import io.circe.Decoder
import io.circe.generic.semiauto.deriveDecoder
import scala.annotation.unused

sealed trait EvaluationResponse

Expand Down Expand Up @@ -58,6 +59,23 @@ object VariantEvaluationResponse {
implicit val d: Decoder[VariantEvaluationResponse] = deriveDecoder
}

case class StructuredVariantEvaluationResponse[A](
`match`: Boolean,
segmentKeys: List[String],
reason: EvaluationReason,
flagKey: String,
variantKey: String,
variantAttachment: A,
requestDurationMillis: Float,
timestamp: String
) extends EvaluationResponse

object StructuredVariantEvaluationResponse {
implicit def d[A](implicit
@unused da: Decoder[A]
): Decoder[StructuredVariantEvaluationResponse[A]] = deriveDecoder
}

case class ErrorEvaluationResponse(
flagKey: String,
namespaceKey: String,
Expand Down