Skip to content

Commit

Permalink
pubmatic adapter: add param prebiddealpriority (#2281)
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-nilesh-chate authored Sep 19, 2022
1 parent c511121 commit 59dd6fb
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 20 deletions.
37 changes: 19 additions & 18 deletions adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ type PubmaticAdapter struct {
}

type pubmaticBidExt struct {
BidType *int `json:"BidType,omitempty"`
VideoCreativeInfo *pubmaticBidExtVideo `json:"video,omitempty"`
Marketplace string `json:"marketplace,omitempty"`
BidType *int `json:"BidType,omitempty"`
VideoCreativeInfo *pubmaticBidExtVideo `json:"video,omitempty"`
Marketplace string `json:"marketplace,omitempty"`
PrebidDealPriority int `json:"prebiddealpriority,omitempty"`
}

type pubmaticWrapperExt struct {
Expand Down Expand Up @@ -387,40 +388,40 @@ func (a *PubmaticAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externa
for _, sb := range bidResp.SeatBid {
for i := 0; i < len(sb.Bid); i++ {
bid := sb.Bid[i]
impVideo := &openrtb_ext.ExtBidPrebidVideo{}

if len(bid.Cat) > 1 {
bid.Cat = bid.Cat[0:1]
}

seat := ""
typedBid := &adapters.TypedBid{
Bid: &bid,
BidType: openrtb_ext.BidTypeBanner,
BidVideo: &openrtb_ext.ExtBidPrebidVideo{},
}

var bidExt *pubmaticBidExt
bidType := openrtb_ext.BidTypeBanner
err := json.Unmarshal(bid.Ext, &bidExt)
if err != nil {
errs = append(errs, err)
} else if bidExt != nil {
seat = bidExt.Marketplace
typedBid.Seat = openrtb_ext.BidderName(bidExt.Marketplace)
typedBid.BidType = getBidType(bidExt)
if bidExt.PrebidDealPriority > 0 {
typedBid.DealPriority = bidExt.PrebidDealPriority
}

if bidExt.VideoCreativeInfo != nil && bidExt.VideoCreativeInfo.Duration != nil {
impVideo.Duration = *bidExt.VideoCreativeInfo.Duration
typedBid.BidVideo.Duration = *bidExt.VideoCreativeInfo.Duration
}
bidType = getBidType(bidExt)
}

if bidType == openrtb_ext.BidTypeNative {
if typedBid.BidType == openrtb_ext.BidTypeNative {
bid.AdM, err = getNativeAdm(bid.AdM)
if err != nil {
errs = append(errs, err)
}
}

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
BidVideo: impVideo,
Seat: openrtb_ext.BidderName(seat),
})

bidResponse.Bids = append(bidResponse.Bids, typedBid)
}
}
return bidResponse, errs
Expand Down
95 changes: 95 additions & 0 deletions adapters/pubmatic/pubmatic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pubmatic

import (
"encoding/json"
"net/http"
"testing"

"github.com/mxmCherry/openrtb/v16/openrtb2"
Expand Down Expand Up @@ -264,3 +265,97 @@ func TestPubmaticAdapter_MakeRequests(t *testing.T) {
})
}
}

func TestPubmaticAdapter_MakeBids(t *testing.T) {
type fields struct {
URI string
}
type args struct {
internalRequest *openrtb2.BidRequest
externalRequest *adapters.RequestData
response *adapters.ResponseData
}
tests := []struct {
name string
fields fields
args args
wantErr []error
wantResp *adapters.BidderResponse
}{
{
name: "happy path, valid response with all bid params",
args: args{
response: &adapters.ResponseData{
StatusCode: http.StatusOK,
Body: []byte(`{"id": "test-request-id", "seatbid":[{"seat": "958", "bid":[{"id": "7706636740145184841", "impid": "test-imp-id", "price": 0.500000, "adid": "29681110", "adm": "some-test-ad", "adomain":["pubmatic.com"], "crid": "29681110", "h": 250, "w": 300, "dealid": "testdeal", "ext":{"dspid": 6, "deal_channel": 1, "prebiddealpriority": 1}}]}], "bidid": "5778926625248726496", "cur": "USD"}`),
},
},
wantErr: nil,
wantResp: &adapters.BidderResponse{
Bids: []*adapters.TypedBid{
{
Bid: &openrtb2.Bid{
ID: "7706636740145184841",
ImpID: "test-imp-id",
Price: 0.500000,
AdID: "29681110",
AdM: "some-test-ad",
ADomain: []string{"pubmatic.com"},
CrID: "29681110",
H: 250,
W: 300,
DealID: "testdeal",
Ext: json.RawMessage(`{"dspid": 6, "deal_channel": 1, "prebiddealpriority": 1}`),
},
DealPriority: 1,
BidType: openrtb_ext.BidTypeBanner,
BidVideo: &openrtb_ext.ExtBidPrebidVideo{},
},
},
Currency: "USD",
},
},
{
name: "ignore invalid prebiddealpriority",
args: args{
response: &adapters.ResponseData{
StatusCode: http.StatusOK,
Body: []byte(`{"id": "test-request-id", "seatbid":[{"seat": "958", "bid":[{"id": "7706636740145184841", "impid": "test-imp-id", "price": 0.500000, "adid": "29681110", "adm": "some-test-ad", "adomain":["pubmatic.com"], "crid": "29681110", "h": 250, "w": 300, "dealid": "testdeal", "ext":{"dspid": 6, "deal_channel": 1, "prebiddealpriority": -1}}]}], "bidid": "5778926625248726496", "cur": "USD"}`),
},
},
wantErr: nil,
wantResp: &adapters.BidderResponse{
Bids: []*adapters.TypedBid{
{
Bid: &openrtb2.Bid{
ID: "7706636740145184841",
ImpID: "test-imp-id",
Price: 0.500000,
AdID: "29681110",
AdM: "some-test-ad",
ADomain: []string{"pubmatic.com"},
CrID: "29681110",
H: 250,
W: 300,
DealID: "testdeal",
Ext: json.RawMessage(`{"dspid": 6, "deal_channel": 1, "prebiddealpriority": -1}`),
},
BidType: openrtb_ext.BidTypeBanner,
BidVideo: &openrtb_ext.ExtBidPrebidVideo{},
},
},
Currency: "USD",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &PubmaticAdapter{
URI: tt.fields.URI,
}
gotResp, gotErr := a.MakeBids(tt.args.internalRequest, tt.args.externalRequest, tt.args.response)
assert.Equal(t, tt.wantErr, gotErr, gotErr)
assert.Equal(t, tt.wantResp, gotResp)
})
}
}
6 changes: 4 additions & 2 deletions adapters/pubmatic/pubmatictest/exemplary/banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
"dealid":"test deal",
"ext": {
"dspid": 6,
"deal_channel": 1
"deal_channel": 1,
"prebiddealpriority": 1
}
}]
}
Expand Down Expand Up @@ -143,7 +144,8 @@
"dealid":"test deal",
"ext": {
"dspid": 6,
"deal_channel": 1
"deal_channel": 1,
"prebiddealpriority": 1
}
},
"type": "banner"
Expand Down

0 comments on commit 59dd6fb

Please sign in to comment.