Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InMobi: mtype support #3921

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions adapters/inmobi/inmobi.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (a *InMobiAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalR

for _, sb := range serverBidResponse.SeatBid {
for i := range sb.Bid {
mediaType := getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp)
mediaType := getMediaTypeForImp(sb.Bid[i])
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
BidType: mediaType,
Expand Down Expand Up @@ -118,18 +118,17 @@ func preprocess(imp *openrtb2.Imp) error {
return nil
}

func getMediaTypeForImp(impId string, imps []openrtb2.Imp) openrtb_ext.BidType {
mediaType := openrtb_ext.BidTypeBanner
for _, imp := range imps {
if imp.ID == impId {
if imp.Video != nil {
mediaType = openrtb_ext.BidTypeVideo
}
if imp.Native != nil {
mediaType = openrtb_ext.BidTypeNative
}
break
}
func getMediaTypeForImp(bid openrtb2.Bid) openrtb_ext.BidType {
switch bid.MType {
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner
case openrtb2.MarkupVideo:
return openrtb_ext.BidTypeVideo
case openrtb2.MarkupAudio:
return openrtb_ext.BidTypeAudio
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative
default:
return openrtb_ext.BidTypeBanner
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears you were defaulting to banner before adding mtype support but now that you have it, is your server supposed to always set it? If so, you might want to do what most other adapters do which is to return an error if mtype does not equal one of your supported formats.

default:
	return "", fmt.Errorf("unrecognized bid type in response from inmobi for bid %s", bid.ImpID)

and then in the calling code:

mediaType, err := getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp)
if err != nil {
	return nil, []error{err}
}

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I've made the recommended changes.

}
return mediaType
}
4 changes: 3 additions & 1 deletion adapters/inmobi/inmobitest/exemplary/simple-app-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"price": 2.0,
"id": "1234",
"adm": "bannerhtml",
"impid": "imp-id"
"impid": "imp-id",
"mtype": 1
}
]
}
Expand All @@ -94,6 +95,7 @@
"adm": "bannerhtml",
"crid": "123456789",
"nurl": "https://some.event.url/params",
"mtype": 1,
"ext": {
"prebid": {
"meta": {
Expand Down
4 changes: 3 additions & 1 deletion adapters/inmobi/inmobitest/exemplary/simple-app-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"price": 2.0,
"id": "1234",
"adm": "native-json",
"impid": "imp-id"
"impid": "imp-id",
"mtype": 4
}
]
}
Expand All @@ -92,6 +93,7 @@
"adm": "native-json",
"crid": "123456789",
"nurl": "https://some.event.url/params",
"mtype": 4,
"ext": {
"prebid": {
"meta": {
Expand Down
4 changes: 3 additions & 1 deletion adapters/inmobi/inmobitest/exemplary/simple-app-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
"price": 2.0,
"id": "1234",
"adm": "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <VAST version=\"3.0\"></VAST>",
"impid": "imp-id"
"impid": "imp-id",
"mtype": 2
}
]
}
Expand All @@ -96,6 +97,7 @@
"adm": "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <VAST version=\"3.0\"></VAST>",
"crid": "123456789",
"nurl": "https://some.event.url/params",
"mtype": 2,
"ext": {
"prebid": {
"meta": {
Expand Down
4 changes: 3 additions & 1 deletion adapters/inmobi/inmobitest/exemplary/simple-web-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"price": 2.0,
"id": "1234",
"adm": "bannerhtml",
"impid": "imp-id"
"impid": "imp-id",
"mtype": 1
}
]
}
Expand All @@ -92,6 +93,7 @@
"adm": "bannerhtml",
"crid": "123456789",
"nurl": "https://some.event.url/params",
"mtype": 1,
"ext": {
"prebid": {
"meta": {
Expand Down
4 changes: 3 additions & 1 deletion adapters/inmobi/inmobitest/exemplary/simple-web-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"price": 2.0,
"id": "1234",
"adm": "native-json",
"impid": "imp-id"
"impid": "imp-id",
"mtype": 4
}
]
}
Expand All @@ -90,6 +91,7 @@
"adm": "native-json",
"crid": "123456789",
"nurl": "https://some.event.url/params",
"mtype": 4,
"ext": {
"prebid": {
"meta": {
Expand Down
4 changes: 3 additions & 1 deletion adapters/inmobi/inmobitest/exemplary/simple-web-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"price": 2.0,
"id": "1234",
"adm": "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <VAST version=\"3.0\"></VAST>",
"impid": "imp-id"
"impid": "imp-id",
"mtype": 2
}
]
}
Expand All @@ -94,6 +95,7 @@
"adm": "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <VAST version=\"3.0\"></VAST>",
"crid": "123456789",
"nurl": "https://some.event.url/params",
"mtype": 2,
"ext": {
"prebid": {
"meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"price": 2.0,
"id": "1234",
"adm": "bannerhtml",
"impid": "imp-id"
"impid": "imp-id",
"mtype": 1
}
]
}
Expand All @@ -100,6 +101,7 @@
"adm": "bannerhtml",
"crid": "123456789",
"nurl": "https://some.event.url/params",
"mtype": 1,
"ext": {
"prebid": {
"meta": {
Expand Down
Loading