Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AvinashKapre committed Nov 25, 2024
1 parent ec838bc commit 9aa3b7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
29 changes: 8 additions & 21 deletions adapters/pubmatic/pubmatic_ow.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ func trimSuffixWithPattern(input string) string {
}

func updateBidExtWithMultiFloor(bidImpID string, bidExt, reqBody []byte) []byte {
reqBodyMap := getMapFromJSON(reqBody)
if reqBodyMap == nil {
var externalRequest openrtb2.BidRequest

if err := json.Unmarshal(reqBody, &externalRequest); err != nil {
return bidExt
}

Expand All @@ -163,35 +164,21 @@ func updateBidExtWithMultiFloor(bidImpID string, bidExt, reqBody []byte) []byte
updatedBidExt = json.RawMessage(`{}`)
}

imps, ok := reqBodyMap["imp"].([]interface{})
if !ok {
return bidExt
}

for _, imp := range imps {
impMap, ok := imp.(map[string]interface{})
if !ok {
for _, imp := range externalRequest.Imp {
if imp.ID != bidImpID {
continue
}

reqImpID, ok := impMap["id"].(string)
if !ok || reqImpID != bidImpID {
if imp.BidFloor <= 0 {
continue
}

floor, ok := impMap["bidfloor"].(float64)
if !ok || floor <= 0 {
continue
}

var err error
updatedBidExt, err = jsonparser.Set(updatedBidExt, []byte(fmt.Sprintf("%f", floor)), multiBidMultiFloorValueKey)
updatedBidExt, err = jsonparser.Set(updatedBidExt, []byte(fmt.Sprintf("%f", imp.BidFloor)), multiBidMultiFloorValueKey)
if err != nil {
return bidExt
}
}

if len(updatedBidExt) > 2 {
if string(updatedBidExt) != "{}" {
return updatedBidExt
}
return bidExt
Expand Down
5 changes: 3 additions & 2 deletions modules/pubmatic/openwrap/defaultbids.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,14 @@ func (m *OpenWrap) addDefaultBids(rctx *models.RequestCtx, bidResponse *openrtb2
}

func (m *OpenWrap) addDefaultBidsForMultiFloorsConfig(rctx *models.RequestCtx, bidResponse *openrtb2.BidResponse, bidResponseExt openrtb_ext.ExtBidResponse) map[string]map[string][]openrtb2.Bid {
defaultBids := rctx.DefaultBids

// MultiBidMultiFloor is only supported for AppLovinMax
if rctx.Endpoint != models.EndpointAppLovinMax || !rctx.AppLovinMax.MultiFloorsConfig.Enabled {
return defaultBids
return rctx.DefaultBids
}

defaultBids := rctx.DefaultBids

bidderExcludeFloors := make(map[string][]float64, len(bidResponse.SeatBid)) //exclude floors which are already present in bidresponse
var adunitFloors []float64 //floors for each adunit
bidderDefaultbidFloors := make(map[string][]float64, len(bidResponse.SeatBid)) //per bidder floors for default bids
Expand Down

0 comments on commit 9aa3b7d

Please sign in to comment.