From bcb5f949644bc6777d7662ab2038dd7a5f482b17 Mon Sep 17 00:00:00 2001 From: ym-prasanth <80693980+ym-prasanth@users.noreply.github.com> Date: Thu, 30 Nov 2023 05:47:42 -0500 Subject: [PATCH] Yieldmo: Get bid type from bid.ext.mediatype in bid response (#3295) --- adapters/yieldmo/yieldmo.go | 35 ++++++++++++++----- .../yieldmotest/exemplary/app-banner.json | 12 +++++-- .../yieldmotest/exemplary/app_video.json | 12 +++++-- .../yieldmotest/exemplary/simple-banner.json | 12 +++++-- .../yieldmotest/exemplary/simple_video.json | 12 +++++-- .../yieldmotest/exemplary/with_gpid.json | 12 +++++-- 6 files changed, 76 insertions(+), 19 deletions(-) diff --git a/adapters/yieldmo/yieldmo.go b/adapters/yieldmo/yieldmo.go index 795d32b8846..69841e88a22 100644 --- a/adapters/yieldmo/yieldmo.go +++ b/adapters/yieldmo/yieldmo.go @@ -30,6 +30,10 @@ type Ext struct { Gpid string `json:"gpid,omitempty"` } +type ExtBid struct { + MediaType string `json:"mediatype,omitempty"` +} + func (a *YieldmoAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { var errs []error var adapterRequests []*adapters.RequestData @@ -138,14 +142,18 @@ func (a *YieldmoAdapter) MakeBids(internalRequest *openrtb2.BidRequest, external for _, sb := range bidResp.SeatBid { for i := range sb.Bid { + bidType, err := getMediaTypeForImp(sb.Bid[i]) + if err != nil { + continue + } + bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ Bid: &sb.Bid[i], - BidType: getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp), + BidType: bidType, }) } } return bidResponse, nil - } // Builder builds a new instance of the Yieldmo adapter for the given bidder with the given config. @@ -156,12 +164,21 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co return bidder, nil } -func getMediaTypeForImp(impId string, imps []openrtb2.Imp) openrtb_ext.BidType { - //default to video unless banner exists in impression - for _, imp := range imps { - if imp.ID == impId && imp.Banner != nil { - return openrtb_ext.BidTypeBanner - } +// Retrieve the media type corresponding to the bid from the bid.ext object +func getMediaTypeForImp(bid openrtb2.Bid) (openrtb_ext.BidType, error) { + var bidExt ExtBid + if err := json.Unmarshal(bid.Ext, &bidExt); err != nil { + return "", &errortypes.BadInput{Message: err.Error()} + } + + switch bidExt.MediaType { + case "banner": + return openrtb_ext.BidTypeBanner, nil + case "video": + return openrtb_ext.BidTypeVideo, nil + case "native": + return openrtb_ext.BidTypeNative, nil + default: + return "", fmt.Errorf("invalid BidType: %s", bidExt.MediaType) } - return openrtb_ext.BidTypeVideo } diff --git a/adapters/yieldmo/yieldmotest/exemplary/app-banner.json b/adapters/yieldmo/yieldmotest/exemplary/app-banner.json index e674cf11539..92609cae16a 100644 --- a/adapters/yieldmo/yieldmotest/exemplary/app-banner.json +++ b/adapters/yieldmo/yieldmotest/exemplary/app-banner.json @@ -65,7 +65,11 @@ "adm": "some-test-ad", "crid": "crid_10", "h": 250, - "w": 300 + "w": 300, + "ext": + { + "mediatype": "banner" + } } ] } @@ -87,7 +91,11 @@ "adm": "some-test-ad", "crid": "crid_10", "w": 300, - "h": 250 + "h": 250, + "ext": + { + "mediatype": "banner" + } }, "type": "banner" } diff --git a/adapters/yieldmo/yieldmotest/exemplary/app_video.json b/adapters/yieldmo/yieldmotest/exemplary/app_video.json index e33c37f69bf..6f94a30b0d8 100644 --- a/adapters/yieldmo/yieldmotest/exemplary/app_video.json +++ b/adapters/yieldmo/yieldmotest/exemplary/app_video.json @@ -63,7 +63,11 @@ "adm": "some-test-ad", "crid": "crid_10", "h": 250, - "w": 300 + "w": 300, + "ext": + { + "mediatype": "video" + } } ] } @@ -85,7 +89,11 @@ "adm": "some-test-ad", "crid": "crid_10", "w": 300, - "h": 250 + "h": 250, + "ext": + { + "mediatype": "video" + } }, "type": "video" } diff --git a/adapters/yieldmo/yieldmotest/exemplary/simple-banner.json b/adapters/yieldmo/yieldmotest/exemplary/simple-banner.json index 11739ca1d32..ba2435001c7 100644 --- a/adapters/yieldmo/yieldmotest/exemplary/simple-banner.json +++ b/adapters/yieldmo/yieldmotest/exemplary/simple-banner.json @@ -65,7 +65,11 @@ "adm": "some-test-ad", "crid": "crid_10", "h": 250, - "w": 300 + "w": 300, + "ext": + { + "mediatype": "banner" + } } ] } @@ -87,7 +91,11 @@ "adm": "some-test-ad", "crid": "crid_10", "w": 300, - "h": 250 + "h": 250, + "ext": + { + "mediatype": "banner" + } }, "type": "banner" } diff --git a/adapters/yieldmo/yieldmotest/exemplary/simple_video.json b/adapters/yieldmo/yieldmotest/exemplary/simple_video.json index aaf53124365..ec65bc98b6c 100644 --- a/adapters/yieldmo/yieldmotest/exemplary/simple_video.json +++ b/adapters/yieldmo/yieldmotest/exemplary/simple_video.json @@ -63,7 +63,11 @@ "adm": "some-test-ad", "crid": "crid_10", "h": 250, - "w": 300 + "w": 300, + "ext": + { + "mediatype": "video" + } } ] } @@ -85,7 +89,11 @@ "adm": "some-test-ad", "crid": "crid_10", "w": 300, - "h": 250 + "h": 250, + "ext": + { + "mediatype": "video" + } }, "type": "video" } diff --git a/adapters/yieldmo/yieldmotest/exemplary/with_gpid.json b/adapters/yieldmo/yieldmotest/exemplary/with_gpid.json index bd9e911058a..d155f5db67f 100644 --- a/adapters/yieldmo/yieldmotest/exemplary/with_gpid.json +++ b/adapters/yieldmo/yieldmotest/exemplary/with_gpid.json @@ -73,7 +73,11 @@ "adm": "some-test-ad", "crid": "crid_10", "h": 250, - "w": 300 + "w": 300, + "ext": + { + "mediatype": "banner" + } } ] } @@ -95,7 +99,11 @@ "adm": "some-test-ad", "crid": "crid_10", "w": 300, - "h": 250 + "h": 250, + "ext": + { + "mediatype": "banner" + } }, "type": "banner" }