Skip to content

Commit

Permalink
MetaX: Add BidVideo for video ads (#4095)
Browse files Browse the repository at this point in the history
Signed-off-by: Kehan Pan <[email protected]>
  • Loading branch information
metax-kehan authored Dec 16, 2024
1 parent f14e113 commit fead7ec
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 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
42 changes: 42 additions & 0 deletions adapters/metax/metax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,48 @@ func TestGetBidType(t *testing.T) {
}
}

func TestGetBidVideo(t *testing.T) {
tests := []struct {
description string
bid *openrtb2.Bid
bidvideo openrtb_ext.ExtBidPrebidVideo
}{
{
description: "One category, no duration",
bid: &openrtb2.Bid{Cat: []string{"IAB1-1"}},
bidvideo: openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "IAB1-1", Duration: 0},
},
{
description: "Two categories and use the first, no duration",
bid: &openrtb2.Bid{Cat: []string{"IAB1-1", "IAB1-2"}},
bidvideo: openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "IAB1-1", Duration: 0},
},
{
description: "No category, no duration",
bid: &openrtb2.Bid{Cat: []string{}},
bidvideo: openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "", Duration: 0},
},
{
description: "No category(nil), no duration",
bid: &openrtb2.Bid{Cat: nil},
bidvideo: openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "", Duration: 0},
},
{
description: "Two categories and use the first, duration is 15",
bid: &openrtb2.Bid{Cat: []string{"IAB1-1", "IAB1-2"}, Dur: 15},
bidvideo: openrtb_ext.ExtBidPrebidVideo{PrimaryCategory: "IAB1-1", Duration: 15},
},
}

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
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
20 changes: 17 additions & 3 deletions adapters/metax/metaxtest/exemplary/simple-app-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@
"crid": "test-crid",
"w": 1024,
"h": 576,
"mtype": 2
"mtype": 2,
"dur": 15,
"cat": [
"IAB1-5",
"IAB1-6"
]
}
]
}
Expand All @@ -120,9 +125,18 @@
"crid": "test-crid",
"w": 1024,
"h": 576,
"mtype": 2
"mtype": 2,
"dur": 15,
"cat": [
"IAB1-5",
"IAB1-6"
]
},
"type": "video"
"type": "video",
"video": {
"duration": 15,
"primary_category": "IAB1-5"
}
}
]
}
Expand Down

0 comments on commit fead7ec

Please sign in to comment.