Skip to content

Commit

Permalink
test6
Browse files Browse the repository at this point in the history
  • Loading branch information
AvinashKapre committed Nov 19, 2024
1 parent 81f1866 commit ac2f35c
Show file tree
Hide file tree
Showing 5 changed files with 458 additions and 452 deletions.
38 changes: 0 additions & 38 deletions adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,44 +259,6 @@ func (a *PubmaticAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ad
return requestData, errs
}

// buildMultiFloorRequests builds multiple requests for each floor value
func (a *PubmaticAdapter) buildMultiFloorRequests(request *openrtb2.BidRequest, impFloorsMap map[string][]float64, cookies []string) ([]*adapters.RequestData, []error) {
requestData := []*adapters.RequestData{}
errs := make([]error, 0, MAX_MULTIFLOORS_PUBMATIC*len(request.Imp))

for i := 0; i < MAX_MULTIFLOORS_PUBMATIC; i++ {
isFloorsUpdated := false
newImps := make([]openrtb2.Imp, len(request.Imp))
copy(newImps, request.Imp)
//TODO-AK: Remove the imp from the request if the floor is not present except for the first floor
for j := range newImps {
floors, ok := impFloorsMap[request.Imp[j].ID]
if !ok || len(floors) <= i {
continue
}
isFloorsUpdated = true
newImps[j].BidFloor = floors[i]
newImps[j].ID = fmt.Sprintf("%s"+multiFloors+"%d", newImps[j].ID, i+1)
}

if !isFloorsUpdated {
continue
}

newRequest := *request
newRequest.Imp = newImps

newRequestData, errData := a.buildAdapterRequest(&newRequest, cookies)
if errData != nil {
errs = append(errs, errData)
}
if len(newRequestData) > 0 {
requestData = append(requestData, newRequestData...)
}
}
return requestData, errs
}

// buildAdapterRequest builds the request for Pubmatic
func (a *PubmaticAdapter) buildAdapterRequest(request *openrtb2.BidRequest, cookies []string) ([]*adapters.RequestData, error) {
reqJSON, err := json.Marshal(request)
Expand Down
39 changes: 39 additions & 0 deletions adapters/pubmatic/pubmatic_ow.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/buger/jsonparser"
"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v2/adapters"
"github.com/prebid/prebid-server/v2/openrtb_ext"
)

Expand Down Expand Up @@ -109,6 +110,44 @@ func renameTransparencyParamsKey(bidExt []byte) []byte {
return bidExt
}

// buildMultiFloorRequests builds multiple requests for each floor value
func (a *PubmaticAdapter) buildMultiFloorRequests(request *openrtb2.BidRequest, impFloorsMap map[string][]float64, cookies []string) ([]*adapters.RequestData, []error) {
requestData := []*adapters.RequestData{}
errs := make([]error, 0, MAX_MULTIFLOORS_PUBMATIC*len(request.Imp))

for i := 0; i < MAX_MULTIFLOORS_PUBMATIC; i++ {
isFloorsUpdated := false
newImps := make([]openrtb2.Imp, len(request.Imp))
copy(newImps, request.Imp)
//TODO-AK: Remove the imp from the request if the floor is not present except for the first floor
for j := range newImps {
floors, ok := impFloorsMap[request.Imp[j].ID]
if !ok || len(floors) <= i {
continue
}
isFloorsUpdated = true
newImps[j].BidFloor = floors[i]
newImps[j].ID = fmt.Sprintf("%s"+multiFloors+"%d", newImps[j].ID, i+1)
}

if !isFloorsUpdated {
continue
}

newRequest := *request
newRequest.Imp = newImps

newRequestData, errData := a.buildAdapterRequest(&newRequest, cookies)
if errData != nil {
errs = append(errs, errData)
}
if len(newRequestData) > 0 {
requestData = append(requestData, newRequestData...)
}
}
return requestData, errs
}

func trimSuffixWithPattern(input string) string {
return re.ReplaceAllString(input, "")
}
Expand Down
Loading

0 comments on commit ac2f35c

Please sign in to comment.