当前位置: 首页>>代码示例>>Scala>>正文


Scala CirceSupport类代码示例

本文整理汇总了Scala中de.heikoseeberger.akkahttpcirce.CirceSupport的典型用法代码示例。如果您正苦于以下问题:Scala CirceSupport类的具体用法?Scala CirceSupport怎么用?Scala CirceSupport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CirceSupport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: AuthServiceRoute

//设置package包名称以及导入依赖的类
package com.noedominguez.class_orchestration.restapi.http.routes

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Directives._
import com.noedominguez.class_orchestration.restapi.models.UserEntity
import com.noedominguez.class_orchestration.restapi.services.AuthService
import com.noedominguez.class_orchestration.restapi.http.SecurityDirectives
import de.heikoseeberger.akkahttpcirce.CirceSupport
import io.circe.generic.auto._
import io.circe.syntax._
import scala.concurrent.ExecutionContext

class AuthServiceRoute(val authService: AuthService)(implicit executionContext: ExecutionContext) extends CirceSupport with SecurityDirectives {

  import StatusCodes._
  import authService._

  val route = pathPrefix("auth") {
    path("signIn") {
      pathEndOrSingleSlash {
        post {
          entity(as[LoginPassword]) { loginPassword =>
            complete(signIn(loginPassword.login, loginPassword.password).map(_.asJson))
          }
        }
      }
    } ~
      path("signUp") {
        pathEndOrSingleSlash {
          post {
            entity(as[UserEntity]) { userEntity =>
              complete(Created -> signUp(userEntity).map(_.asJson))
            }
          }
        }
      }
  }

  private case class LoginPassword(login: String, password: String)

} 
开发者ID:poguez,项目名称:class_orchestration_api,代码行数:42,代码来源:AuthServiceRoute.scala

示例2: provisionUsersList

//设置package包名称以及导入依赖的类
package com.arisanet

import akka.http.scaladsl.testkit.ScalatestRouteTest
import de.heikoseeberger.akkahttpcirce.CirceSupport
import com.noedominguez.class_orchestration.restapi.http.HttpService
import com.noedominguez.class_orchestration.restapi.models.UserEntity
import com.noedominguez.class_orchestration.restapi.services.{AuthService, ExplorationsService, ExplorationEventsService, TeamsService, UsersService, ExplorationObjectsService}
import com.noedominguez.class_orchestration.restapi.utils.DatabaseService
import com.arisanet.utils.InMemoryPostgresStorage._
import org.scalatest._

import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.util.Random

trait BaseServiceTest extends WordSpec with Matchers with ScalatestRouteTest with CirceSupport {

  dbProcess.getProcessId

  private val databaseService = new DatabaseService(jdbcUrl, dbUser, dbPassword)

  val usersService = new UsersService(databaseService)
  val authService = new AuthService(databaseService)(usersService)
  val teamsService = new TeamsService(databaseService)
  val explorationsService = new ExplorationsService(databaseService)
  val explorationEventsService = new ExplorationEventsService(databaseService)
  val explorationObjectsService = new ExplorationObjectsService(databaseService)
  val httpService = new HttpService(usersService, authService, teamsService, explorationsService, explorationEventsService, explorationObjectsService)

  def provisionUsersList(size: Int): Seq[UserEntity] = {
    val savedUsers = (1 to size).map { _ =>
      UserEntity(Some(Random.nextLong()),
                  Random.nextString(10),
                  Random.nextString(10),
                  Random.nextBoolean(),
                  Some(0L))
    }.map(usersService.createUser)

    Await.result(Future.sequence(savedUsers), 10.seconds)
  }

  def provisionTokensForUsers(usersList: Seq[UserEntity]) = {
    val savedTokens = usersList.map(authService.createToken)
    Await.result(Future.sequence(savedTokens), 10.seconds)
  }

} 
开发者ID:poguez,项目名称:class_orchestration_api,代码行数:48,代码来源:BaseServiceTest.scala

示例3: AboutHttpHandler

//设置package包名称以及导入依赖的类
package im.actor.server.api.http.info

import akka.actor.ActorSystem
import akka.http.scaladsl.model.StatusCodes.OK
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import de.heikoseeberger.akkahttpcirce.CirceSupport
import im.actor.config.ActorConfig
import im.actor.server.api.http.HttpHandler
import im.actor.server.api.http.json.{ JsonEncoders, ServerInfo }

import scala.collection.JavaConversions._

