powerspace / scala-openrtb

Scala OpenRTB tools used at @Powerspace

Website GitHub

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 Powerspace and 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_2.12" % "version" to your build.sbt

We also provide json encoders through libraryDependencies += "com.powerspace.openrtb" % "openrtb-json_2.12" % "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

  • Macro replacement will be included into ScalaOpenRTB

Links

Contributions

Feel free to:

  • add support for other DSPs
  • raise an issue
  • submit your pull request