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

Silvermob: Use mtype and add global host #3936

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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,

Choose a reason for hiding this comment

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

Found incorrect assignment made to Bid. bid variable receives a new value in each iteration of range loop. Assigning the address of bid (&bid) to Bid will result in a pointer that always points to the same memory address with the value of the last iteration. This can lead to unexpected behavior or incorrect results. Refer https://go.dev/play/p/9ZS1f-5h4qS
Consider using an index variable in the seatBids.Bid loop as shown below

  for _, seatBid := range response.SeatBid {
    for i := range seatBids.Bid {
      ...
      responseBid := &adapters.TypedBid{
        Bid: &seatBids.Bid[i],
        ...
      }
      ...
      ...
    }
  }

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"
}
]
}
Loading