private[http] final class AboutHttpHandler()(implicit system: ActorSystem) extends HttpHandler
  with CirceSupport
  with JsonEncoders {

  private lazy val about = getServerInfo

  def routes: Route = path("about") {
    get {
      complete(OK ? about)
    }
  }

  private def getServerInfo: ServerInfo =
    ServerInfo(
      projectName = ActorConfig.projectName,
      endpoints = ActorConfig.load().getStringList("public-endpoints").toList
    )

} 
开发者ID:wex5,项目名称:dangchat-server,代码行数:33,代码来源:AboutHttpHandler.scala

示例4: GatewayRoute

//设置package包名称以及导入依赖的类
package gateway.restapi.http.routes

import akka.http.scaladsl.server.Directives._
import de.heikoseeberger.akkahttpcirce.CirceSupport
import gateway.restapi.domain._
import gateway.restapi.services.{TransactionsService, WalletsService}
import io.circe.generic.auto._
import io.circe.syntax._

class GatewayRoute (val transactionsService: TransactionsService, val walletsService: WalletsService)
                   extends CirceSupport {

  // 1. use POST method here, because it's secure: http://blog.teamtreehouse.com/the-definitive-guide-to-get-vs-post
  // 2. when dealing with multiple fields of data in transaction: shift to object or collection of key/value POST
  // 3. allow transaction with amount == 0 for testing/debuging purposes

  import transactionsService._

  val route =
  pathPrefix("gateway") {
    path("process") {
      pathEndOrSingleSlash {
        post {
          parameters('paymenttype.as[String], 'issuer.as[String].?, 'receiver.as[String].?, 'currency.as[String].?, 'amount.as[String]) {
            (paymenttype, issuer, receiver, currency, amount) =>
              complete {
                val entity = processTransaction(
                  TransactionModel(
                    None,
                    issuer,
                    receiver,
                    None,
                    CheckModelConverter.OptStringToCurrency(currency).toString,
                    amount,
                    TransactionStatus.Pending.toString,
                    paymenttype)
                )
                val model = TransactionConverter.EntityToModel(entity)
                model.map(_.asJson)
              }
          }
        }
      }
    } ~
      path("wallet") {
        pathEndOrSingleSlash {
          post {
            parameters('clientId.as[String], 'currency.as[String].?) {
              (clientId, currency) =>
                complete {
                  val entity = walletsService.getTotalByClient(clientId, CheckModelConverter.OptStringToCurrency(currency))
                  val model = WalletConverter.EntityToModel(entity)
                  EncoderOps(model).asJson // since not an Option
                }
            }
          }
        }
      }
    // todo: transaction statuses external updates. like 2 phase auth with sms.
  }
} 
开发者ID:kartavtcev,项目名称:gateway-sketch,代码行数:62,代码来源:GatewayRoute.scala

示例5: cleanContext

//设置package包名称以及导入依赖的类
package gateway.restapi

import akka.actor.ActorSystem
import akka.event.{Logging, LoggingAdapter}
import akka.http.scaladsl.testkit.ScalatestRouteTest
import de.heikoseeberger.akkahttpcirce.CirceSupport
import gateway.restapi.domain.ClientEnitity
import gateway.restapi.domain.storagecontext.StorageContext
import gateway.restapi.http.HttpService
import gateway.restapi.services.{ClientsService, TransactionsService, WalletsService}
import org.scalatest._

import scala.util.Random

trait BaseServiceTest extends WordSpec with Matchers with ScalatestRouteTest with CirceSupport {

  implicit val actorSystem = ActorSystem("gateway-sketch-rest-api-test")
  implicit val log: LoggingAdapter = Logging(actorSystem, getClass)

  val clientsService = new ClientsService(StorageContext.instanceTest)
  val walletsService = new WalletsService(StorageContext.instanceTest)
  val transactionService = new TransactionsService(StorageContext.instanceTest, walletsService)
  val httpService = new HttpService(clientsService, transactionService, walletsService)

  def cleanContext : Unit = { StorageContext.instanceTest.clean() } // todo: replace this hack ro reset/clear Context with better language/scala test feature
  def provisionClientsList(size: Int): Seq[ClientEnitity] = {
    (1 to size).map { _ =>
      clientsService.createClient(ClientEnitity(None, Random.nextString(10)))
    }
    StorageContext.instanceTest.getClients
  }
  def getTransactionService = transactionService
} 
开发者ID:kartavtcev,项目名称:gateway-sketch,代码行数:34,代码来源:BaseServiceTest.scala

示例6: AccountRequests

