Skip to content

Commit

Permalink
Silvermob: Use mtype and add global host (#3936)
Browse files Browse the repository at this point in the history
  • Loading branch information
freemmy authored Dec 10, 2024
1 parent f46883b commit 30b1d75
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 19 deletions.
44 changes: 25 additions & 19 deletions adapters/silvermob/silvermob.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SilverMobAdapter struct {
}

func isValidHost(host string) bool {
return host == "eu" || host == "us" || host == "apac"
return host == "eu" || host == "us" || host == "apac" || host == "global"
}

// Builder builds a new instance of the SilverMob adapter for the given bidder with the given config.
Expand Down Expand Up @@ -177,28 +177,34 @@ func (a *SilverMobAdapter) MakeBids(
bidResponse := adapters.NewBidderResponseWithBidsCapacity(1)

for _, sb := range bidResp.SeatBid {
for _, bid := range sb.Bid {
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: getMediaTypeForImp(bid.ImpID, openRTBRequest.Imp),
})
for i := range sb.Bid {
bid := sb.Bid[i]
bidType, err := getBidMediaTypeFromMtype(&bid)

if err != nil {
errs = append(errs, err)
} else {
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
})
}

}
}

return bidResponse, nil
return bidResponse, errs
}

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
} else if imp.Native != nil {
mediaType = openrtb_ext.BidTypeNative
}
return mediaType
}
func getBidMediaTypeFromMtype(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 for imp: %s", bid.ImpID)
}
return mediaType
}
2 changes: 2 additions & 0 deletions adapters/silvermob/silvermobtest/exemplary/banner-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "1",
"price": 3.5,
"mtype": 1,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
Expand Down Expand Up @@ -147,6 +148,7 @@
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "1",
"price": 3.5,
"mtype": 1,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"mtype": 1,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
Expand Down Expand Up @@ -226,6 +227,7 @@
"id": "a3ae1b4e2fc24a4fb45540082e98e162",
"impid": "another-impression-id",
"price": 3.5,
"mtype": 1,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
Expand Down Expand Up @@ -259,6 +261,7 @@
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"mtype": 1,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
Expand All @@ -278,6 +281,7 @@
"id": "a3ae1b4e2fc24a4fb45540082e98e162",
"impid": "another-impression-id",
"price": 3.5,
"mtype": 1,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
Expand Down
2 changes: 2 additions & 0 deletions adapters/silvermob/silvermobtest/exemplary/native-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"mtype": 4,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
Expand Down Expand Up @@ -145,6 +146,7 @@
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"mtype": 4,
"adm": "awesome-markup",
"crid": "20",
"adomain": [
Expand Down
2 changes: 2 additions & 0 deletions adapters/silvermob/silvermobtest/exemplary/video-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"adomain": [
"awesome.com"
],
"mtype": 2,
"crid": "20",
"w": 1280,
"h": 720
Expand Down Expand Up @@ -156,6 +157,7 @@
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"mtype": 2,
"adm": "awesome-markup",
"crid": "20",
"adomain": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

{
"mockBidRequest": {
"id": "some-request-id",
"tmax": 1000,
"user": {
"buyeruid": "awesome-user"
},
"app": {
"id": "app_001",
"bundle": "com.awesome.app",
"publisher": {
"id": "2"
}
},
"imp": [
{
"id": "some-impression-id",
"tagid": "ogTAGID",
"video": {
"mimes": ["video/mp4"],
"w": 640,
"h": 480,
"minduration": 120,
"maxduration": 150
},
"ext": {
"bidder": {
"host": "eu",
"zoneid": "0"
}
}
}
]
},

"httpCalls": [{
"expectedRequest": {
"uri": "http://eu.example.com/api/dsp/bid/0",
"body": {
"id": "some-request-id",
"imp": [
{
"id": "some-impression-id",
"tagid": "ogTAGID",
"video": {
"mimes": [
"video/mp4"
],
"minduration": 120,
"maxduration": 150,
"w": 640,
"h": 480
},
"ext": {
"bidder": {
"host": "eu",
"zoneid": "0"
}
}
}
],
"app": {
"id": "app_001",
"bundle": "com.awesome.app",
"publisher": {
"id": "2"
}
},
"user": {
"buyeruid": "awesome-user"
},
"tmax": 1000
},
"impIDs":["some-impression-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "awesome-resp-id",
"seatbid": [
{
"bid": [
{
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
],
"crid": "20",
"w": 1280,
"h": 720
}
],
"seat": "silvermob"
}
],
"cur": "USD",
"ext": {
"responsetimemillis": {
"silvermob": 154
},
"tmaxrequest": 1000
}
}
}
}],
"expectedBidResponses": [{"currency":"USD","bids":[]}],
"expectedMakeBidsErrors": [
{
"value": "Unable to fetch mediaType for imp: some-impression-id",
"comparison": "literal"
}
]
}
118 changes: 118 additions & 0 deletions adapters/silvermob/silvermobtest/supplemental/invalid-mtype.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

{
"mockBidRequest": {
"id": "some-request-id",
"tmax": 1000,
"user": {
"buyeruid": "awesome-user"
},
"app": {
"id": "app_001",
"bundle": "com.awesome.app",
"publisher": {
"id": "2"
}
},
"imp": [
{
"id": "some-impression-id",
"tagid": "ogTAGID",
"video": {
"mimes": ["video/mp4"],
"w": 640,
"h": 480,
"minduration": 120,
"maxduration": 150
},
"ext": {
"bidder": {
"host": "eu",
"zoneid": "0"
}
}
}
]
},

"httpCalls": [{
"expectedRequest": {
"uri": "http://eu.example.com/api/dsp/bid/0",
"body": {
"id": "some-request-id",
"imp": [
{
"id": "some-impression-id",
"tagid": "ogTAGID",
"video": {
"mimes": [
"video/mp4"
],
"minduration": 120,
"maxduration": 150,
"w": 640,
"h": 480
},
"ext": {
"bidder": {
"host": "eu",
"zoneid": "0"
}
}
}
],
"app": {
"id": "app_001",
"bundle": "com.awesome.app",
"publisher": {
"id": "2"
}
},
"user": {
"buyeruid": "awesome-user"
},
"tmax": 1000
},
"impIDs":["some-impression-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "awesome-resp-id",
"seatbid": [
{
"bid": [
{
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
],
"mtype": 8,
"crid": "20",
"w": 1280,
"h": 720
}
],
"seat": "silvermob"
}
],
"cur": "USD",
"ext": {
"responsetimemillis": {
"silvermob": 154
},
"tmaxrequest": 1000
}
}
}
}],
"expectedBidResponses": [{"currency":"USD","bids":[]}],
"expectedMakeBidsErrors": [
{
"value": "Unable to fetch mediaType for imp: some-impression-id",
"comparison": "literal"
}
]
}

0 comments on commit 30b1d75

Please sign in to comment.