Skip to content

Commit

Permalink
MetaX: Add BidVideo for video ads
Browse files Browse the repository at this point in the history
Signed-off-by: Kehan Pan <[email protected]>
  • Loading branch information
metax-kehan committed Dec 10, 2024
1 parent a9564da commit 06155ef
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
16 changes: 14 additions & 2 deletions adapters/metax/metax.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ func (a *adapter) MakeBids(bidReq *openrtb2.BidRequest, reqData *adapters.Reques
return nil, []error{err}
}
resp.Bids = append(resp.Bids, &adapters.TypedBid{
Bid: bid,
BidType: bidType,
Bid: bid,
BidType: bidType,
BidVideo: getBidVideo(bid),
})
}
}
Expand Down Expand Up @@ -177,6 +178,17 @@ func getBidType(bid *openrtb2.Bid) (openrtb_ext.BidType, error) {
}
}

func getBidVideo(bid *openrtb2.Bid) *openrtb_ext.ExtBidPrebidVideo {
bidVideo := openrtb_ext.ExtBidPrebidVideo{}
if len(bid.Cat) > 0 {
bidVideo.PrimaryCategory = bid.Cat[0]
}
if bid.Dur > 0 {
bidVideo.Duration = int(bid.Dur)
}
return &bidVideo
}

// Builder builds a new instance of the MetaX adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
if config.Endpoint == "" {
Expand Down
34 changes: 34 additions & 0 deletions adapters/metax/metax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,40 @@ func TestGetBidType(t *testing.T) {
}
}

func TestGetBidVideo(t *testing.T) {
tests := []struct {
bid *openrtb2.Bid
bidvideo openrtb_ext.ExtBidPrebidVideo
}{
{
&openrtb2.Bid{Cat: []string{"IAB1-1"}},
openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "IAB1-1", Duration: 0},
},
{
&openrtb2.Bid{Cat: []string{"IAB1-1", "IAB1-2"}},
openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "IAB1-1", Duration: 0},
},
{
&openrtb2.Bid{Cat: []string{}},
openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "", Duration: 0},
},
{
&openrtb2.Bid{Cat: nil},
openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "", Duration: 0},
},
{
&openrtb2.Bid{Cat: []string{"IAB1-1", "IAB1-2"}, Dur: 15},
openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "IAB1-1", Duration: 15},
},
}

for _, test := range tests {
bidVideo := getBidVideo(test.bid)
assert.Equal(t, test.bidvideo.PrimaryCategory, bidVideo.PrimaryCategory)
assert.Equal(t, test.bidvideo.Duration, bidVideo.Duration)
}
}

func TestBuilder(t *testing.T) {
serverCfg := config.Server{}

Expand Down

0 comments on commit 06155ef

Please sign in to comment.