From a0dceab9dec914c88a08b6a1586111ed07aafd8d Mon Sep 17 00:00:00 2001 From: rpanchyk Date: Thu, 23 Jan 2020 17:04:18 +0200 Subject: [PATCH] Add imp.ext.is_rewarded_inventory flag for rewarded video in Rubicon (#1170) --- adapters/rubicon/rubicon.go | 9 ++++++- adapters/rubicon/rubicon_test.go | 42 ++++++++++++++++++++++++++++++++ openrtb_ext/imp.go | 3 +++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/adapters/rubicon/rubicon.go b/adapters/rubicon/rubicon.go index e7461c48f7e..46caf262108 100644 --- a/adapters/rubicon/rubicon.go +++ b/adapters/rubicon/rubicon.go @@ -129,6 +129,7 @@ type rubiconVideoParams struct { type rubiconVideoExt struct { Skip int `json:"skip,omitempty"` SkipDelay int `json:"skipdelay,omitempty"` + VideoType string `json:"videotype,omitempty"` RP rubiconVideoExtRP `json:"rp"` } @@ -693,8 +694,14 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adap continue } + // if imp.ext.is_rewarded_inventory = 1, set imp.video.ext.videotype = "rewarded" + var videoType = "" + if bidderExt.Prebid != nil && bidderExt.Prebid.IsRewardedInventory == 1 { + videoType = "rewarded" + } + videoCopy := *thisImp.Video - videoExt := rubiconVideoExt{Skip: rubiconExt.Video.Skip, SkipDelay: rubiconExt.Video.SkipDelay, RP: rubiconVideoExtRP{SizeID: rubiconExt.Video.VideoSizeID}} + videoExt := rubiconVideoExt{Skip: rubiconExt.Video.Skip, SkipDelay: rubiconExt.Video.SkipDelay, VideoType: videoType, RP: rubiconVideoExtRP{SizeID: rubiconExt.Video.VideoSizeID}} videoCopy.Ext, err = json.Marshal(&videoExt) thisImp.Video = &videoCopy thisImp.Banner = nil diff --git a/adapters/rubicon/rubicon_test.go b/adapters/rubicon/rubicon_test.go index dd9cea62bc7..d386daed5b1 100644 --- a/adapters/rubicon/rubicon_test.go +++ b/adapters/rubicon/rubicon_test.go @@ -1270,6 +1270,48 @@ func TestOpenRTBRequestWithVideoImpEvenIfImpHasBannerButAllRequiredVideoFields(t assert.NotNil(t, rubiconReq.Imp[0].Video, "Video object must be in request impression") } +func TestOpenRTBRequestWithVideoImpAndEnabledRewardedInventoryFlag(t *testing.T) { + bidder := new(RubiconAdapter) + + request := &openrtb.BidRequest{ + ID: "test-request-id", + Imp: []openrtb.Imp{{ + ID: "test-imp-id", + Video: &openrtb.Video{ + W: 640, + H: 360, + MIMEs: []string{"video/mp4"}, + Protocols: []openrtb.Protocol{openrtb.ProtocolVAST10}, + MaxDuration: 30, + Linearity: 1, + API: []openrtb.APIFramework{}, + }, + Ext: json.RawMessage(`{ + "prebid":{ + "is_rewarded_inventory": 1 + }, + "bidder": { + "video": {"size_id": 1} + }}`), + }}, + } + + reqs, _ := bidder.MakeRequests(request, &adapters.ExtraRequestInfo{}) + + rubiconReq := &openrtb.BidRequest{} + if err := json.Unmarshal(reqs[0].Body, rubiconReq); err != nil { + t.Fatalf("Unexpected error while decoding request: %s", err) + } + + videoExt := &rubiconVideoExt{} + if err := json.Unmarshal(rubiconReq.Imp[0].Video.Ext, &videoExt); err != nil { + t.Fatal("Error unmarshalling request.imp[i].video.ext object.") + } + + assert.Equal(t, "rewarded", videoExt.VideoType, + "Unexpected VideoType. Got %s. Expected %s", videoExt.VideoType, "rewarded") +} + func TestOpenRTBEmptyResponse(t *testing.T) { httpResp := &adapters.ResponseData{ StatusCode: http.StatusNoContent, diff --git a/openrtb_ext/imp.go b/openrtb_ext/imp.go index 499d1f631bf..0e8f224b884 100644 --- a/openrtb_ext/imp.go +++ b/openrtb_ext/imp.go @@ -20,6 +20,9 @@ type ExtImp struct { type ExtImpPrebid struct { StoredRequest *ExtStoredRequest `json:"storedrequest"` + // Rewarded inventory signal, can be 0 or 1 + IsRewardedInventory int8 `json:"is_rewarded_inventory"` + // NOTE: This is not part of the official API, we are not expecting clients // migrate from imp[...].ext.${BIDDER} to imp[...].ext.prebid.bidder.${BIDDER} // at this time