Powerspace / scala-openrtb

Scala OpenRTB tools used at @Powerspace
https://powerspace.com
Apache License 2.0
23 stars 8 forks source link

Scala OpenRTB is a full Scala library that provides protobuf bindings as well as JSON serialization for OpenRTB-based entities in a functional fashion. This library also provides SerDes for BidSwitch bidding models, and aims to support other DSPs in the near future.

Artifacts

Scala openrtb artifacts are available on Sonatype.

Building

Build it like any other SBT project. Go to the root folder and run:

sbt compile

Usage

If you want to use the core of ScalaOpenRTB, you only need to add libraryDependencies += "com.powerspace.openrtb" %% "openrtb-model" % "version" to your build.sbt

We also provide json encoders through libraryDependencies += "com.powerspace.openrtb" %% "openrtb-json" % "version"

To leverage ScalaOpenRTB we have to define our bid request/response extensions and their decoders:

object CustomSerdeModule extends SerdeModule {

  // Define encoder for custom extension
  implicit val directEncoder: Encoder[CustomExtension] = openRtbEncoder[CustomExtension]

  // Register extension for specific proto-kind object
  override def extensionRegistry: ExtensionRegistry = ExtensionRegistry()
    .registerExtension(CustomProto.bidRequest)

  override def nativeRegistry: ExtensionRegistry = ExtensionRegistry()

Then in the bidder client we import defined module and use it for bid requests/response encoding/decoding:

import CustomSerdeModule._
import io.circe.syntax._
import io.circe.parser.decode

implicit val bidRequestEncoder: Encoder[BidRequest] = PowerspaceSerdeModule.bidRequestEncoder
implicit val bidResponseDecoder: Decoder[BidRequest] = PowerspaceSerdeModule.bidResponseDecoder

val bidRequest = BidRequest(...).asJson
val bidRequest = decode[BidResponse](bidRequest)

Work in Progress

Links

Contributions

Feel free to: