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

Adot: add new bid param publisherPath #2164

Merged
merged 1 commit into from
Feb 28, 2022
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
26 changes: 25 additions & 1 deletion adapters/adot/adot.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters
// MakeRequests makes the HTTP requests which should be made to fetch bids.
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var reqJSON []byte
var publisherPath string
var err error

if reqJSON, err = json.Marshal(request); err != nil {
Expand All @@ -46,9 +47,17 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")

if adotExt := getImpAdotExt(&request.Imp[0]); adotExt != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my understanding, could there be a situation where request.Imp has multiple entries, and you'd want the publisher path from an entry other than request.Imp[0]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The publisher path will be used with some of our partners for custom integrations, so the value should be the same across all request.Imp entries

publisherPath = adotExt.PublisherPath
} else {
publisherPath = ""
}

endpoint := strings.Replace(a.endpoint, "{PUBLISHER_PATH}", publisherPath, -1)

return []*adapters.RequestData{{
Method: "POST",
Uri: a.endpoint,
Uri: endpoint,
Body: reqJSON,
Headers: headers,
}}, nil
Expand Down Expand Up @@ -129,3 +138,18 @@ func resolveMacros(bid *openrtb2.Bid) {
bid.NURL = strings.Replace(bid.NURL, "${AUCTION_PRICE}", price, -1)
bid.AdM = strings.Replace(bid.AdM, "${AUCTION_PRICE}", price, -1)
}

// getImpAdotExt parses and return first imp ext or nil
func getImpAdotExt(imp *openrtb2.Imp) *openrtb_ext.ExtImpAdot {
var extImpAdot openrtb_ext.ExtImpAdot
var extBidder adapters.ExtImpBidder
err := json.Unmarshal(imp.Ext, &extBidder)
if err != nil {
return nil
}
err = json.Unmarshal(extBidder.Bidder, &extImpAdot)
if err != nil {
return nil
}
return &extImpAdot
}
19 changes: 17 additions & 2 deletions adapters/adot/adot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/assert"
)

const testsBidderEndpoint = "https://dsp.adotmob.com/headerbidding/bidrequest"
const testsBidderEndpoint = "https://dsp.adotmob.com/headerbidding{PUBLISHER_PATH}/bidrequest"

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderAdot, config.Adapter{
Expand All @@ -38,7 +38,7 @@ func TestMediaTypeError(t *testing.T) {

func TestBidResponseNoContent(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderAdot, config.Adapter{
Endpoint: "https://dsp.adotmob.com/headerbidding/bidrequest"})
Endpoint: "https://dsp.adotmob.com/headerbidding{PUBLISHER_PATH}/bidrequest"})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
Expand Down Expand Up @@ -79,3 +79,18 @@ func TestResolveMacros(t *testing.T) {
assert.Equal(t, "adm:imp_123.45 amd:creativeview_123.45", bid.AdM)
assert.Equal(t, "nurl_123.45", bid.NURL)
}

func TestGetImpAdotExt(t *testing.T) {
ext := &openrtb2.Imp{Ext: json.RawMessage(`{"bidder":{"publisherPath": "/hubvisor"}}`)}
adotExt := getImpAdotExt(ext)
assert.Equal(t, adotExt.PublisherPath, "/hubvisor")

emptyBidderExt := &openrtb2.Imp{Ext: json.RawMessage(`{"bidder":{}}`)}
emptyAdotBidderExt := getImpAdotExt(emptyBidderExt)
assert.NotNil(t, emptyAdotBidderExt)
assert.Equal(t, emptyAdotBidderExt.PublisherPath, "")

emptyExt := &openrtb2.Imp{Ext: json.RawMessage(`{}`)}
emptyAdotExt := getImpAdotExt(emptyExt)
assert.Nil(t, emptyAdotExt)
}
27 changes: 14 additions & 13 deletions adapters/adot/adottest/exemplary/simple-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,22 @@
"seatbid": [
{
"seat": "adot",
"bid": [{
"id": "test-request-native-id",
"impid": "test-imp-native-id",
"price": 1.16346,
"adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}",
"nurl": "nurl.link/win?p=${AUCTION_PRICE}",
"w": 300,
"h": 250,
"ext": {
"adot": {
"media_type": "native"
"bid": [
{
"id": "test-request-native-id",
"impid": "test-imp-native-id",
"price": 1.16346,
"adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}",
"nurl": "nurl.link/win?p=${AUCTION_PRICE}",
"w": 300,
"h": 250,
"ext": {
"adot": {
"media_type": "native"
}
}
}
}]
]
}
],
"cur": "USD"
Expand Down Expand Up @@ -87,4 +89,3 @@
}
]
}

