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

RTBHouse: native support #3212

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 60 additions & 5 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/v2/adapters"
"github.com/prebid/prebid-server/v2/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 @@ -156,13 +161,63 @@ func (adapter *RTBHouseAdapter) MakeBids(
for _, seatBid := range openRTBBidderResponse.SeatBid {
for _, bid := range seatBid.Bid {
bid := bid // pin! -> https://github.com/kyoh86/scopelint#whats-this
typedBid = &adapters.TypedBid{Bid: &bid, BidType: "banner"}
bidderResponse.Bids = append(bidderResponse.Bids, typedBid)
bidType, err := getMediaTypeForBid(bid)
if err != nil {
errs = append(errs, err)
continue
} else {
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)
continue
}
}

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

bidderResponse.Currency = BidderCurrency

return bidderResponse, nil
return bidderResponse, errs

}

func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
switch bid.MType {
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner, nil
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative, nil
default:
return "", fmt.Errorf("unrecognized bid type in response from rtbhouse for bid %s", bid.ImpID)
}
}

func getNativeAdm(adm string) (string, 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