//设置package包名称以及导入依赖的类
package com.kimstebel.alexa

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpRequest
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.ActorMaterializer
import com.kimstebel.alexa.AccountResponses.{Readings, Reading}
import de.heikoseeberger.akkahttpcirce.CirceSupport
import io.circe.generic.auto._

import scala.concurrent.{ExecutionContext, Future}

final case class AccountRequests(accountId: String)(
    implicit context: ExecutionContext,
    system: ActorSystem,
    materializer: ActorMaterializer
) extends CirceSupport {

  private[this] def accountUrl(relativePath: String) =
    s"http://meters.uat.ptl.ovotech.org.uk/accounts/$accountId$relativePath?source=DTMF"

  def fetchReadings(): Future[List[Readings]] =
    Http()
      .singleRequest(HttpRequest(uri = accountUrl("/readings")))
      .flatMap(response ? Unmarshal(response).to[List[Readings]])

  def fetchLatestElectricityReading(): Future[Option[Reading]] =
    fetchReadings().map { readings ?
      readings
        .find(_.chargeItem == "Electricity")
        .flatMap(_.readings.find(_.actual))
    }
} 
开发者ID:KimStebel,项目名称:magic8ball,代码行数:35,代码来源:AccountRequests.scala

示例7: RootHandler

//设置package包名称以及导入依赖的类
package jp.co.dzl.example.akka.api.handler

import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.server.Directives._
import de.heikoseeberger.akkahttpcirce.CirceSupport
import jp.co.dzl.example.akka.api.response.MessageResponse
import io.circe.generic.auto._

class RootHandler(handlers: List[Handler]) extends Handler with CirceSupport {
  def routes = {
    val root = pathSingleSlash {
      get {
        complete(OK -> MessageResponse("Hello, example for reverse proxy"))
      }
    }

    handlers.foldRight(root)(_.routes ~ _)
  }
} 
开发者ID:dazzle-lab,项目名称:akka-api-gateway-example,代码行数:20,代码来源:RootHandler.scala

示例8: EventsServiceRoute

//设置package包名称以及导入依赖的类
package smarthouse.restapi.http.routes

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Directives._
import de.heikoseeberger.akkahttpcirce.CirceSupport
import io.circe.generic.auto._
import io.circe.syntax._
import smarthouse.restapi.http.SecurityDirectives
import smarthouse.restapi.models.EventEntity
import smarthouse.restapi.services.{AuthService, EventsService}

import scala.concurrent.ExecutionContext

class EventsServiceRoute(val authService: AuthService,
                         val eventService: EventsService)
                        (implicit executionContext: ExecutionContext) extends CirceSupport with SecurityDirectives {

  import StatusCodes._
  import authService._
  import eventService._

  val route = pathPrefix("events") {
    path("all") {
      pathEndOrSingleSlash {
        get {
          complete(getEvents().map(_.asJson))
        }
      }
    } ~
      path("add") {
        pathEndOrSingleSlash {
          post {
            entity(as[EventEntity]) { entity =>
              complete(Created -> createEvent(entity).map(_.asJson))
            }
          }
        }
      }
  }
} 
开发者ID:andrewobukhov,项目名称:smart-house,代码行数:41,代码来源:EventsServiceRoute.scala

示例9: DevicesServiceRoute

//设置package包名称以及导入依赖的类
package smarthouse.restapi.http.routes

import java.util.Date

import akka.http.scaladsl.model.{StatusCodes}
import akka.http.scaladsl.server.Directives._
import de.heikoseeberger.akkahttpcirce.CirceSupport
import io.circe.{Decoder, Encoder}
import io.circe.generic.auto._
import io.circe.syntax._
import smarthouse.restapi.http.SecurityDirectives
import smarthouse.restapi.models.DeviceEntity
import smarthouse.restapi.services.{AuthService, DevicesService}

import scala.concurrent.ExecutionContext

class DevicesServiceRoute(val authService: AuthService,
                          val eventService: DevicesService)
                         (implicit executionContext: ExecutionContext) extends CirceSupport with SecurityDirectives {

  import StatusCodes._
  import eventService._

  implicit val dateTimeEncoder: Encoder[Date] = Encoder.instance(a => a.getTime.asJson)
  implicit val dateTimeDecoder: Decoder[Date] = Decoder.instance(a => a.as[Long].map(new Date(_)))

  val route = pathPrefix("devices") {

    pathEndOrSingleSlash {
      get {
        complete(getDevices().map(_.asJson))
      } ~ post {
        entity(as[DeviceEntity]) { item =>
          complete(Created -> createDevice(item).map(_.asJson))
        }
      }
    }
  }
} 
开发者ID:andrewobukhov,项目名称:smart-house,代码行数:40,代码来源:DevicesServiceRoute.scala

