From fb67c3384abb8e0a922eab1c9524e7594289b097 Mon Sep 17 00:00:00 2001 From: Jurij Sinickij Date: Wed, 12 May 2021 00:11:27 +0300 Subject: [PATCH] Adf adapter: banner and video mediatype support (#1841) --- adapters/adf/adf.go | 31 ++++- .../adf/adftest/exemplary/multi-format.json | 118 ++++++++++++++++++ .../adf/adftest/exemplary/single-banner.json | 95 ++++++++++++++ .../adf/adftest/exemplary/single-video.json | 93 ++++++++++++++ .../supplemental/invalid-imp-mediatype.json | 59 +++++++++ static/bidder-info/adf.yaml | 4 + 6 files changed, 396 insertions(+), 4 deletions(-) create mode 100644 adapters/adf/adftest/exemplary/multi-format.json create mode 100644 adapters/adf/adftest/exemplary/single-banner.json create mode 100644 adapters/adf/adftest/exemplary/single-video.json create mode 100644 adapters/adf/adftest/supplemental/invalid-imp-mediatype.json diff --git a/adapters/adf/adf.go b/adapters/adf/adf.go index 4ed0dc077dc..f73e23aa07d 100644 --- a/adapters/adf/adf.go +++ b/adapters/adf/adf.go @@ -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), + } } diff --git a/adapters/adf/adftest/exemplary/multi-format.json b/adapters/adf/adftest/exemplary/multi-format.json new file mode 100644 index 00000000000..6b917658cdc --- /dev/null +++ b/adapters/adf/adftest/exemplary/multi-format.json @@ -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" + }] + }] +} diff --git a/adapters/adf/adftest/exemplary/single-banner.json b/adapters/adf/adftest/exemplary/single-banner.json new file mode 100644 index 00000000000..5fdfe8af7c8 --- /dev/null +++ b/adapters/adf/adftest/exemplary/single-banner.json @@ -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" + } + ] + }] +} diff --git a/adapters/adf/adftest/exemplary/single-video.json b/adapters/adf/adftest/exemplary/single-video.json new file mode 100644 index 00000000000..ebe4c6f1b38 --- /dev/null +++ b/adapters/adf/adftest/exemplary/single-video.json @@ -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" + } + ] + }] +} diff --git a/adapters/adf/adftest/supplemental/invalid-imp-mediatype.json b/adapters/adf/adftest/supplemental/invalid-imp-mediatype.json new file mode 100644 index 00000000000..2f01e7eaae9 --- /dev/null +++ b/adapters/adf/adftest/supplemental/invalid-imp-mediatype.json @@ -0,0 +1,59 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [{ + "id": "test-imp-id", + "audio": {}, + "ext": { + "bidder": { + "mid": 12345 + } + } + }] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://adx.adform.net/adx/openrtb", + "body": { + "id": "test-request-id", + "imp": [{ + "ext": { + "bidder": { + "mid": 12345 + } + }, + "id": "test-imp-id", + "audio": { + "mimes": null + }, + "tagid": "12345" + }] + } + }, + "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": [], + "expectedMakeBidsErrors": [ + { + "value": "Failed to find supported impression \"test-imp-id\" mediatype", + "comparison": "literal" + } + ] +} diff --git a/static/bidder-info/adf.yaml b/static/bidder-info/adf.yaml index 8cc96350703..776e208f562 100644 --- a/static/bidder-info/adf.yaml +++ b/static/bidder-info/adf.yaml @@ -4,7 +4,11 @@ gvlVendorID: 50 capabilities: app: mediaTypes: + - banner - native + - video site: mediaTypes: + - banner - native + - video