Skip to content

Commit

Permalink
Adot: Add OpenRTB macros resolution (prebid#2118)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramyferjaniadot authored and shunj-nb committed Nov 8, 2022
1 parent 55b3724 commit db2c63c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
13 changes: 13 additions & 0 deletions adapters/adot/adot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/mxmCherry/openrtb/v15/openrtb2"
"github.com/prebid/prebid-server/adapters"
Expand Down Expand Up @@ -85,6 +87,7 @@ func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest
for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
if bidType, err := getMediaTypeForBid(&sb.Bid[i]); err == nil {
resolveMacros(&sb.Bid[i])
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
BidType: bidType,
Expand Down Expand Up @@ -116,3 +119,13 @@ func getMediaTypeForBid(bid *openrtb2.Bid) (openrtb_ext.BidType, error) {

return "", fmt.Errorf("unrecognized bid type in response from adot")
}

// resolveMacros resolves OpenRTB macros in nurl and adm
func resolveMacros(bid *openrtb2.Bid) {
if bid == nil {
return
}
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)
}
10 changes: 7 additions & 3 deletions adapters/adot/adot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "adottest", bidder)
}

//Test the media type error
func TestMediaTypeError(t *testing.T) {
_, err := getMediaTypeForBid(nil)

Expand All @@ -37,7 +36,6 @@ func TestMediaTypeError(t *testing.T) {
assert.Error(t, err)
}

//Test the bid response when the bidder return a status code 204
func TestBidResponseNoContent(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderAdot, config.Adapter{
Endpoint: "https://dsp.adotmob.com/headerbidding/bidrequest"})
Expand All @@ -54,7 +52,6 @@ func TestBidResponseNoContent(t *testing.T) {
}
}

//Test the media type for a bid response
func TestMediaTypeForBid(t *testing.T) {
byteBanner, _ := json.Marshal(&adotBidExt{Adot: bidExt{"banner"}})
byteVideo, _ := json.Marshal(&adotBidExt{Adot: bidExt{"video"}})
Expand All @@ -75,3 +72,10 @@ func TestMediaTypeForBid(t *testing.T) {
t.Errorf("the type is not the valid one. actual: %v, expected: %v", bidTypeNative, openrtb_ext.BidTypeVideo)
}
}

func TestResolveMacros(t *testing.T) {
bid := &openrtb2.Bid{AdM: "adm:imp_${AUCTION_PRICE} amd:creativeview_${AUCTION_PRICE}", NURL: "nurl_${AUCTION_PRICE}", Price: 123.45}
resolveMacros(bid)
assert.Equal(t, "adm:imp_123.45 amd:creativeview_123.45", bid.AdM)
assert.Equal(t, "nurl_123.45", bid.NURL)
}
6 changes: 4 additions & 2 deletions adapters/adot/adottest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"id": "test-request-banner-id",
"impid": "test-imp-banner-id",
"price": 1.16346,
"adm": "some-test-ad",
"adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}",
"nurl": "nurl.link/win?p=${AUCTION_PRICE}",
"w": 320,
"h": 50,
"ext": {
Expand All @@ -78,7 +79,8 @@
"id": "test-request-banner-id",
"impid": "test-imp-banner-id",
"price": 1.16346,
"adm": "some-test-ad",
"adm": "some-test-ad imp_1.16346 creativeview_1.16346",
"nurl": "nurl.link/win?p=1.16346",
"w": 320,
"h": 50,
"ext": {
Expand Down
8 changes: 5 additions & 3 deletions adapters/adot/adottest/exemplary/simple-interstitial.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
"bid": [{
"id": "test-request-inter-id",
"impid": "test-imp-inter-id",
"adm": "some-test-ad",
"price": 1.16346,
"adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}",
"nurl": "nurl.link/win?p=${AUCTION_PRICE}",
"w": 320,
"h": 480,
"ext": {
Expand All @@ -82,8 +83,9 @@
"bid": {
"id": "test-request-inter-id",
"impid": "test-imp-inter-id",
"price": 1.16346,
"adm": "some-test-ad",
"price": 1.16346,
"adm": "some-test-ad imp_1.16346 creativeview_1.16346",
"nurl": "nurl.link/win?p=1.16346",
"w": 320,
"h": 480,
"ext": {
Expand Down
6 changes: 4 additions & 2 deletions adapters/adot/adottest/exemplary/simple-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"id": "test-request-native-id",
"impid": "test-imp-native-id",
"price": 1.16346,
"adm" : "native-ad",
"adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}",
"nurl": "nurl.link/win?p=${AUCTION_PRICE}",
"w": 300,
"h": 250,
"ext": {
Expand All @@ -70,7 +71,8 @@
"id": "test-request-native-id",
"impid": "test-imp-native-id",
"price": 1.16346,
"adm" : "native-ad",
"adm": "some-test-ad imp_1.16346 creativeview_1.16346",
"nurl": "nurl.link/win?p=1.16346",
"w": 300,
"h": 250,
"ext": {
Expand Down
6 changes: 4 additions & 2 deletions adapters/adot/adottest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
"id": "test-request-video-id",
"impid": "test-imp-video-id",
"price": 1.16346,
"adm": "some-test-ad",
"adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}",
"nurl": "nurl.link/win?p=${AUCTION_PRICE}",
"w": 300,
"h": 250,
"ext": {
Expand All @@ -102,7 +103,8 @@
"id": "test-request-video-id",
"impid": "test-imp-video-id",
"price": 1.16346,
"adm": "some-test-ad",
"adm": "some-test-ad imp_1.16346 creativeview_1.16346",
"nurl": "nurl.link/win?p=1.16346",
"w": 300,
"h": 250,
"ext": {
Expand Down

0 comments on commit db2c63c

Please sign in to comment.