Skip to content

Commit

Permalink
Adprime: Add mtype (#3439)
Browse files Browse the repository at this point in the history
Co-authored-by: Aiholkin <[email protected]>
  • Loading branch information
Adprime and Aiholkin authored Feb 7, 2024
1 parent 86bddad commit 535d1f7
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 19 deletions.
30 changes: 12 additions & 18 deletions adapters/adprime/adprime.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func (a *AdprimeAdapter) MakeBids(internalRequest *openrtb2.BidRequest, external

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
bidType, err := getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp)
bidType, err := getBidMediaType(&sb.Bid[i])

if err != nil {
errs = append(errs, err)
} else {
Expand All @@ -163,22 +164,15 @@ func (a *AdprimeAdapter) MakeBids(internalRequest *openrtb2.BidRequest, external
return bidResponse, errs
}

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.Video != nil {
return openrtb_ext.BidTypeVideo, nil
}
if 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)
}
}
2 changes: 2 additions & 0 deletions adapters/adprime/adprimetest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"dealid": "test_dealid",
"w": 300,
"h": 250,
"mtype": 1,
"ext": {
"prebid": {
"type": "banner"
Expand Down Expand Up @@ -120,6 +121,7 @@
"dealid": "test_dealid",
"w": 300,
"h": 250,
"mtype": 1,
"ext": {
"prebid": {
"type": "banner"
Expand Down
2 changes: 2 additions & 0 deletions adapters/adprime/adprimetest/exemplary/simple-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"dealid": "test_dealid",
"w": 300,
"h": 250,
"mtype": 4,
"ext": {
"prebid": {
"type": "native"
Expand Down Expand Up @@ -104,6 +105,7 @@
"dealid": "test_dealid",
"w": 300,
"h": 250,
"mtype": 4,
"ext": {
"prebid": {
"type": "native"
Expand Down
2 changes: 2 additions & 0 deletions adapters/adprime/adprimetest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 2,
"ext": {
"prebid": {
"type": "video"
Expand Down Expand Up @@ -115,6 +116,7 @@
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"mtype": 2,
"ext": {
"prebid": {
"type": "video"
Expand Down
2 changes: 2 additions & 0 deletions adapters/adprime/adprimetest/exemplary/simple-web-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"dealid": "test_dealid",
"w": 468,
"h": 60,
"mtype": 1,
"ext": {
"prebid": {
"type": "banner"
Expand Down Expand Up @@ -120,6 +121,7 @@
"dealid": "test_dealid",
"w": 468,
"h": 60,
"mtype": 1,
"ext": {
"prebid": {
"type": "banner"
Expand Down
2 changes: 2 additions & 0 deletions adapters/adprime/adprimetest/exemplary/withAudiences.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"dealid": "test_dealid",
"w": 300,
"h": 250,
"mtype": 1,
"ext": {
"prebid": {
"type": "banner"
Expand Down Expand Up @@ -124,6 +125,7 @@
"dealid": "test_dealid",
"w": 300,
"h": 250,
"mtype": 1,
"ext": {
"prebid": {
"type": "banner"
Expand Down
2 changes: 2 additions & 0 deletions adapters/adprime/adprimetest/exemplary/withKeywords.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"dealid": "test_dealid",
"w": 300,
"h": 250,
"mtype": 1,
"ext": {
"prebid": {
"type": "banner"
Expand Down Expand Up @@ -122,6 +123,7 @@
"dealid": "test_dealid",
"w": 300,
"h": 250,
"mtype": 1,
"ext": {
"prebid": {
"type": "banner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"expectedBidResponses": [{"currency":"USD","bids":[]}],
"expectedMakeBidsErrors": [
{
"value": "Failed to find impression \"test-imp-id\"",
"value": "Unable to fetch mediaType in multi-format: test-imp-id",
"comparison": "literal"
}
]
Expand Down

0 comments on commit 535d1f7

Please sign in to comment.