Skip to content

Commit

Permalink
RTBHouse: native support
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrj-rtbh committed Oct 13, 2023
1 parent 81c78ff commit 18c794b
Show file tree
Hide file tree
Showing 16 changed files with 1,227 additions and 129 deletions.
63 changes: 59 additions & 4 deletions adapters/rtbhouse/rtbhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package rtbhouse

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"

"github.com/buger/jsonparser"
"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
Expand Down Expand Up @@ -49,9 +51,12 @@ func (adapter *RTBHouseAdapter) MakeRequests(
if err != nil {
return nil, []error{err}
}
if rtbhouseExt.BidFloor > 0 && len(reqCopy.Cur) > 0 {
bidFloorCur = reqCopy.Cur[0]
if rtbhouseExt.BidFloor > 0 {
bidFloor = rtbhouseExt.BidFloor
bidFloorCur = BidderCurrency
if len(reqCopy.Cur) > 0 {
bidFloorCur = reqCopy.Cur[0]
}
}
}

Expand Down Expand Up @@ -155,9 +160,27 @@ func (adapter *RTBHouseAdapter) MakeBids(
var typedBid *adapters.TypedBid
for _, seatBid := range openRTBBidderResponse.SeatBid {
for _, bid := range seatBid.Bid {
var err error
bid := bid // pin! -> https:/kyoh86/scopelint#whats-this
typedBid = &adapters.TypedBid{Bid: &bid, BidType: "banner"}
bidderResponse.Bids = append(bidderResponse.Bids, typedBid)
bidType := getMediaTypeForBid(bid)

if bidType != "" {
typedBid = &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
}

// for native bid responses fix Adm field
if typedBid.BidType == openrtb_ext.BidTypeNative {
bid.AdM, err = getNativeAdm(bid.AdM)
if err != nil {
errs = append(errs, err)
return nil, errs
}
}

bidderResponse.Bids = append(bidderResponse.Bids, typedBid)
}
}
}

Expand All @@ -166,3 +189,35 @@ func (adapter *RTBHouseAdapter) MakeBids(
return bidderResponse, nil

}

func getMediaTypeForBid(bid openrtb2.Bid) openrtb_ext.BidType {
switch bid.MType {
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative
default:
return ""
}
}

func getNativeAdm(adm string) (string, error) {
var err error
nativeAdm := make(map[string]interface{})
err = json.Unmarshal([]byte(adm), &nativeAdm)
if err != nil {
return adm, errors.New("unable to unmarshal native adm")
}

// move bid.adm.native to bid.adm
if _, ok := nativeAdm["native"]; ok {
//using jsonparser to avoid marshaling, encode escape, etc.
value, dataType, _, err := jsonparser.Get([]byte(adm), string(openrtb_ext.BidTypeNative))
if err != nil || dataType != jsonparser.Object {
return adm, errors.New("unable to get native adm")
}
adm = string(value)
}

return adm, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"publisherId": "12345",
"bidfloor": 3.00
}
}
}
],
"ext": {
"prebid": {
"currency": {
"rates": {
"EUR": {
"USD": 0.05
}
},
"usepbsrates": false
}
}
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://localhost/prebid_server",
"body": {
"id": "test-request-id",
"cur": [
"USD"
],
"imp": [
{
"banner": {
"format": [
{
"h": 250,
"w": 300
}
]
},
"bidfloor": 3.00,
"bidfloorcur": "USD",
"ext": {
"bidder": {
"publisherId": "12345",
"bidfloor": 3.00
}
},
"id": "test-imp-id"
}
],
"ext": {
"prebid": {
"currency": {
"rates": {
"EUR": {
"USD": 0.05
}
},
"usepbsrates": false
}
}
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-response-id",
"cur": "USD",
"seatbid": [
{
"seat": "rtbhouse",
"bid": [
{
"id": "randomid",
"impid": "test-imp-id",
"price": 300,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 1
}
]
}
]
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "randomid",
"impid": "test-imp-id",
"price": 300,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 1
},
"type": "banner"
}
]
}
]
}
133 changes: 133 additions & 0 deletions adapters/rtbhouse/rtbhousetest/exemplary/bidfloor-as-bidder-param.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"mockBidRequest": {
"id": "test-request-id",
"cur": [
"EUR"
],
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"publisherId": "12345",
"bidfloor": 2
}
}
}
],
"ext": {
"prebid": {
"currency": {
"rates": {
"EUR": {
"USD": 0.05
}
},
"usepbsrates": false
}
}
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://localhost/prebid_server",
"body": {
"id": "test-request-id",
"cur": [
"USD"
],
"imp": [
{
"banner": {
"format": [
{
"h": 250,
"w": 300
}
]
},
"bidfloor": 0.1,
"bidfloorcur": "USD",
"ext": {
"bidder": {
"publisherId": "12345",
"bidfloor": 2
}
},
"id": "test-imp-id"
}
],
"ext": {
"prebid": {
"currency": {
"rates": {
"EUR": {
"USD": 0.05
}
},
"usepbsrates": false
}
}
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-response-id",
"cur": "USD",
"seatbid": [
{
"seat": "rtbhouse",
"bid": [
{
"id": "randomid",
"impid": "test-imp-id",
"price": 300,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 1
}
]
}
]
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "randomid",
"impid": "test-imp-id",
"price": 300,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 1
},
"type": "banner"
}
]
}
]
}
Loading

0 comments on commit 18c794b

Please sign in to comment.