Skip to content

Commit b56923c

Browse files
authored
RTB House: Resolve AUCTION_PRICE macro (#3901)
1 parent cbe9876 commit b56923c

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

adapters/rtbhouse/rtbhouse.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"net/http"
8+
"strconv"
89
"strings"
910

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

223225
return adm, nil
224226
}
227+
228+
func resolveMacros(bid *openrtb2.Bid) {
229+
if bid != nil {
230+
price := strconv.FormatFloat(bid.Price, 'f', -1, 64)
231+
bid.NURL = strings.Replace(bid.NURL, "${AUCTION_PRICE}", price, -1)
232+
bid.AdM = strings.Replace(bid.AdM, "${AUCTION_PRICE}", price, -1)
233+
}
234+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"mockBidRequest": {
3+
"id": "test-request-id",
4+
"site": {
5+
"page": "https://good.site/url"
6+
},
7+
"imp": [{
8+
"id": "test-imp-id",
9+
"banner": {
10+
"format": [{
11+
"w": 300,
12+
"h": 250
13+
}]
14+
},
15+
"ext": {
16+
"bidder": {}
17+
}
18+
}]
19+
},
20+
21+
"httpCalls": [{
22+
"expectedRequest": {
23+
"uri": "http://localhost/prebid_server",
24+
"body": {
25+
"id": "test-request-id",
26+
"cur": ["USD"],
27+
"site": {
28+
"page": "https://good.site/url"
29+
},
30+
"imp": [{
31+
"id": "test-imp-id",
32+
"banner": {
33+
"format": [{
34+
"w": 300,
35+
"h": 250
36+
}]
37+
},
38+
"ext": {
39+
"bidder": {}
40+
}
41+
}]
42+
},
43+
"impIDs":["test-imp-id"]
44+
},
45+
"mockResponse": {
46+
"status": 200,
47+
"body": {
48+
"id": "test-request-id",
49+
"seatbid": [{
50+
"seat": "rtbhouse",
51+
"bid": [{
52+
"id": "randomid",
53+
"impid": "test-imp-id",
54+
"price": 0.500000,
55+
"adid": "12345678",
56+
"adm": "<iframe src=\"https://endpoint.url/banner1234567890.html\"></iframe><img src=\"https://endpoint.url/win-notify?a=xyz&price=${AUCTION_PRICE}\">",
57+
"cid": "987",
58+
"crid": "12345678",
59+
"h": 250,
60+
"w": 300,
61+
"mtype": 1
62+
}]
63+
}],
64+
"cur": "USD"
65+
}
66+
}
67+
}],
68+
69+
"expectedBidResponses": [{
70+
"currency": "USD",
71+
"bids": [{
72+
"bid": {
73+
"id": "randomid",
74+
"impid": "test-imp-id",
75+
"price": 0.5,
76+
"adm": "<iframe src=\"https://endpoint.url/banner1234567890.html\"></iframe><img src=\"https://endpoint.url/win-notify?a=xyz&price=0.5\">",
77+
"adid": "12345678",
78+
"cid": "987",
79+
"crid": "12345678",
80+
"w": 300,
81+
"h": 250,
82+
"mtype": 1
83+
},
84+
"type": "banner"
85+
}]
86+
}]
87+
}

0 commit comments

Comments
 (0)