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

Force usage of native specs when required #46

Open
valdo404 opened this issue Oct 6, 2020 · 0 comments
Open

Force usage of native specs when required #46

valdo404 opened this issue Oct 6, 2020 · 0 comments

Comments

@valdo404
Copy link
Contributor

valdo404 commented Oct 6, 2020

Dsps should forcibly reply native responses when requests contains native request.

hence the following code should be using the bid request to determine if impression is native based.

implicit val admOneOfDecoder: Decoder[SeatBid.Bid.AdmOneof] = { cursor =>
    cursor.focus.map {
      case json if json.isString =>
        json.asString
          .map(s => {
            decode[NativeResponse](s)
              .map(AdmOneof.AdmNative) // the string can be decoded as native
              .getOrElse(AdmOneof.Adm(s)) // the string cannot be decoded
          })
          .getOrElse(AdmOneof.Empty) // there's no string or it's impossible to decode it
      case json if json.isObject =>
        json.as[NativeResponse].map(AdmOneof.AdmNative).getOrElse(AdmOneof.Empty)
    }.orElse(Some(AdmOneof.Empty)).map(Right(_)).get
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant