Skip to content

Commit

Permalink
TheMediaGrid s2s adapter: add video support (prebid#1020)
Browse files Browse the repository at this point in the history
* Add TheMediaGrid server adapter

* Add video support in TheMediaGrid s2s adapter
  • Loading branch information
TheMediaGrid authored and mansinahar committed Oct 31, 2019
1 parent 5d856e1 commit 1054d57
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
31 changes: 30 additions & 1 deletion adapters/grid/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
)

type GridAdapter struct {
Expand Down Expand Up @@ -62,9 +63,14 @@ func (a *GridAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequ

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
bidType, err := getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp)
if err != nil {
return nil, []error{err}
}

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
BidType: "banner",
BidType: bidType,
})
}
}
Expand All @@ -78,3 +84,26 @@ func NewGridBidder(endpoint string) *GridAdapter {
endpoint: endpoint,
}
}

func getMediaTypeForImp(impID string, imps []openrtb.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
}

return "", &errortypes.BadServerResponse{
Message: fmt.Sprintf("Unknown impression type for ID: \"%s\"", impID),
}
}
}

// This shouldnt happen. Lets handle it just incase by returning an error.
return "", &errortypes.BadServerResponse{
Message: fmt.Sprintf("Failed to find impression for ID: \"%s\"", impID),
}
}
83 changes: 83 additions & 0 deletions adapters/grid/gridtest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"mockBidRequest": {
"id": "test-request-id",
"site": {
"page": "https://good.site/url"
},
"imp": [{
"id": "test-imp-id",
"video": {
"mimes": ["video/mp4"],
"protocols": [2, 5],
"w": 300,
"h": 250
},
"ext": {
"bidder": {}
}
}]
},

"httpCalls": [{
"expectedRequest": {
"uri": "http://localhost/prebid",
"body": {
"id": "test-request-id",
"site": {
"page": "https://good.site/url"
},
"imp": [{
"id": "test-imp-id",
"video": {
"mimes": ["video/mp4"],
"protocols": [2, 5],
"w": 300,
"h": 250
},
"ext": {
"bidder": {}
}
}]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"seat": "grid",
"bid": [{
"id": "randomid",
"impid": "test-imp-id",
"price": 0.500000,
"adid": "12345678",
"adm": "some-test-ad-vast",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300
}]
}],
"cur": "USD"
}
}
}],

"expectedBidResponses": [{
"currency": "USD",
"bids": [{
"bid": {
"id": "randomid",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-ad-vast",
"adid": "12345678",
"cid": "987",
"crid": "12345678",
"w": 300,
"h": 250
},
"type": "video"
}]
}]
}
1 change: 1 addition & 0 deletions static/bidder-info/grid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ capabilities:
site:
mediaTypes:
- banner
- video

0 comments on commit 1054d57

Please sign in to comment.