Skip to content

Instantly share code, notes, and snippets.

View marekzebrowski's full-sized avatar

Marek Żebrowski marekzebrowski

View GitHub Profile
@marekzebrowski
marekzebrowski / Field.scala
Last active July 19, 2016 15:05
shapeless record try
package me.sgrouples.rogue
import io.fsq.field.Field
import shapeless._
import labelled.{FieldType, field}
import syntax.singleton._
import record._
import ops.record._
import org.bson.{BsonDocument, BsonNull, BsonValue}
import shapeless.syntax.SingletonOps
@marekzebrowski
marekzebrowski / httpclient.scala
Created March 29, 2016 18:49
simplifications of http-client
trait HttpClient {
implicit def system: ActorSystem
implicit def materializer: ActorMaterializer
def connectionContext: HttpsConnectionContext
protected val http = Http()
//execs only if result was successful
@marekzebrowski
marekzebrowski / HttpAuth.scala
Created March 29, 2016 18:28
akka-http-auth-help
def logUserIn(token:String):Future[Option[UserId]] = ???
val withUserId: Directive1[User.Id] = {
extractExecutionContext.flatMap { implicit ec =>
headerValueByType[Authorization]().flatMap { authHdr =>
{
onSuccess(logUserIn(authHdr)).flatMap {
case Some(userId) => provide[UserId](userId): Directive1[UserId]
case None => reject(MissingHeaderRejection(Authorization.name)): Directive1[UserId]
}