Skip to content

Commit

Permalink
RTB House: Resolve AUCTION_PRICE macro (prebid#3901)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrj-rtbh authored Oct 15, 2024
1 parent cbe9876 commit b56923c
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
12 changes: 11 additions & 1 deletion adapters/rtbhouse/rtbhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/buger/jsonparser"
Expand Down Expand Up @@ -161,8 +162,9 @@ func (adapter *RTBHouseAdapter) MakeBids(
var typedBid *adapters.TypedBid
for _, seatBid := range openRTBBidderResponse.SeatBid {
for _, bid := range seatBid.Bid {
bid := bid // pin! -> https://github.com/kyoh86/scopelint#whats-this
bid := bid
bidType, err := getMediaTypeForBid(bid)
resolveMacros(&bid)
if err != nil {
errs = append(errs, err)
continue
Expand Down Expand Up @@ -222,3 +224,11 @@ func getNativeAdm(adm string) (string, error) {

return adm, nil
}

func resolveMacros(bid *openrtb2.Bid) {
if bid != nil {
price := strconv.FormatFloat(bid.Price, 'f', -1, 64)
bid.NURL = strings.Replace(bid.NURL, "${AUCTION_PRICE}", price, -1)
bid.AdM = strings.Replace(bid.AdM, "${AUCTION_PRICE}", price, -1)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"mockBidRequest": {
"id": "test-request-id",
"site": {
"page": "https://good.site/url"
},
"imp": [{
"id": "test-imp-id",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {}
}
}]
},

"httpCalls": [{
"expectedRequest": {
"uri": "http://localhost/prebid_server",
"body": {
"id": "test-request-id",
"cur": ["USD"],
"site": {
"page": "https://good.site/url"
},
"imp": [{
"id": "test-imp-id",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {}
}
}]
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"seat": "rtbhouse",
"bid": [{
"id": "randomid",
"impid": "test-imp-id",
"price": 0.500000,
"adid": "12345678",
"adm": "<iframe src=\"https://endpoint.url/banner1234567890.html\"></iframe><img src=\"https://endpoint.url/win-notify?a=xyz&price=${AUCTION_PRICE}\">",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 1
}]
}],
"cur": "USD"
}
}
}],

"expectedBidResponses": [{
"currency": "USD",
"bids": [{
"bid": {
"id": "randomid",
"impid": "test-imp-id",
"price": 0.5,
"adm": "<iframe src=\"https://endpoint.url/banner1234567890.html\"></iframe><img src=\"https://endpoint.url/win-notify?a=xyz&price=0.5\">",
"adid": "12345678",
"cid": "987",
"crid": "12345678",
"w": 300,
"h": 250,
"mtype": 1
},
"type": "banner"
}]
}]
}

0 comments on commit b56923c

Please sign in to comment.