59 changes: 20 additions & 39 deletions adapters/adot/adottest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@
"h": 250,
"maxduration": 60,
"minduration": 1,
"api": [
1,
2,
5,
6,
7
],
"mimes": [
"video\/mp4"
],
"api": [1, 2, 5, 6, 7],
"mimes": ["video/mp4"],
"placement": 4,
"protocols": [
2
]
"protocols": [2]
},
"ext": {
"adot": {}
Expand All @@ -44,20 +34,10 @@
"h": 250,
"maxduration": 60,
"minduration": 1,
"api": [
1,
2,
5,
6,
7
],
"mimes": [
"video\/mp4"
],
"api": [1, 2, 5, 6, 7],
"mimes": ["video/mp4"],
"placement": 4,
"protocols": [
2
]
"protocols": [2]
},
"ext": {
"adot": {}
Expand All @@ -73,20 +53,22 @@
"seatbid": [
{
"seat": "adot",
"bid": [{
"id": "test-request-video-id",
"impid": "test-imp-video-id",
"price": 1.16346,
"adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}",
"nurl": "nurl.link/win?p=${AUCTION_PRICE}",
"w": 300,
"h": 250,
"ext": {
"adot": {
"media_type": "video"
"bid": [
{
"id": "test-request-video-id",
"impid": "test-imp-video-id",
"price": 1.16346,
"adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}",
"nurl": "nurl.link/win?p=${AUCTION_PRICE}",
"w": 300,
"h": 250,
"ext": {
"adot": {
"media_type": "video"
}
}
}
}]
]
}
],
"cur": "USD"
Expand Down Expand Up @@ -119,4 +101,3 @@
}
]
}

107 changes: 107 additions & 0 deletions adapters/adot/adottest/supplemental/ext-bidder-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"mockBidRequest": {
"id": "test-request-publishPath-id",
"imp": [
{
"id": "test-imp-publishPath-id",
"banner": {
"format": [
{
"w": 320,
"h": 250
}
],
"w": 320,
"h": 250
},
"ext": {
"bidder": {},
"adot": {}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://dsp.adotmob.com/headerbidding/bidrequest",
"body": {
"id": "test-request-publishPath-id",
"imp": [
{
"id": "test-imp-publishPath-id",
"banner": {
"format": [
{
"w": 320,
"h": 250
}
],
"w": 320,
"h": 250
},
"ext": {
"bidder": {
},
"adot": {}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-publishPath-id",
"seatbid": [
{
"seat": "adot",
"bid": [
{
"id": "test-request-publishPath-id",
"impid": "test-imp-publishPath-id",
"price": 1.16346,
"adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}",
"nurl": "nurl.link/win?p=${AUCTION_PRICE}",
"w": 320,
"h": 50,
"ext": {
"adot": {
"media_type": "banner"
}
}
}
]
}
],
"cur": "USD"
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "test-request-publishPath-id",
"impid": "test-imp-publishPath-id",
"price": 1.16346,
"adm": "some-test-ad imp_1.16346 creativeview_1.16346",
"nurl": "nurl.link/win?p=1.16346",
"w": 320,
"h": 50,
"ext": {
"adot": {
"media_type": "banner"
}
}
},
"type": "banner"
}
]
}
]
}
Loading