Skip to content

Commit

Permalink
Adf adapter: banner and video mediatype support (#1841)
Browse files Browse the repository at this point in the history
  • Loading branch information
braizhas authored May 11, 2021
1 parent 125e07b commit c2f91c3
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 4 deletions.
31 changes: 27 additions & 4 deletions adapters/adf/adf.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,38 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp))
bidResponse.Currency = response.Cur

var errors []error
for _, seatBid := range response.SeatBid {
for i := range seatBid.Bid {
for i, bid := range seatBid.Bid {
bidType, err := getMediaTypeForImp(bid.ImpID, request.Imp)
if err != nil {
errors = append(errors, err)
continue
}
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &seatBid.Bid[i],
BidType: openrtb_ext.BidTypeNative,
BidType: bidType,
})
}
}

return bidResponse, nil
return bidResponse, errors
}

func getMediaTypeForImp(impID string, imps []openrtb2.Imp) (openrtb_ext.BidType, error) {
for _, imp := range imps {
if imp.ID == impID {
if imp.Banner != nil {
return openrtb_ext.BidTypeBanner, nil
} else if imp.Video != nil {
return openrtb_ext.BidTypeVideo, nil
} else if imp.Native != nil {
return openrtb_ext.BidTypeNative, nil
}
}
}

return "", &errortypes.BadInput{
Message: fmt.Sprintf("Failed to find supported impression \"%s\" mediatype", impID),
}
}
118 changes: 118 additions & 0 deletions adapters/adf/adftest/exemplary/multi-format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [{
"id": "test-imp-id-1",
"ext": {
"bidder": {
"mid": "828782"
}
},
"video": {
"mimes": [
"video/mp4"
],
"placement": 1
}
}, {
"id": "test-imp-id-2",
"ext": {
"bidder": {
"mid": "828783"
}
},
"banner": {
"format": [{
"w": 300,
"h": 250
}]
}
}]
},
"httpCalls": [{
"expectedRequest": {
"uri": "https://adx.adform.net/adx/openrtb",
"body": {
"id": "test-request-id",
"imp": [{
"id": "test-imp-id-1",
"ext": {
"bidder": {
"mid": "828782"
}
},
"video": {
"mimes": [
"video/mp4"
],
"placement": 1
},
"tagid": "828782"
}, {
"id": "test-imp-id-2",
"ext": {
"bidder": {
"mid": "828783"
}
},
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"tagid": "828783"
}]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"bid": [{
"id": "test-bid-id-1",
"impid": "test-imp-id-1",
"price": 10,
"adm": "{video xml}",
"adomain": [],
"crid": "test-creative-id-1"
}]
}, {
"bid": [{
"id": "test-bid-id-2",
"impid": "test-imp-id-2",
"price": 2,
"adm": "{banner html}",
"adomain": [ "ad-domain" ],
"crid": "test-creative-id-2"
}]
}],
"cur": "EUR"
}
}
}],
"expectedBidResponses": [{
"currency": "EUR",
"bids": [{
"bid": {
"id": "test-bid-id-1",
"impid": "test-imp-id-1",
"price": 10,
"adm": "{video xml}",
"crid": "test-creative-id-1"
},
"type": "video"
}, {
"bid": {
"id": "test-bid-id-2",
"impid": "test-imp-id-2",
"price": 2,
"adm": "{banner html}",
"adomain": [ "ad-domain" ],
"crid": "test-creative-id-2"
},
"type": "banner"
}]
}]
}
95 changes: 95 additions & 0 deletions adapters/adf/adftest/exemplary/single-banner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [{
"id": "test-imp-id",
"ext": {
"bidder": {
"mid": "828782"
}
},
"banner": {
"format": [{
"w": 300,
"h": 250
}]
}
}],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
},
"httpCalls": [{
"expectedRequest": {
"uri": "https://adx.adform.net/adx/openrtb",
"body": {
"id": "test-request-id",
"imp": [{
"id": "test-imp-id",
"ext": {
"bidder": {
"mid": "828782"
}
},
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"tagid": "828782"
}],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"bid": [{
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{banner html}",
"adomain": [ "test.com" ],
"crid": "test-creative-id"
}]
}],
"cur": "USD"
}
}
}],
"expectedBidResponses": [{
"currency": "USD",
"bids": [
{
"bid": {
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{banner html}",
"crid": "test-creative-id",
"adomain": [ "test.com" ]
},
"type": "banner"
}
]
}]
}
93 changes: 93 additions & 0 deletions adapters/adf/adftest/exemplary/single-video.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [{
"id": "test-imp-id",
"ext": {
"bidder": {
"mid": "828782"
}
},
"video": {
"mimes": [
"video/mp4"
],
"placement": 1
}
}],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
},
"httpCalls": [{
"expectedRequest": {
"uri": "https://adx.adform.net/adx/openrtb",
"body": {
"id": "test-request-id",
"imp": [{
"id": "test-imp-id",
"ext": {
"bidder": {
"mid": "828782"
}
},
"video": {
"mimes": [
"video/mp4"
],
"placement": 1
},
"tagid": "828782"
}],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"bid": [{
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{vast xml}",
"crid": "test-creative-id"
}]
}],
"cur": "USD"
}
}
}],
"expectedBidResponses": [{
"currency": "USD",
"bids": [
{
"bid": {
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{vast xml}",
"crid": "test-creative-id"
},
"type": "video"
}
]
}]
}
Loading

0 comments on commit c2f91c3

Please sign in to comment.