示例10: AuthServiceRoute

//设置package包名称以及导入依赖的类
package smarthouse.restapi.http.routes

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Directives._
import de.heikoseeberger.akkahttpcirce.CirceSupport
import io.circe.generic.auto._
import io.circe.syntax._
import smarthouse.restapi.http.SecurityDirectives
import smarthouse.restapi.models.UserEntity
import smarthouse.restapi.services.AuthService

import scala.concurrent.ExecutionContext

class AuthServiceRoute(val authService: AuthService)(implicit executionContext: ExecutionContext) extends CirceSupport with SecurityDirectives {

  import StatusCodes._
  import authService._

  val route = pathPrefix("auth") {
    path("signIn") {
      pathEndOrSingleSlash {
        post {
          entity(as[LoginPassword]) { loginPassword =>
            complete(signIn(loginPassword.login, loginPassword.password).map(_.asJson))
          }
        }
      }
    } ~
      path("signUp") {
        pathEndOrSingleSlash {
          post {
            entity(as[UserEntity]) { userEntity =>
              complete(Created -> signUp(userEntity).map(_.asJson))
            }
          }
        }
      }
  }

  private case class LoginPassword(login: String, password: String)

} 
开发者ID:andrewobukhov,项目名称:smart-house,代码行数:43,代码来源:AuthServiceRoute.scala

示例11: UsersServiceRoute

//设置package包名称以及导入依赖的类
package smarthouse.restapi.http.routes

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.PathMatchers.IntNumber
import de.heikoseeberger.akkahttpcirce.CirceSupport
import io.circe.generic.auto._
import io.circe.syntax._
import smarthouse.restapi.http.SecurityDirectives
import smarthouse.restapi.models.UserEntityUpdate
import smarthouse.restapi.services.{AuthService, UsersService}

import scala.concurrent.ExecutionContext

class UsersServiceRoute(val authService: AuthService,
                        usersService: UsersService
                       )(implicit executionContext: ExecutionContext) extends CirceSupport with SecurityDirectives {

  import StatusCodes._
  import usersService._

  val route = pathPrefix("users") {
    pathEndOrSingleSlash {
      get {
        complete(getUsers().map(_.asJson))
      }
    } ~
      pathPrefix("me") {
        pathEndOrSingleSlash {
          authenticate { loggedUser =>
            get {
              complete(loggedUser)
            } ~
              post {
                entity(as[UserEntityUpdate]) { userUpdate =>
                  complete(updateUser(loggedUser.id.get, userUpdate).map(_.asJson))
                }
              }
          }
        }
      } ~
      pathPrefix(IntNumber) { id =>
        pathEndOrSingleSlash {
          get {
            complete(getUserById(id).map(_.asJson))
          } ~
            post {
              entity(as[UserEntityUpdate]) { userUpdate =>
                complete(updateUser(id, userUpdate).map(_.asJson))
              }
            } ~
            delete {
              onSuccess(deleteUser(id)) { ignored =>
                complete(NoContent)
              }
            }
        }
      }
  }

} 
开发者ID:andrewobukhov,项目名称:smart-house,代码行数:62,代码来源:UsersServiceRoute.scala

示例12: provisionUsersList

//设置package包名称以及导入依赖的类
package smarthouse

import akka.http.scaladsl.testkit.ScalatestRouteTest
import de.heikoseeberger.akkahttpcirce.CirceSupport
import smarthouse.restapi.http.HttpService
import smarthouse.restapi.models.UserEntity
import smarthouse.restapi.services.{AuthService, DevicesService, EventsService, UsersService}
import smarthouse.restapi.utils.DatabaseService
import smarthouse.utils.InMemoryPostgresStorage._
import org.scalatest._

import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.util.Random

trait BaseServiceTest extends WordSpec with Matchers with ScalatestRouteTest with CirceSupport {

  dbProcess.getProcessId

  private val databaseService = new DatabaseService(jdbcUrl, dbUser, dbPassword)

  val usersService = new UsersService(databaseService)
  val authService = new AuthService(databaseService)(usersService)
  val eventsService = new EventsService(databaseService)
  val devicesService = new DevicesService(databaseService)

  val httpService = new HttpService(usersService, authService, eventsService, devicesService)

