Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Add imp.ext.is_rewarded_inventory flag for rewarded video in Rubicon (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
rpanchyk authored and SyntaxNode committed Jan 23, 2020
1 parent d0c3456 commit a0dceab
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
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)
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

0 comments on commit a0dceab

Please sign in to comment.