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

Add imp.ext.prebid.is_rewarded_inventory flag for rewarded video in Rubicon #1170

Merged
merged 2 commits into from
Jan 23, 2020
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
9 changes: 8 additions & 1 deletion adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to give the recently added VideoType field a value also on the legacy side of this adapter? Or is this field only for the OpenRTB2 endpoints?

 364 func (a *RubiconAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder *pbs.PBSBidder) (pbs.PBSBidSlice, error) {
 365     callOneObjects := make([]callOneObject, 0, len(bidder.AdUnits))
 366 +-- 54 lines: supportedMediaTypes := []pbs.MediaType{pbs.MEDIA_TYPE_BANNER, pbs.MEDIA_TYPE_VIDEO}-------------------------------------------------------------------------
 420
 421         if thisImp.Video != nil {
 422             videoExt := rubiconVideoExt{Skip: params.Video.Skip, SkipDelay: params.Video.SkipDelay, RP: rubiconVideoExtRP{SizeID: params.Video.VideoSizeID}}
 423             thisImp.Video.Ext, err = json.Marshal(&videoExt)
 424         } else {
 425             primarySizeID, altSizeIDs, err := parseRubiconSizes(unit.Sizes)
adapters/rubicon/rubicon.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't think so. This feature refers only for OpenRTB, no legacy support.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got ya. Approved

thisImp.Video = &videoCopy
thisImp.Banner = nil
Expand Down
42 changes: 42 additions & 0 deletions adapters/rubicon/rubicon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions openrtb_ext/imp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down