  def provisionUsersList(size: Int): Seq[UserEntity] = {
    val savedUsers = (1 to size).map { _ =>
      UserEntity(Some(Random.nextLong()), Random.nextString(10), Random.nextString(10))
    }.map(usersService.createUser)

    Await.result(Future.sequence(savedUsers), 10.seconds)
  }

  def provisionTokensForUsers(usersList: Seq[UserEntity]) = {
    val savedTokens = usersList.map(authService.createToken)
    Await.result(Future.sequence(savedTokens), 10.seconds)
  }

} 
开发者ID:andrewobukhov,项目名称:smart-house,代码行数:43,代码来源:BaseServiceTest.scala

示例13: OwnerShip

//设置package包名称以及导入依赖的类
package io.github.yeghishe

import java.lang.management.ManagementFactory

import akka.http.scaladsl.server.Directives.pathPrefix
import akka.http.scaladsl.server.{ Directives, Route }
import io.circe.Json

import scala.concurrent.duration._
import de.heikoseeberger.akkahttpcirce.CirceSupport

trait MockAuthService extends BaseService {
  import Directives._
  import CirceSupport._
  import io.circe.generic.auto._

  protected case class OwnerShip(owner_type: String)
  private final case class Foo(owner_type: String)

  override protected def routes: Route =
    get {
      complete {
        Foo("admin")
      }
    }
} 
开发者ID:jeado,项目名称:mock-mqtt-auth,代码行数:27,代码来源:MockAuthService.scala

示例14: AuthServiceRoute

//设置package包名称以及导入依赖的类
package app.board.http.routes

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Directives._
import de.heikoseeberger.akkahttpcirce.CirceSupport
import app.board.http.SecurityDirectives
import app.board.models.UserEntity
import app.board.services.AuthService
import io.circe.generic.auto._
import io.circe.syntax._

import scala.concurrent.ExecutionContext

class AuthServiceRoute(val authService: AuthService)
                      (implicit executionContext: ExecutionContext) extends CirceSupport with SecurityDirectives {

  import StatusCodes._
  import authService._

  val route = pathPrefix("auth") {
    path("signIn") {
      pathEndOrSingleSlash {
        post {
          entity(as[LoginPassword]) { loginPassword =>
            complete(signIn(loginPassword.login, loginPassword.password).map(_.asJson))
          }
        }
      }
    } ~
      path("signUp") {
        pathEndOrSingleSlash {
          post {
            entity(as[UserEntity]) { userEntity =>
              complete(Created -> signUp(userEntity).map(_.asJson))
            }
          }
        }
      }
  }

  private case class LoginPassword(login: String, password: String)

} 
开发者ID:hwshim0810,项目名称:scalable-board,代码行数:44,代码来源:AuthServiceRoute.scala

示例15: UsersServiceRoute

//设置package包名称以及导入依赖的类
package app.board.http.routes

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.PathMatchers.IntNumber
import de.heikoseeberger.akkahttpcirce.CirceSupport
import app.board.http.SecurityDirectives
import app.board.models.UserEntityUpdate
import app.board.services.{AuthService, UsersService}
import io.circe.generic.auto._
import io.circe.syntax._

import scala.concurrent.ExecutionContext

class UsersServiceRoute(val authService: AuthService,
                        usersService: UsersService
                       )(implicit executionContext: ExecutionContext) extends CirceSupport with SecurityDirectives {

  import StatusCodes._
  import usersService._

  val route = pathPrefix("users") {
    pathEndOrSingleSlash {
      get {
        complete(getUsers().map(_.asJson))
      }
    } ~
      pathPrefix("me") {
        pathEndOrSingleSlash {
          authenticate { loggedUser =>
            get {
              complete(loggedUser)
            } ~
              post {
                entity(as[UserEntityUpdate]) { userUpdate =>
                  complete(updateUser(loggedUser.id.get, userUpdate).map(_.asJson))
                }
              }
          }
        }
      } ~
      pathPrefix(IntNumber) { id =>
        pathEndOrSingleSlash {
          get {
            complete(getUserById(id).map(_.asJson))
          } ~
            post {
              entity(as[UserEntityUpdate]) { userUpdate =>
                complete(updateUser(id, userUpdate).map(_.asJson))
              }
            } ~
            delete {
              onSuccess(deleteUser(id)) { ignored =>
                complete(NoContent)
              }
            }
        }
      }
  }

} 
开发者ID:hwshim0810,项目名称:scalable-board,代码行数:62,代码来源:UsersServiceRoute.scala


注:本文中的de.heikoseeberger.akkahttpcirce.CirceSupport类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。