From e2a9806c37fdddd19b732d869ef1ab441e681a0f Mon Sep 17 00:00:00 2001 From: IQZoneAdx <88879712+IQZoneAdx@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:25:17 +0200 Subject: [PATCH] iqzone get media type from mtype bid property (#3557) --- adapters/iqzone/iqzone.go | 29 +++++++------------ .../iqzonetest/exemplary/endpointId.json | 2 ++ .../iqzonetest/exemplary/simple-banner.json | 2 ++ .../iqzonetest/exemplary/simple-native.json | 4 ++- .../iqzonetest/exemplary/simple-video.json | 2 ++ .../exemplary/simple-web-banner.json | 2 ++ .../supplemental/bad_media_type.json | 2 +- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/adapters/iqzone/iqzone.go b/adapters/iqzone/iqzone.go index 1888711df93..099d11106b3 100644 --- a/adapters/iqzone/iqzone.go +++ b/adapters/iqzone/iqzone.go @@ -111,7 +111,7 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R bidResponse.Currency = response.Cur for _, seatBid := range response.SeatBid { for i := range seatBid.Bid { - bidType, err := getMediaTypeForImp(seatBid.Bid[i].ImpID, request.Imp) + bidType, err := getBidMediaType(&seatBid.Bid[i]) if err != nil { return nil, []error{err} } @@ -126,22 +126,15 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R return bidResponse, nil } -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 - } - if imp.Banner == nil && imp.Video != nil { - return openrtb_ext.BidTypeVideo, nil - } - if imp.Banner == nil && imp.Video == nil && imp.Native != nil { - return openrtb_ext.BidTypeNative, nil - } - } - } - - return "", &errortypes.BadInput{ - Message: fmt.Sprintf("Failed to find impression \"%s\"", impID), +func getBidMediaType(bid *openrtb2.Bid) (openrtb_ext.BidType, error) { + switch bid.MType { + case openrtb2.MarkupBanner: + return openrtb_ext.BidTypeBanner, nil + case openrtb2.MarkupVideo: + return openrtb_ext.BidTypeVideo, nil + case openrtb2.MarkupNative: + return openrtb_ext.BidTypeNative, nil + default: + return "", fmt.Errorf("Unable to fetch mediaType in multi-format: %s", bid.ImpID) } } diff --git a/adapters/iqzone/iqzonetest/exemplary/endpointId.json b/adapters/iqzone/iqzonetest/exemplary/endpointId.json index 79887443a89..dc8a0010bee 100644 --- a/adapters/iqzone/iqzonetest/exemplary/endpointId.json +++ b/adapters/iqzone/iqzonetest/exemplary/endpointId.json @@ -90,6 +90,7 @@ "dealid": "test_dealid", "w": 300, "h": 250, + "mtype": 1, "ext": { "prebid": { "type": "banner" @@ -119,6 +120,7 @@ "dealid": "test_dealid", "w": 300, "h": 250, + "mtype": 1, "ext": { "prebid": { "type": "banner" diff --git a/adapters/iqzone/iqzonetest/exemplary/simple-banner.json b/adapters/iqzone/iqzonetest/exemplary/simple-banner.json index 12f97e1bb52..08d27d151cd 100644 --- a/adapters/iqzone/iqzonetest/exemplary/simple-banner.json +++ b/adapters/iqzone/iqzonetest/exemplary/simple-banner.json @@ -90,6 +90,7 @@ "dealid": "test_dealid", "w": 300, "h": 250, + "mtype": 1, "ext": { "prebid": { "type": "banner" @@ -119,6 +120,7 @@ "dealid": "test_dealid", "w": 300, "h": 250, + "mtype": 1, "ext": { "prebid": { "type": "banner" diff --git a/adapters/iqzone/iqzonetest/exemplary/simple-native.json b/adapters/iqzone/iqzonetest/exemplary/simple-native.json index 967a846dd07..bf811487c7d 100644 --- a/adapters/iqzone/iqzonetest/exemplary/simple-native.json +++ b/adapters/iqzone/iqzonetest/exemplary/simple-native.json @@ -74,6 +74,7 @@ "dealid": "test_dealid", "w": 300, "h": 250, + "mtype": 4, "ext": { "prebid": { "type": "native" @@ -107,7 +108,8 @@ "prebid": { "type": "native" } - } + }, + "mtype": 4 }, "type": "native" } diff --git a/adapters/iqzone/iqzonetest/exemplary/simple-video.json b/adapters/iqzone/iqzonetest/exemplary/simple-video.json index 7e2b7971e24..5130a6e651b 100644 --- a/adapters/iqzone/iqzonetest/exemplary/simple-video.json +++ b/adapters/iqzone/iqzonetest/exemplary/simple-video.json @@ -86,6 +86,7 @@ "cid": "test_cid", "crid": "test_crid", "dealid": "test_dealid", + "mtype": 2, "ext": { "prebid": { "type": "video" @@ -114,6 +115,7 @@ "cid": "test_cid", "crid": "test_crid", "dealid": "test_dealid", + "mtype": 2, "ext": { "prebid": { "type": "video" diff --git a/adapters/iqzone/iqzonetest/exemplary/simple-web-banner.json b/adapters/iqzone/iqzonetest/exemplary/simple-web-banner.json index 4d69ef41336..96ff1b88aa8 100644 --- a/adapters/iqzone/iqzonetest/exemplary/simple-web-banner.json +++ b/adapters/iqzone/iqzonetest/exemplary/simple-web-banner.json @@ -90,6 +90,7 @@ "dealid": "test_dealid", "w": 468, "h": 60, + "mtype": 1, "ext": { "prebid": { "type": "banner" @@ -119,6 +120,7 @@ "dealid": "test_dealid", "w": 468, "h": 60, + "mtype": 1, "ext": { "prebid": { "type": "banner" diff --git a/adapters/iqzone/iqzonetest/supplemental/bad_media_type.json b/adapters/iqzone/iqzonetest/supplemental/bad_media_type.json index 4dddd568932..a2c886504b0 100644 --- a/adapters/iqzone/iqzonetest/supplemental/bad_media_type.json +++ b/adapters/iqzone/iqzonetest/supplemental/bad_media_type.json @@ -79,7 +79,7 @@ }], "expectedMakeBidsErrors": [ { - "value": "Failed to find impression \"test-imp-id\"", + "value": "Unable to fetch mediaType in multi-format: test-imp-id", "comparison": "literal" } ]